优化华为平台

This commit is contained in:
iioter 2022-08-11 00:07:02 +08:00
parent 858ce94bbb
commit acd7d86f5c
4 changed files with 51 additions and 43 deletions

View File

@ -62,6 +62,8 @@ namespace IoTGateway.ViewModel.BasicData.DeviceVMs
List<Guid> Ids = new List<Guid>() { Guid.Parse(FC["id"].ToString()) };
var pluginManager = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
var myMqttClient = Wtm.ServiceProvider.GetService(typeof(MyMqttClient)) as MyMqttClient;
myMqttClient.DeviceDeleted(Entity);
var ret = DeleteDevices.doDelete(pluginManager, DC, Ids);
if (!ret.IsSuccess)
{
@ -69,9 +71,6 @@ namespace IoTGateway.ViewModel.BasicData.DeviceVMs
return;
}
var myMqttClient = Wtm.ServiceProvider.GetService(typeof(MyMqttClient)) as MyMqttClient;
myMqttClient.DeviceDeleted(Entity);
}
public override DuplicatedInfo<Device> SetDuplicatedCheck()
{

View File

@ -98,7 +98,7 @@ namespace Plugin
try
{
ret.CookedValue = _interpreter.Eval(DealMysqlStr(item.Expressions)
.Replace("raw", ret.Value.ToString()));
.Replace("raw", ret.Value?.ToString()));
}
catch (Exception)
{
@ -114,9 +114,9 @@ namespace Plugin
//变化了才推送到mqttserver用于前端展示
if (DeviceValues[item.ID].StatusType != ret.StatusType ||
DeviceValues[item.ID].Value?.ToString() != ret.Value.ToString() ||
DeviceValues[item.ID].CookedValue.ToString() !=
ret.CookedValue.ToString())
DeviceValues[item.ID].Value?.ToString() != ret.Value?.ToString() ||
DeviceValues[item.ID].CookedValue?.ToString() !=
ret.CookedValue?.ToString())
{
//这是设备变量列表要用的
mqttServer.PublishAsync(

View File

@ -1,4 +1,5 @@
using IoTGateway.DataAccess;
using System.Text;
using IoTGateway.DataAccess;
using IoTGateway.Model;
using Microsoft.Extensions.Logging;
using MQTTnet;
@ -363,10 +364,7 @@ namespace Plugin
{
ServiceId = "serviceId",
EventTime = DateTime.Now.ToString("yyyyMMddTHHmmssZ"),
Data = new Dictionary<string, object>()
{
{ "data", obj }
}
Data = obj
}
}
}
@ -538,14 +536,16 @@ namespace Plugin
case IoTPlatformType.IoTSharp:
foreach (var payload in sendModel[device.DeviceName])
{
await UploadIsTelemetryDataAsync(device.DeviceName, payload.Values);
if (payload.Values != null)
await UploadIsTelemetryDataAsync(device.DeviceName, payload.Values);
}
break;
case IoTPlatformType.ThingsCloud:
foreach (var payload in sendModel[device.DeviceName])
{
await UploadTcTelemetryDataAsync(device.DeviceName, payload.Values);
if (payload.Values != null)
await UploadTcTelemetryDataAsync(device.DeviceName, payload.Values);
}
break;
@ -560,8 +560,8 @@ namespace Plugin
{
device = device.DeviceName,
timestamp = payload.TS,
measurements = payload.Values.Keys.ToList(),
values = payload.Values.Values.ToList()
measurements = payload.Values?.Keys.ToList(),
values = payload.Values?.Values.ToList()
};
await Client.PublishAsync(device.DeviceName, JsonConvert.SerializeObject(tsData));
}
@ -571,7 +571,8 @@ namespace Plugin
case IoTPlatformType.HuaWei:
foreach (var payload in sendModel[device.DeviceName])
{
await UploadHwTelemetryDataAsync(device, payload.Values);
if (payload.Values != null)
await UploadHwTelemetryDataAsync(device, payload.Values);
}
break;
@ -587,12 +588,13 @@ namespace Plugin
foreach (var payload in sendModel[device.DeviceName])
{
foreach (var kv in payload.Values)
{
//更新到UAService
_uaNodeManager?.UpdateNode($"{device.Parent.DeviceName}.{device.DeviceName}.{kv.Key}",
kv.Value);
}
if (payload.Values != null)
foreach (var kv in payload.Values)
{
//更新到UAService
_uaNodeManager?.UpdateNode($"{device.Parent.DeviceName}.{device.DeviceName}.{kv.Key}",
kv.Value);
}
}
}
catch (Exception ex)
@ -630,7 +632,7 @@ namespace Plugin
case IoTPlatformType.HuaWei:
var deviceOnLine = new HwDeviceOnOffLine()
{
MId = new Random().NextInt64(), //命令ID
MId = new Random().Next(0, 1024), //命令ID
DeviceStatuses = new List<DeviceStatus>()
{
new DeviceStatus()
@ -643,7 +645,8 @@ namespace Plugin
}
};
await Client.PublishAsync($"/v1/devices/{_systemConfig.GatewayName}/topo/update",
JsonConvert.SerializeObject(deviceOnLine));
JsonConvert.SerializeObject(deviceOnLine), MqttQualityOfServiceLevel.AtLeastOnce,
retain: false);
break;
}
}
@ -682,7 +685,7 @@ namespace Plugin
case IoTPlatformType.HuaWei:
var deviceOnLine = new HwDeviceOnOffLine()
{
MId = new Random().NextInt64(), //命令ID
MId = new Random().Next(0, 1024), //命令ID
DeviceStatuses = new List<DeviceStatus>()
{
new DeviceStatus()
@ -695,7 +698,8 @@ namespace Plugin
}
};
await Client.PublishAsync($"/v1/devices/{_systemConfig.GatewayName}/topo/update",
JsonConvert.SerializeObject(deviceOnLine));
JsonConvert.SerializeObject(deviceOnLine), MqttQualityOfServiceLevel.AtLeastOnce,
retain: false);
break;
}
}
@ -718,7 +722,7 @@ namespace Plugin
var addDeviceDto = new HwAddDeviceDto
{
MId = new Random().NextInt64() //命令ID
MId = new Random().Next(0, 1024), //命令ID
};
addDeviceDto.DeviceInfos.Add(
new DeviceInfo
@ -753,22 +757,27 @@ namespace Plugin
case IoTPlatformType.HuaWei:
var topic = $"/v1/devices/{_systemConfig.GatewayName}/topo/delete";
var deleteDeviceDto = new HwDeleteDeviceDto
await using (var dc = new DataContext(IoTBackgroundService.connnectSetting, IoTBackgroundService.DbType))
{
Id = new Random().NextInt64(), //命令ID
DeviceId = device.DeviceConfigs.FirstOrDefault(x => x.DeviceConfigName == "DeviceId")
?.Value,
RequestTime = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds,
Request = new()
{
ManufacturerId = "Test_n",
ManufacturerName = "Test_n",
ProductType = "A_n"
}
};
var deviceId = dc.Set<DeviceConfig>().FirstOrDefault(x =>
x.DeviceId == device.ID && x.DeviceConfigName == "DeviceId")?.Value;
await Client.PublishAsync(topic,
JsonConvert.SerializeObject(deleteDeviceDto));
var deleteDeviceDto = new HwDeleteDeviceDto
{
Id = new Random().Next(0, 1024), //命令ID
DeviceId = deviceId,
RequestTime = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds,
Request = new()
{
ManufacturerId = "Test_n",
ManufacturerName = "Test_n",
ProductType = "A_n"
}
};
await Client.PublishAsync(topic,
JsonConvert.SerializeObject(deleteDeviceDto));
}
break;
}
}

View File

@ -14,7 +14,7 @@ namespace PluginInterface
[JsonProperty(PropertyName = "devicestatus")]
public DeviceStatusTypeEnum DeviceStatus { get; set; } = DeviceStatusTypeEnum.Good;
[JsonProperty(PropertyName = "values")]
public Dictionary<string, object> Values { get; set; } = new();
public Dictionary<string, object>? Values { get; set; } = new();
}
public enum DeviceStatusTypeEnum
{