Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IoTSharp
IoTSharp
提交
367611dd
IoTSharp
项目概览
IoTSharp
/
IoTSharp
10 个月 前同步成功
通知
15
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
IoTSharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
367611dd
编写于
3月 20, 2022
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
支持网关批量多设备上传遥测数据。
上级
caef7174
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
21 deletion
+34
-21
IoTSharp.Data/RawMsg.cs
IoTSharp.Data/RawMsg.cs
+6
-2
IoTSharp/Handlers/MQTTServerHandler.cs
IoTSharp/Handlers/MQTTServerHandler.cs
+27
-19
IoTSharp/Program.cs
IoTSharp/Program.cs
+1
-0
未找到文件。
IoTSharp.Data/RawMsg.cs
浏览文件 @
367611dd
using
System
;
using
Newtonsoft.Json
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
...
...
@@ -7,8 +8,11 @@ namespace IoTSharp.Data
{
public
class
Playload
{
public
long
Ts
{
get
;
set
;
}
=
DateTime
.
Now
.
Ticks
;
[
JsonProperty
(
PropertyName
=
"ts"
)]
public
long
Ticks
{
get
;
set
;
}
=
DateTime
.
Now
.
Ticks
;
[
JsonProperty
(
PropertyName
=
"devicestatus"
)]
public
DeviceStatus
DeviceStatus
{
get
;
set
;
}
=
DeviceStatus
.
Good
;
[
JsonProperty
(
PropertyName
=
"values"
)]
public
Dictionary
<
string
,
object
>
Values
{
get
;
set
;
}
=
new
();
}
public
enum
DeviceStatus
...
...
IoTSharp/Handlers/MQTTServerHandler.cs
浏览文件 @
367611dd
...
...
@@ -90,7 +90,6 @@ namespace IoTSharp.Handlers
if
(
device
!=
null
)
{
bool
statushavevalue
=
false
;
bool
isplayload
=
false
;
Dictionary
<
string
,
object
>
keyValues
=
new
Dictionary
<
string
,
object
>();
if
(
tpary
.
Length
>=
4
)
{
...
...
@@ -112,11 +111,6 @@ namespace IoTSharp.Handlers
{
keyValues
.
Add
(
keyname
,
e
.
ApplicationMessage
.
Payload
);
}
else
if
(
tpary
[
3
].
ToLower
()
==
"playload"
)
{
isplayload
=
true
;
}
}
else
{
...
...
@@ -129,20 +123,9 @@ namespace IoTSharp.Handlers
_logger
.
LogWarning
(
ex
,
$"转换为字典格式失败
{
topic
}
,
{
ex
.
Message
}
"
);
}
}
if
(
tpary
[
2
]
==
"telemetry"
)
if
(
tpary
[
2
]
==
"telemetry"
)
{
if
(
isplayload
)
{
var
lst
=
Newtonsoft
.
Json
.
JsonConvert
.
DeserializeObject
<
List
<
Playload
>>(
e
.
ApplicationMessage
.
ConvertPayloadToString
());
lst
?.
ForEach
(
p
=>
{
_queue
.
PublishTelemetryData
(
new
RawMsg
()
{
DeviceId
=
device
.
Id
,
DeviceStatus
=
p
.
DeviceStatus
,
ts
=
p
.
Ts
,
MsgBody
=
p
.
Values
,
DataSide
=
DataSide
.
ClientSide
,
DataCatalog
=
DataCatalog
.
TelemetryData
});
});
}
else
{
_queue
.
PublishTelemetryData
(
new
RawMsg
()
{
DeviceId
=
device
.
Id
,
MsgBody
=
keyValues
,
DataSide
=
DataSide
.
ClientSide
,
DataCatalog
=
DataCatalog
.
TelemetryData
});
}
_queue
.
PublishTelemetryData
(
new
RawMsg
()
{
DeviceId
=
device
.
Id
,
MsgBody
=
keyValues
,
DataSide
=
DataSide
.
ClientSide
,
DataCatalog
=
DataCatalog
.
TelemetryData
});
}
else
if
(
tpary
[
2
]
==
"attributes"
)
{
...
...
@@ -182,6 +165,31 @@ namespace IoTSharp.Handlers
_logger
.
LogInformation
(
$"
{
e
.
SenderClientId
}
的数据
{
e
.
ApplicationMessage
.
Topic
}
未能匹配到设备"
);
}
}
else
if
(
tpary
.
Length
>=
3
&&
tpary
[
0
]
==
"gateway"
&&
_dev
!=
null
)
{
var
lst
=
Newtonsoft
.
Json
.
JsonConvert
.
DeserializeObject
<
Dictionary
<
string
,
List
<
Playload
>>>(
e
.
ApplicationMessage
.
ConvertPayloadToString
());
_logger
.
LogInformation
(
$"
{
e
.
SenderClientId
}
的数据
{
e
.
ApplicationMessage
.
Topic
}
是网关数据, 解析到
{
lst
?.
Count
}
个设备"
);
bool
istelemetry
=
tpary
[
2
]
==
"telemetry"
;
lst
?.
Keys
.
ToList
().
ForEach
(
dev
=>
{
var
plst
=
lst
[
dev
];
var
device
=
_dev
.
JudgeOrCreateNewDevice
(
dev
,
_scopeFactor
,
_logger
);
_logger
.
LogInformation
(
$"
{
e
.
SenderClientId
}
的网关数据正在处理设备
{
dev
}
, 设备ID为
{
device
?.
Id
}
"
);
plst
.
ForEach
(
p
=>
{
if
(
istelemetry
)
{
_queue
.
PublishTelemetryData
(
new
RawMsg
()
{
DeviceId
=
device
.
Id
,
DeviceStatus
=
p
.
DeviceStatus
,
ts
=
p
.
Ticks
,
MsgBody
=
p
.
Values
,
DataSide
=
DataSide
.
ClientSide
,
DataCatalog
=
DataCatalog
.
TelemetryData
});
}
else
{
_queue
.
PublishAttributeData
(
new
RawMsg
()
{
DeviceId
=
device
.
Id
,
DeviceStatus
=
p
.
DeviceStatus
,
ts
=
p
.
Ticks
,
MsgBody
=
p
.
Values
,
DataSide
=
DataSide
.
ClientSide
,
DataCatalog
=
DataCatalog
.
TelemetryData
});
}
});
_logger
.
LogInformation
(
$"
{
e
.
SenderClientId
}
的网关数据处理完成,设备
{
dev
}
ID为
{
device
?.
Id
}
共计
{
plst
.
Count
}
条"
);
});
}
else
{
//tpary.Length >= 3 && tpary[0] == "devices" && _dev != null
...
...
IoTSharp/Program.cs
浏览文件 @
367611dd
...
...
@@ -9,6 +9,7 @@ using Microsoft.Extensions.Hosting;
using
Silkier.AspNetCore
;
using
SilkierQuartz
;
using
Rin
;
namespace
IoTSharp
{
public
class
Program
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录