|
|
@@ -1,4 +1,5 @@ |
|
|
|
using BPASmartClient.MQTT; |
|
|
|
using BPA.Message; |
|
|
|
using BPASmartClient.MQTT; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
@@ -7,45 +8,49 @@ using System.Threading.Tasks; |
|
|
|
|
|
|
|
namespace BPASmartClient.Business.Plugin |
|
|
|
{ |
|
|
|
public class LocalMqtt : IPlugin |
|
|
|
public class LocalMqtt |
|
|
|
{ |
|
|
|
|
|
|
|
//客户端ID |
|
|
|
private int clientId; |
|
|
|
//运行标识 |
|
|
|
private bool running = false; |
|
|
|
//MQTT 代理 |
|
|
|
private MQTTProxy mqttProxy = new MQTTProxy(); |
|
|
|
private volatile static LocalMqtt _Instance; |
|
|
|
public static LocalMqtt GetInstance => _Instance ?? (_Instance = new LocalMqtt()); |
|
|
|
private LocalMqtt() { } |
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
SendScreenDataModel MqttPush = new SendScreenDataModel(); |
|
|
|
|
|
|
|
public void Init(ScreenDeviceType DeviceType) |
|
|
|
{ |
|
|
|
|
|
|
|
Dictionary<string, string> MqttPushdata = new Dictionary<string, string>(); |
|
|
|
MqttPush.mqttDataDic.Add(DeviceType.ToString(), SetTopic(DeviceType, MqttPushdata)); |
|
|
|
MQTTProxy mQTTProxy = new MQTTProxy(); |
|
|
|
mQTTProxy.Connected = new Action(() => |
|
|
|
{ |
|
|
|
mQTTProxy.Subscrib(ScreenTOPIC.GetInstance.GetTopic(DeviceType)) ; |
|
|
|
|
|
|
|
}); |
|
|
|
mQTTProxy.Connect("UserName", "Password", "Host", 1880, $"{DeviceType}_设备监听数据{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); |
|
|
|
} |
|
|
|
|
|
|
|
public void Initialize() |
|
|
|
public void Start() |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void Start() |
|
|
|
private Dictionary<string, string> SetTopic(ScreenDeviceType DeviceType, Dictionary<string, string> MqttPushdata ) |
|
|
|
{ |
|
|
|
running = true; |
|
|
|
//主题初始化 |
|
|
|
TopicDefine.GetInstance().Initialize(Plugin.GetInstance().GetPlugin<DeviceMgr>().GetDevices()); |
|
|
|
//MQTT 连接成功 |
|
|
|
mqttProxy.Connected = new Action(() => |
|
|
|
{ |
|
|
|
mqttProxy.Subscrib(); |
|
|
|
}); |
|
|
|
//MQTT 连接成功 |
|
|
|
mqttProxy.LostConnect = new Action(() => |
|
|
|
switch (DeviceType) |
|
|
|
{ |
|
|
|
mqttProxy.Subscrib(); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
//MQTT 初始化 |
|
|
|
mqttProxy.Connect(); |
|
|
|
case ScreenDeviceType.大炒: |
|
|
|
break; |
|
|
|
case ScreenDeviceType.小炒: |
|
|
|
break; |
|
|
|
case ScreenDeviceType.分餐机: |
|
|
|
break; |
|
|
|
case ScreenDeviceType.煮面机: |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
return MqttPushdata; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|