From b3e96fce4cc01113128ddf8e0a18fc19594a9e56 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 05 十二月 2019 18:38:30 +0800
Subject: [PATCH] 一个新的版本

---
 ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
index 695486f..dffdf80 100755
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
@@ -603,7 +603,8 @@
                     var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 82 } };
                     var data = new JObject { { "HomeId", homeId }, { "AccountId", accountId } };
                     jObject.Add("Data", data);
-                    Send("GwSetHomeId", jObject.ToString());
+                    //浣忓畢ID鐨勮缃�,鍥哄畾浣跨敤灞�鍩熺綉,涓嶅瓨鍦ㄨ繙绋嬬殑璇存硶
+                    SendLocation("GwSetHomeId", System.Text.Encoding.UTF8.GetBytes(jObject.ToString()));
                 }
                 catch { }
 
@@ -3631,6 +3632,7 @@
                             await StartLocalMqtt("ReConnect");
                             if (localIsConnected)
                             {
+                                DebugPrintLog($"灞�鍩熺綉鈥斺�斾簩娆″彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_褰撳墠缃戝叧{CurrentGateWayId} 鏄惁鍔犲瘑:{IsEncry}");
                                 await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
                             }
                         }
@@ -3657,8 +3659,58 @@
                 return;
             }
             await Send(topic, System.Text.Encoding.UTF8.GetBytes(message), retain);
+        }
+
+        /// <summary>
+        /// 寮哄埗鎸囧畾浣跨敤鏈湴灞�鍩熺綉鍙戦�佹秷鎭埌鏈嶅姟鍣�
+        /// </summary>
+        /// <returns></returns>
+        /// <param name="topic"></param>
+        /// <param name="message"></param>
+        /// <param name="retain"></param>
+        public async Task SendLocation(string topic, byte[] message, bool retain = false)
+        {
+            try
+            {
+                if (Shared.Common.Config.Instance.HomeId == "")
+                {
+                    return;
+                }
+
+                DebugPrintLog($"灞�鍩熺綉鈥斺�斿彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_褰撳墠缃戝叧{CurrentGateWayId} 鏄惁鍔犲瘑:{IsEncry}");
+
+                if (IsEncry)
+                {
+                    //鏂囦欢娴佷笉鐢ㄥ姞瀵�
+                    if (topic != "FileTransfer/SendFile")
+                    {
+                        message = SecuritySet.AesEncryptBytes(message, password);
+                    }
+                }
+                if (localIsConnected)
+                {
+                    try
+                    {
+                        await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
+                    }
+                    catch (Exception e)
+                    {
+                        DebugPrintLog($"Local涓诲姩鏂紑_{e.Message}");
+                        await DisConnectLocalMqttClient(e.Message);
+                        await StartLocalMqtt("ReConnect");
+                        if (localIsConnected)
+                        {
+                            DebugPrintLog($"灞�鍩熺綉鈥斺�斾簩娆″彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_褰撳墠缃戝叧{CurrentGateWayId} 鏄惁鍔犲瘑:{IsEncry}");
+                            await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
+                        }
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                DebugPrintLog($"Send:{ex.Message}");
+            }
         }
-
 
         [Serializable]
         public class CloudTimeResponse

--
Gitblit v1.8.0