From e87985ec1dcb69beedaf9f95e8e7aba14b7c08d6 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期三, 09 十二月 2020 18:50:14 +0800
Subject: [PATCH] 2020-12-09 1.信息中心,增加下划线和点击Alter提醒详情。

---
 HDL_ON/DAL/Mqtt/MqttClient.cs |   60 ++++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 40 insertions(+), 20 deletions(-)

diff --git a/HDL_ON/DAL/Mqtt/MqttClient.cs b/HDL_ON/DAL/Mqtt/MqttClient.cs
index 137d082..321d8b1 100644
--- a/HDL_ON/DAL/Mqtt/MqttClient.cs
+++ b/HDL_ON/DAL/Mqtt/MqttClient.cs
@@ -9,6 +9,8 @@
 using System.Text;
 using System.Security.Cryptography;
 using HDL_ON.DriverLayer;
+using HDL_ON.Entity;
+using HDL_ON.UI;
 
 namespace HDL_ON.DAL.Mqtt
 {
@@ -19,7 +21,7 @@
         /// </summary>
         static string mqttEncryptKey = "";
         //static string checkGatewayTopicBase64 = "";
-
+        static bool hadGateway = true;
         /// <summary>
         /// 鎸や笅绾夸富棰�
         /// </summary>
@@ -130,7 +132,7 @@
         static void InitMqtt()
         {
             new System.Threading.Thread(async () => {
-                while (true)
+                while (hadGateway)
                 {
                     try
                     {
@@ -165,7 +167,7 @@
                     //2020-05-14 璁㈤槄涓婚璐ㄩ噺鏀逛负0
                     var topicFilterBusGateWayToClient = new MqttTopicFilter()
                     {
-                        Topic = $"/BusGateWayToClient/{MqttInfoConfig.Current.HomeGatewayInfo.id}/#",
+                        Topic = $"/BusGateWayToClient/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/#",
                         QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
                         //QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce
                     };
@@ -177,8 +179,14 @@
                         //QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce
                     };
 
+                    var topicAlinkStatus = new MqttTopicFilter()
+                    {
+                        Topic = $"/user/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/app/thing/property/send",
+                        QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
+                    };
+
                     Utlis.WriteLine("寮�濮嬭闃咃紒");
-                    var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { topicFilterBusGateWayToClient, topicFilterPush2 });
+                    var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { topicFilterBusGateWayToClient, topicFilterPush2 , topicAlinkStatus });
                     if (result.Items[0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0)
                     {
                         isSubscribeSuccess = true;
@@ -202,7 +210,6 @@
         /// </summary>
         public static async Task StartCloudMqtt()
         {
-
             if (OnAppConfig.Instance.internetStatus == 0)
             {
                 return;
@@ -225,7 +232,7 @@
                 try
                 {
                     #region 鍒濆鍖栬繙绋婱qtt
-
+                    remoteMqttIsConnecting = true;
                     RemoteMqttClient = new MqttFactory().CreateMqttClient();
 
 
@@ -243,17 +250,17 @@
                                     //鏂版尋涓嬬嚎涓婚鏂规 鏀跺埌鎸や笅绾夸富棰�
                                     ReceiveNotifySqueezeAsync(mMes);
                                 }
-                                else if (topic == $"/BusGateWayToClient/{MqttInfoConfig.Current.HomeGatewayInfo.id}/NotifyBusGateWayInfoChange")
+                                else if (topic == $"/BusGateWayToClient/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/NotifyBusGateWayInfoChange")
                                 {//缃戝叧涓婄嚎锛岄渶瑕佹洿鏂癮eskey
                                     //鏀跺埌缃戝叧涓婄嚎娑堟伅涓婚
                                     ReceiveNotifyBusGateWayInfoChange();
                                 }
-                                else if (topic == $"/BusGateWayToClient/{MqttInfoConfig.Current.HomeGatewayInfo.id}/NotifyGateWayOffline")
+                                else if (topic == $"/BusGateWayToClient/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/NotifyGateWayOffline")
                                 {//缃戝叧鎺夌嚎
                                     //----绗簩姝ワ細璇诲彇璐﹀彿涓嬮潰鐨勭綉鍏冲垪琛�
                                     ReceiveNotifyGateWayOffline();
                                 }
-                                else if (topic == $"/BusGateWayToClient/{MqttInfoConfig.Current.HomeGatewayInfo.id}/Common/CheckGateway")
+                                else if (topic == $"/BusGateWayToClient/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/Common/CheckGateway")
                                 {
                                     var ss = Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
                                     ReceiveCheckGateway(ss);
@@ -261,7 +268,9 @@
                                 else
                                 {
                                     SetGatewayOnlineResetCheck();
-                                    if (Entity.DB_ResidenceData.residenceData.GatewayType == 0)
+                                    Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, DB_ResidenceData.residenceData.HomeGateway.aesKey);
+                                    //bus鏁版嵁瑙f瀽
+                                    if (DB_ResidenceData.residenceData.GatewayType == 0)
                                     {
                                         var packet = new Packet();
 
@@ -278,6 +287,8 @@
                                     else
                                     {
                                         //A鍗忚鏁版嵁澶勭悊
+                                        var revString = Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
+                                        Control.Ins.UpdataFunctionStatus(revString);
                                     }
                                 }
                             }
@@ -301,11 +312,7 @@
                             IfNeedReadAllDeviceStatus = true;
                             Utlis.WriteLine($"============>Mqtt杩滅▼杩炴帴鎴愬姛");
                             SendPushSignOut();
-
-                            //if (Control.Ins.IsRemote) {
-                            //    //Utlis.ShowAppLinkStatus (AppLinkStatus.CloudLink);
-                            //    MainPage.AddTip (Language.StringByID (SimpleControl.R.MyInternationalizationString.LinkSuccess));
-                            //}
+                            FunctionList.List.ReadAllFunctionStatus();
                         });
                     }
                     #endregion
@@ -423,8 +430,7 @@
 
                     //url = HttpUtil.GetProxyEMQUrl (url);
                     //#if DEBUG
-                    //                   url = HttpUtil.GetProxyEMQUrl (url);
-
+                    //url = HttpUtil.GetProxyEMQUrl (url);
                     //#endif
                     var clientId = MqttInfoConfig.Current.mMqttInfo.clientId;
                     var username = MqttInfoConfig.Current.mMqttInfo.userName;
@@ -580,7 +586,7 @@
                 switch (optionType)
                 {
                     case 0:
-                        topicName = $"/ClientToBusGateWay/{MqttInfoConfig.Current.HomeGatewayInfo.id}/Common/ON";
+                        topicName = $"/ClientToBusGateWay/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/Common/ON";
                         if (!string.IsNullOrEmpty(mqttEncryptKey))
                         {
                             message = Securitys.EncryptionService.AesEncryptPayload(message, mqttEncryptKey);
@@ -588,7 +594,7 @@
                         await RemoteMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topicName, Payload = message, Retain = false, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce });
                         break;
                     case 3:
-                        topicName = $"/ClientToBusGateWay/{MqttInfoConfig.Current.HomeGatewayInfo.id}/Common/CheckGateway";
+                        topicName = $"/ClientToBusGateWay/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/Common/CheckGateway";
                         Utlis.WriteLine("CheckGateway");
                         await RemoteMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topicName, Retain = false, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce });
                         break;
@@ -628,7 +634,8 @@
         {
             if (Control.Ins.IsRemote)
             {
-                Control.Ins.GatewayOnline = true;
+                if (!Control.Ins.GatewayOnline)
+                    Control.Ins.GatewayOnline = true;
             }
         }
 
@@ -644,6 +651,19 @@
             {
                 MqttInfoConfig.Current.mMqttInfo = mqttInfoRequestResult_Obj;
                 await MQTTConnectAsync();
+                //1.鍒ゆ柇鏄惁缁戝畾浜嗙綉鍏筹紝鑾峰彇缃戝叧杩滅▼杩炴帴鐨勫姞瀵咾EY
+                if (DB_ResidenceData.residenceData.CheckWhetherGatewayIsBound())
+                {
+                    //2.鎵惧嚭鏄惁瀛樺湪鍖归厤褰撳墠浣忓畢鐨刴ac锛屽瓨鍦ㄥ啀杩涜杩滅▼銆�
+                    MqttInfoConfig.Current.HomeGatewayInfo = DB_ResidenceData.residenceData.HomeGateway;
+                    //3.寮�濮嬭繛鎺�
+                    await MQTTConnectAsync();
+                }
+                else
+                {
+                    Utlis.WriteLine("============>杩樻病缁戝畾缃戝叧");
+                    hadGateway = false;
+                }
             }
         }
 

--
Gitblit v1.8.0