From eb3a71699bcf371db801165e3af65951b1292706 Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期四, 24 十二月 2020 15:10:05 +0800
Subject: [PATCH] 20201224-3

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

diff --git a/HDL_ON/DAL/Mqtt/MqttClient.cs b/HDL_ON/DAL/Mqtt/MqttClient.cs
index 1ecf619..fb5d3b5 100644
--- a/HDL_ON/DAL/Mqtt/MqttClient.cs
+++ b/HDL_ON/DAL/Mqtt/MqttClient.cs
@@ -186,9 +186,14 @@
                         Topic = $"/user/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/app/thing/property/send",
                         QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
                     };
+                    var topicBusStatus = new MqttTopicFilter()
+                    {
+                        Topic = $"/BusGateWayToClient/MacMask/Common",
+                        QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
+                    };
 
                     Utlis.WriteLine("寮�濮嬭闃咃紒");
-                    var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { topicFilterBusGateWayToClient, topicFilterPush2 , topicAlinkStatus });
+                    var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { topicFilterBusGateWayToClient, topicFilterPush2, topicAlinkStatus, topicBusStatus });
                     if (result.Items[0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0)
                     {
                         isSubscribeSuccess = true;
@@ -269,7 +274,6 @@
                                 }
                                 else
                                 {
-                                    MainPage.Log($"mqtt data");
                                     SetGatewayOnlineResetCheck();
                                     var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, DB_ResidenceData.Instance.HomeGateway.aesKey);
                                     
@@ -286,10 +290,19 @@
                                         {
                                             packet.Bytes = e.ApplicationMessage.Payload;
                                         }
+#if DEBUG
+                                        string ddd = "";
+                                        foreach (var bb in packet.Bytes)
+                                        {
+                                            ddd += bb + ",";
+                                        }
+                                        MainPage.Log($"mqtt bus data:{ddd}");
+#endif
                                         packet.Manager();
                                     }
                                     else
                                     {
+                                        MainPage.Log($"mqtt A-Link data");
                                         //A鍗忚鏁版嵁澶勭悊
                                         var revString = Encoding.UTF8.GetString(bytes);
                                         Control.Ins.UpdataFunctionStatus(revString,null);
@@ -312,25 +325,9 @@
                     //(3)ConnectedHandler
                     if (RemoteMqttClient.ConnectedHandler == null)
                     {
-                        RemoteMqttClient.UseConnectedHandler(async (e) => {
-                            if (DB_ResidenceData.Instance.HomeGateway.gatewayStatus)
-                            {
-                                Control.Ins.GatewayOnline = true;
-                            }
-                            else
-                            {
-                                //new System.Threading.Thread(() => {
-                                //    while(true)
-                                //    {
-                                //        System.Threading.Thread.Sleep(1000);
-                                //        if (DB_ResidenceData.Instance.HomeGateway.GatewayOnline)
-                                //        {
-                                //            Control.Ins.GatewayOnline = true;
-                                //            break;
-                                //        }
-                                //    }
-                                //}) { IsBackground = true }.Start();
-                            }
+                        RemoteMqttClient.UseConnectedHandler(async (e) =>
+                        {
+                            Control.Ins.GatewayOnline = true;
                             IfNeedReadAllDeviceStatus = true;
                             Utlis.WriteLine($"============>Mqtt杩滅▼杩炴帴鎴愬姛");
                             SendPushSignOut();
@@ -655,7 +652,6 @@
         /// 鏄惁闇�瑕佽鍙栦竴娆℃墍鏈夎澶囩姸鎬�
         /// </summary>
         static bool IfNeedReadAllDeviceStatus = true;
-        //public static bool IsGatewayOnline = true;
 
         /// <summary>
         /// 璁剧疆缃戝叧鍦ㄧ嚎鏍囧織锛屽苟閲嶇疆CheckGateway鍙傛暟

--
Gitblit v1.8.0