| | |
| | | //订阅一个挤下线的主题
|
| | | await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + Config.Instance.ConnEmqClientId + "/Push/NotifySqueeze");
|
| | |
|
| | | await initGateWayBaseInfomation(); |
| | |
|
| | | //没有主网关时主动读取,获取主网关信息
|
| | | var gateWayList = GateWayList.FindAll(obj => obj.HomeId == Shared.Common.Config.Instance.HomeId);
|
| | | if (gateWayList.Find(obj => obj.IsMainGateWay == true) == null)
|
| | | //如果这个函数卡久了的话,会接收到云端推送的挤下线主题,不知道为什么
|
| | | new Thread(async () =>
|
| | | {
|
| | | if (gateWayList.Count == 1)
|
| | | await initGateWayBaseInfomation();
|
| | |
|
| | | //没有主网关时主动读取,获取主网关信息
|
| | | var gateWayList = GateWayList.FindAll(obj => obj.HomeId == Shared.Common.Config.Instance.HomeId);
|
| | | if (gateWayList.Find(obj => obj.IsMainGateWay == true) == null)
|
| | | {
|
| | | gateWayList[0].IsMainGateWay = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | for (int i = 0; i < gateWayList.Count; i++)
|
| | | if (gateWayList.Count == 1)
|
| | | {
|
| | | var gateWay = gateWayList[i];
|
| | | var info = await gateWay.GetZbGwInfoAsync();
|
| | | if (info == null || info.getGwData == null)
|
| | | gateWayList[0].IsMainGateWay = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | for (int i = 0; i < gateWayList.Count; i++)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | if (info.getGwData.IsDominant == 1)
|
| | | {
|
| | | for (int j = 0; j < gateWayList.Count; j++)
|
| | | var gateWay = gateWayList[i];
|
| | | var info = await gateWay.GetZbGwInfoAsync();
|
| | | if (info == null || info.getGwData == null)
|
| | | {
|
| | | if (gateWayList[i].GwId == info.getGwData.GwId)
|
| | | {
|
| | | gateWayList[i].IsMainGateWay = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | gateWayList[i].IsMainGateWay = false;
|
| | | }
|
| | | continue;
|
| | | }
|
| | | break;
|
| | | if (info.getGwData.IsDominant == 1)
|
| | | {
|
| | | for (int j = 0; j < gateWayList.Count; j++)
|
| | | {
|
| | | if (gateWayList[i].GwId == info.getGwData.GwId)
|
| | | {
|
| | | gateWayList[i].IsMainGateWay = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | gateWayList[i].IsMainGateWay = false;
|
| | | }
|
| | | }
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | })
|
| | | { IsBackground = true }.Start();
|
| | | |
| | | }); |
| | | } |
| | | #endregion |
| | |
| | | { |
| | | DebugPrintLog($"Local断开通讯连接出异常:{ex.Message}"); |
| | | } |
| | | }
|
| | |
|
| | | /// <summary> |
| | | /// 强制断开本地的网关连接 |
| | | /// </summary> |
| | | public async Task CloseLocalConnectionOnForce() |
| | | { |
| | | try |
| | | {
|
| | | await localMqttClient.DisconnectAsync();
|
| | | } |
| | | catch { } |
| | | finally |
| | | {
|
| | | localIsConnected = false;
|
| | | //这个东西也要弄
|
| | | localMqttIsConnecting = false;
|
| | | } |
| | | } |
| | | |
| | | /// <summary>
|
| | |
| | | catch (Exception e)
|
| | | { |
| | | DebugPrintLog($"Remote断开通讯连接出异常:{e.Message}");
|
| | | }
|
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 强制断开远程Mqtt的链接
|
| | | /// </summary>
|
| | | /// <returns></returns> |
| | | public static async Task CloseRemoteConnectionOnForce()
|
| | | {
|
| | | try
|
| | | {
|
| | | await RemoteMqttClient.DisconnectAsync();
|
| | | }
|
| | | catch { }
|
| | | finally
|
| | | {
|
| | | remoteIsConnected = false;
|
| | | //这个东西也要弄
|
| | | remoteMqttIsConnecting = false;
|
| | | }
|
| | | } |
| | | |
| | |
| | | #if DEBUG |
| | | if (flage == true) |
| | | { |
| | | //if (msg.Contains("DeviceStatusReport") == false) |
| | | //if (msg.Contains("DeviceInfoRespon") == true) |
| | | { |
| | | System.Console.WriteLine(msg + " " + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond); |
| | | } |