fyf пре 2 година
родитељ
комит
1cb7c07df9
4 измењених фајлова са 52 додато и 46 уклоњено
  1. +14
    -44
      BPASmartClient.IoT/DataVClient.cs
  2. +37
    -0
      BPASmartClient.IoT/Model/DataVReport.cs
  3. +1
    -1
      BPASmartClient.ViewModel/LogViewModel.cs
  4. +0
    -1
      BPASmartClient/App.config

+ 14
- 44
BPASmartClient.IoT/DataVClient.cs Прегледај датотеку

@@ -45,6 +45,10 @@ namespace BPASmartClient.IoT
/// 大屏上报Model
/// </summary>
public DataVAPI.Tool.IOT.IOTDevSXModel iOTDevSXModel = new DataVAPI.Tool.IOT.IOTDevSXModel() { };
/// <summary>
/// 广播
/// </summary>
public string PubTopic = "/broadcast/" + "grgpECHSL7q" + "/" + "Transit_SetDevice";
#endregion

#region API调用
@@ -60,15 +64,9 @@ namespace BPASmartClient.IoT
{
if (DeviceDataV != null && DeviceDataV.GetIsConnected())
{
string url = DataVApiAddress + "/api/Alarm/Create";
alarmTable.ClientId = ClientId;
alarmTable.devicename = DeviceDataV.deviceTable.devicename;
string redata = HttpRequestHelper.HttpPostRequest(url, Tools.JsonConvertTools(alarmTable));
if (!string.IsNullOrEmpty(redata))
{
JsonMsg<AlarmTable> msg = Tools.JsonToObjectTools<JsonMsg<AlarmTable>>(redata);
id = msg?.obj?.data?.Id;
}
DeviceDataV.IOT_Publish(PubTopic, Tools.JsonConvertTools(alarmTable));
}
}
catch (Exception ex)
@@ -78,24 +76,6 @@ namespace BPASmartClient.IoT
return id;
}

/// <summary>
/// 根据ID删除告警信息
/// </summary>
/// <param name="alarm"></param>
public void HttpDeleteAlarm(string id)
{
try
{
if (string.IsNullOrEmpty(id)) { MessageLog.GetInstance.Show("API调用删除告警信息,ID不能为空!"); return; }
string url = DataVApiAddress + "/api/Alarm/Delete?id=" + id;
HttpRequestHelper.HttpGetRequest(url);
}
catch (Exception ex)
{
MessageLog.GetInstance.Show(ex.Message);
}
}

/// <summary>
/// 增加日志信息
/// </summary>
@@ -108,15 +88,9 @@ namespace BPASmartClient.IoT
{
if (DeviceDataV != null && DeviceDataV.GetIsConnected())
{
string url = DataVApiAddress + "/api/Log/Create";
logTable.ClientId = ClientId;
logTable.devicename = DeviceDataV.deviceTable.devicename;
string redata = HttpRequestHelper.HttpPostRequest(url, Tools.JsonConvertTools(logTable));
if (!string.IsNullOrEmpty(redata))
{
JsonMsg<LogTable> msg = Tools.JsonToObjectTools<JsonMsg<LogTable>>(redata);
id = msg?.obj?.data?.Id;
}
DeviceDataV.IOT_Publish(PubTopic, Tools.JsonConvertTools(logTable));
}
}
catch (Exception ex)
@@ -147,7 +121,10 @@ namespace BPASmartClient.IoT
DeviceDataV.DataVMessageAction += DevIOTActionHandler;
MessageLog.GetInstance.Show($"客户端:【{ClientId}】,设备名称{DeviceDataV.deviceTable.devicename}阿里云连接成功");
}
else MessageLog.GetInstance.ShowEx(message);
else
{
MessageLog.GetInstance.ShowEx(message);
}
}

