From 330e3ae4cdd1e9facb14b6ea2b3e609166c04fd3 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 12 一月 2021 16:00:27 +0800
Subject: [PATCH] 2021-1-12-1

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

diff --git a/HDL_ON/DAL/Mqtt/MqttClient.cs b/HDL_ON/DAL/Mqtt/MqttClient.cs
index eb7a731..8b725d6 100644
--- a/HDL_ON/DAL/Mqtt/MqttClient.cs
+++ b/HDL_ON/DAL/Mqtt/MqttClient.cs
@@ -32,18 +32,18 @@
         /// </summary>
         static string RandomKey = "";
 
+        /// <summary>
+        /// 闅忔満鐢熸垚瀛楃
+        /// </summary>
+        /// <returns></returns>
         static string GetRandomKey()
         {
             if (string.IsNullOrEmpty(RandomKey))
             {
                 //闅忔満2浣嶅瓧绗︿覆
-                Random random = new Random(Guid.NewGuid().GetHashCode());
-                int num = random.Next(65, 91);
-                RandomKey = Convert.ToChar(num).ToString();
+                RandomKey = Utlis.CreateRandomString(2);
             }
-
             return RandomKey;
-
         }
 
         /// <summary>
@@ -132,7 +132,7 @@
         static void InitMqtt()
         {
             new System.Threading.Thread(async () => {
-                while (hadGateway)
+                while (true)
                 {
                     try
                     {
@@ -160,6 +160,10 @@
         }
 
         static bool isSubscribeSuccess;
+        /// <summary>
+        /// 璁㈤槄涓婚
+        /// </summary>
+        /// <returns></returns>
         static async Task SubscribeTopics()
         {
             if (remoteIsConnected && !isSubscribeSuccess)
@@ -186,16 +190,17 @@
                         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
-                    };
+                    //var topicBusStatus = new MqttTopicFilter()
+                    //{
+                    //    Topic = $"/BusGateWayToClient/{}/Common",
+                    //    QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
+                    //};
 
                     Utlis.WriteLine("寮�濮嬭闃咃紒");
-                    var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { topicFilterBusGateWayToClient, topicFilterPush2, topicAlinkStatus, topicBusStatus });
+                    var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { topicFilterBusGateWayToClient, topicFilterPush2, topicAlinkStatus });
                     if (result.Items[0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0)
                     {
+                        Control.Ins.GatewayOnline = true;
                         isSubscribeSuccess = true;
                         Utlis.WriteLine("璁㈤槄鎴愬姛锛�");
 
@@ -327,7 +332,6 @@
                     {
                         RemoteMqttClient.UseConnectedHandler(async (e) =>
                         {
-                            Control.Ins.GatewayOnline = true;
                             IfNeedReadAllDeviceStatus = true;
                             Utlis.WriteLine($"============>Mqtt杩滅▼杩炴帴鎴愬姛");
                             SendPushSignOut();
@@ -540,9 +544,9 @@
         /// </summary>
         static void ReceiveNotifySqueezeAsync(string mMes)
         {
-#if DEBUG
+//#if DEBUG
             return;
-#endif
+//#endif
             if (mMes == PushSignStr) return;//鏄嚜宸辩殑鐧诲綍鎺ㄩ�佷笉澶勭悊
 
             //鏂紑杩滅▼杩炴帴
@@ -605,8 +609,6 @@
         /// <returns></returns>
         public static async Task MqttRemoteSend(byte[] message, int optionType = 0)
         {
-            //return;
-
             try
             {
                 string topicName;
@@ -661,7 +663,17 @@
             if (Control.Ins.IsRemote)
             {
                 if (!Control.Ins.GatewayOnline)
-                    Control.Ins.GatewayOnline = true;
+                {
+                    try
+                    {
+                        if (DB_ResidenceData.Instance.HomeGateway != null)
+                        {
+                            DB_ResidenceData.Instance.HomeGateway.gatewayStatus = true;
+                        }
+                        Control.Ins.GatewayOnline = true;
+                    }
+                    catch { }
+                }
             }
         }
 

--
Gitblit v1.8.0