diff --git a/Plugins/Plugin/MyMqttClient.cs b/Plugins/Plugin/MyMqttClient.cs index f15a292..d75f59a 100644 --- a/Plugins/Plugin/MyMqttClient.cs +++ b/Plugins/Plugin/MyMqttClient.cs @@ -12,6 +12,7 @@ using PluginInterface.HuaWeiRoma; using PluginInterface.IotDB; using PluginInterface.IoTSharp; using PluginInterface.ThingsBoard; +using System.Xml.Linq; namespace Plugin { @@ -540,7 +541,7 @@ namespace Plugin measurements = payload.Values?.Keys.ToList(), values = payload.Values?.Values.ToList() }; - await Client.EnqueueAsync(device.DeviceName, JsonConvert.SerializeObject(tsData)); + await Client.EnqueueAsync(_systemConfig.GatewayName + device.DeviceName, JsonConvert.SerializeObject(tsData)); } break; @@ -580,6 +581,10 @@ namespace Plugin } } + private readonly DateTime _tsStartDt = new(1970, 1, 1); + private readonly List iotDbOnLineMeasurement = new() { "online" }; + private readonly List iotDbOnLine = new() { true }; + private readonly List iotDbOffLine = new() { false }; public async Task DeviceConnected(Device device) { try @@ -605,6 +610,17 @@ namespace Plugin JsonConvert.SerializeObject(new Dictionary { { "device", device.DeviceName } })); break; + case IoTPlatformType.IotDB: + IotTsData onlineData = new IotTsData() + { + device = _systemConfig.GatewayName + device.DeviceName, + timestamp = (long)(DateTime.UtcNow - _tsStartDt).TotalMilliseconds, + measurements = iotDbOnLineMeasurement, + values = iotDbOnLine + }; + await Client.EnqueueAsync(_systemConfig.GatewayName + device.DeviceName, + JsonConvert.SerializeObject(onlineData)); + break; case IoTPlatformType.HuaWei: var deviceOnLine = new HwDeviceOnOffLine() { @@ -657,6 +673,17 @@ namespace Plugin JsonConvert.SerializeObject(new Dictionary { { "device", device.DeviceName } })); break; + case IoTPlatformType.IotDB: + IotTsData onlineData = new IotTsData() + { + device = _systemConfig.GatewayName + device.DeviceName, + timestamp = (long)(DateTime.UtcNow - _tsStartDt).TotalMilliseconds, + measurements = iotDbOnLineMeasurement, + values = iotDbOffLine + }; + await Client.EnqueueAsync(_systemConfig.GatewayName + device.DeviceName, + JsonConvert.SerializeObject(onlineData)); + break; case IoTPlatformType.HuaWei: var deviceOnLine = new HwDeviceOnOffLine() { @@ -684,7 +711,6 @@ namespace Plugin } } - public async Task DeviceAdded(Device device) { try @@ -720,7 +746,6 @@ namespace Plugin } } - public async Task DeviceDeleted(Device device) { try