/// <summary>
@@ -159,8 +136,7 @@ namespace BPASmartClient.IoT
{
if (DeviceDataV != null && DeviceDataV.GetIsConnected())
{
DataVNodeStatus dataVNode = new DataVNodeStatus();
dataVNode.data = new List<object>();
List<object> dataVNode = new List<object>();
Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices()?.ForEach(device =>
{
var obj=new
@@ -174,13 +150,13 @@ namespace BPASmartClient.IoT
IsHealthColor = !device.IsHealth ? new ALYColor { r = 255, g = 0, b = 0, a = 1 } : new ALYColor { r = 51, g = 232, b = 34, a = 1 },
Status = device.Status.GetStatus(),
};
dataVNode.data.Add(obj);
dataVNode.Add(obj);
});
if (dataVNode.data.Count > 0)
if (dataVNode.Count > 0)
{
iOTDevSXModel.KZSX = Tools.JsonConvertTools<DevSX>(new DevSX { data = new List<DevSXBase> { new DevSXBase { SXMC = "", SXLX = "" } } });
iOTDevSXModel.JBSX = Tools.JsonConvertTools<DevSX>(new DevSX { data = new List<DevSXBase> { new DevSXBase { SXMC = "", SXLX = "" } } });
iOTDevSXModel.NodeStatus = Tools.JsonConvertTools<DataVNodeStatus>(dataVNode);
iOTDevSXModel.NodeStatus = Tools.JsonConvertTools(new { data = dataVNode });
DeviceDataV.IOT_Publish(DeviceDataV.PubTopic, iOTDevSXModel.Tojson());
}
}
@@ -237,10 +213,4 @@ namespace BPASmartClient.IoT
set;
}
}

public class DataVNodeStatus
{
public List<object> data { get; set; }
}

}

+ 37
- 0
BPASmartClient.IoT/Model/DataVReport.cs Прегледај датотеку

@@ -36,6 +36,43 @@ namespace BPASmartDatavDeviceClient.IoT
return DatavDeviceClient.IsConnected;
}

/// <summary>
/// 初始化IOT连接
/// </summary>
public bool InitializeNo(string _productkey, string _devicename, string _devicesecret, ref string message)
{
try
{
deviceTable.devicename = _devicename;
SetValue(_productkey, _devicename, _devicesecret);
IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
string _clientIp = host.AddressList.FirstOrDefault(
ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToString();
string t = Convert.ToString(DateTimeOffset.Now.ToUnixTimeMilliseconds());
string signmethod = "hmacmd5";

Dictionary<string, string> dict = new Dictionary<string, string>();
dict.Add("productKey", ProductKey);
dict.Add("deviceName", DeviceName);
dict.Add("clientId", _clientIp);
dict.Add("timestamp", t);

mqttUserName = DeviceName + "&" + ProductKey;
mqttPassword = IotSignUtils.sign(dict, DeviceSecret, signmethod);
mqttClientId = _clientIp + "|securemode=3,signmethod=" + signmethod + ",timestamp=" + t + "|";
targetServer = ProductKey + ".iot-as-mqtt." + RegionId + ".aliyuncs.com";
ConnectMqtt(targetServer, mqttClientId, mqttUserName, mqttPassword);
}
catch (Exception ex)
{
message += $"阿里云{_devicename}连接失败,{ex.Message}";
return false;
}
IOT_Subscribe(BroadcastTopic);//订阅广播主题
if (!DatavDeviceClient.IsConnected) message += $"客户端:【】,设备名称{deviceTable.devicename}阿里云连接失败.不能上报业务信息";
return DatavDeviceClient.IsConnected;
}

/// <summary>
/// 获取连接状态
/// </summary>


+ 1
- 1
BPASmartClient.ViewModel/LogViewModel.cs Прегледај датотеку

@@ -60,7 +60,7 @@ namespace BPASmartClient.ViewModel
DataVClient.GetInstance().HttpAddLog(new LogTable
{
ClientId = ClientId,
LogTime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"),
LogTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
LogType = "严重",
LogMessage = s,
LogVla = "错误日志",


+ 0
- 1
BPASmartClient/App.config Прегледај датотеку

@@ -19,7 +19,6 @@
<add key="ApolloUri" value="https://bpa.black-pa.com:28080"/>
<add key="OrderServiceUri" value="https://bpa.black-pa.com:21527/order/"/>
<add key="StockServiceUri" value="https://bpa.black-pa.com:21527/stock/"/>

<add key="DataVServiceUri" value="https://bpa.black-pa.com:21527/datav"/>




Loading…
Откажи
Сачувај