提交 598d59df 编写于 作者: 麦壳饼's avatar 麦壳饼

fix for xml and binary data

上级 bbf6246a
......@@ -162,12 +162,12 @@ namespace IoTSharp.Extensions
if (kp.Value.GetType() == typeof(byte[]))
{
tdata.Type = DataType.Binary;
tdata.Value_Boolean = (bool)kp.Value;
tdata.Value_Binary = (byte[])kp.Value;
}
else if (kp.Value.GetType() == typeof(System.Xml.XmlDocument))
{
tdata.Type = DataType.XML;
tdata.Value_XML = ((System.Xml.XmlDocument)kp.Value).ToString();
tdata.Value_XML = ((System.Xml.XmlDocument)kp.Value).InnerXml;
}
else
{
......
......@@ -70,9 +70,41 @@ namespace IoTSharp.Handlers
if (tpary.Length >= 3 && tpary[0] == "devices" && Devices.ContainsKey(e.ClientId))
{
Device device = JudgeOrCreateNewDevice(tpary, Devices[e.ClientId]);
var keyValues = e.ApplicationMessage.ConvertPayloadToDictionary();
if (device != null)
{
Dictionary<string, object> keyValues = new Dictionary<string, object>();
if (tpary.Length >= 4)
{
string keyname = tpary.Length >= 5 ? tpary[4] : tpary[3];
if (tpary[3].ToLower() == "xml")
{
try
{
var xml = new System.Xml.XmlDocument();
xml.LoadXml(e.ApplicationMessage.ConvertPayloadToString());
keyValues.Add(keyname, xml);
}
catch (Exception ex)
{
_logger.LogWarning(ex, $"xml data error {topic},{ex.Message}");
}
}
else if (tpary[3].ToLower() == "binary")
{
keyValues.Add(keyname, e.ApplicationMessage.Payload);
}
}
else
{
try
{
keyValues = e.ApplicationMessage.ConvertPayloadToDictionary();
}
catch (Exception ex)
{
_logger.LogWarning(ex, $"ConvertPayloadToDictionary Error {topic},{ex.Message}");
}
}
if (tpary[2] == "telemetry")
{
Task.Run(async () =>
......@@ -93,7 +125,7 @@ namespace IoTSharp.Handlers
{
try
{
var result = await _dbContext.SaveAsync<AttributeLatest, AttributeData>(keyValues, device, DataSide.ClientSide);
}
catch (Exception ex)
......@@ -105,10 +137,7 @@ namespace IoTSharp.Handlers
}
}
}
}
internal void Server_ClientDisconnected(IMqttServerEx server, MqttServerClientDisconnectedEventArgs args)
......
# MQTT API说明
## Topic 规则
### 设备:
属性数据 /devices/me/attributes
遥测数据 /devices/me/telemetry
### 网关:
上传自身属性数据 /devices/me/attributes
上传自身遥测数据 /devices/me/telemetry
上传子设备属性数据 /devices/<子设备名称>/attributes
上传子设备遥测数据 /devices/<子设备名称>/telemetry
上传子设备的属性和遥测数据时 , 首先会查找设备是否存在, 如果存在, 则创建设备, 创建设备的租户和客户信息继承自网关,自动创建的设备与普通设备没有区别。
子设备名称如果指定的是已存在设备或者其他网关的子设备则不能创建, 也就是说, 一个客户的所有设备名称是唯一的。
##
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册