From ea0b1e8e5f43c5fd0a7d479e25ede3b8cbea464a Mon Sep 17 00:00:00 2001
From: wxr <wxr@hdlchina.com.cn>
Date: 星期一, 02 十二月 2024 17:17:19 +0800
Subject: [PATCH] tcp;可视对讲;

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

diff --git a/HDL_ON/DAL/Mqtt/MqttClient.cs b/HDL_ON/DAL/Mqtt/MqttClient.cs
index 1262268..87d29a4 100644
--- a/HDL_ON/DAL/Mqtt/MqttClient.cs
+++ b/HDL_ON/DAL/Mqtt/MqttClient.cs
@@ -12,6 +12,7 @@
 using HDL_ON.Entity;
 using HDL_ON.UI;
 using HDL_ON.DAL.Server;
+using HDL_ON;
 
 namespace HDL_ON.DAL.Mqtt
 {
@@ -110,6 +111,7 @@
             {
                 MqttInfoConfig.Current.IfGetMqttInfoSuccess = false;
             }
+            //Control.Ins.GatewayOnline_Cloud = Control.Ins.GatewayOnline_Local = false;
             await DisConnectRemoteMqttClient(s);
         }
 
@@ -143,6 +145,7 @@
 
                         await StartCloudMqtt();
                         await SubscribeTopics();
+
                     }
                     catch { }
                 }
@@ -159,7 +162,7 @@
             StartCloudMqtt();
         }
 
-        static bool isSubscribeSuccess;
+        public static bool isSubscribeSuccess;
         /// <summary>
         /// 璁㈤槄涓婚
         /// </summary>
@@ -202,6 +205,12 @@
                     var pirStudy = new MqttTopicFilter()
                     {
                         Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/irCodeStudyDone/up",
+                        QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
+                    };
+                    //App璁㈤槄缇ゆ帶鐘舵�佷富棰�
+                    var groupControlStatus = new MqttTopicFilter()
+                    {
+                        Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/device/group/control/property/send",
                         QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
                     };
 
@@ -255,13 +264,18 @@
                     #endregion
 
 
-                    Utlis.WriteLine("寮�濮嬭闃咃紒");
-                    var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] {
+                    Utlis.WriteLine("寮�濮嬭闃咃紒"); 
+                     var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] {
                         pirStatus,pirStudy,
                         appDeviceRefresh,appHomeRefresh,appRoomRefresh,residenceChange,
                         topicFilterPush2, topicAlinkStatus ,mqttkeyChange,
                         deviceOnlinePush,
                         securityStatusChange});
+                    //璁㈤槄缇ゆ帶鐘舵��
+                    if (DB_ResidenceData.Instance.HomeGateway.isSupportGroupControl)
+                    {
+                        await RemoteMqttClient.SubscribeAsync(groupControlStatus);
+                    }
                     if (result.Items[0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0)
                     {
                         isSubscribeSuccess = true;
@@ -363,7 +377,7 @@
                             try
                             {
                                 var topic = e.ApplicationMessage.Topic;
-                                //MainPage.Log($"鏀跺埌mqtt涓婚:{topic}");
+                                MainPage.Log($"鏀跺埌mqtt涓婚:{topic}");
                                 //涓�绔彛涓婚澶勭悊
                                 if (DB_ResidenceData.Instance.GatewayType == 0 && !DB_ResidenceData.Instance.CheckWhetherGatewayIdIsNull())
                                 {
@@ -446,10 +460,10 @@
                                 }
                                 #region 鏁版嵁鏇存柊鎺ㄩ�佷富棰�
                                 //appHomeRefresh锛氫綇瀹呮暟鎹埛鏂伴�氱煡
-                                else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appHomeRefresh/up"
-                                        || topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appDeviceRefresh/up")
+                                else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appHomeRefresh/up")
                                 {
                                     MainPage.Log("浣忓畢鏁版嵁鍒锋柊閫氱煡");
+                                    System.Threading.Thread.Sleep(2000);
                                     new HttpServerRequest().GetHomePager();
                                 }
                                 //appRoomRefresh锛氭埧闂存暟鎹埛鏂伴�氱煡
@@ -478,48 +492,6 @@
                                 else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appDeviceRefresh/up")
                                 {
                                     MainPage.Log("璁惧鏁版嵁鍒锋柊閫氱煡");
-                                    var deviceResult = new HttpServerRequest().GetDeviceList();
-                                    if (deviceResult.Code == StateCode.SUCCESS)
-                                    {
-                                        MainPage.Log($"璇诲彇璁惧淇℃伅鎴愬姛");
-                                        var deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString());
-                                        if (deviceList == null)
-                                        {
-                                            deviceList = new DevcieApiPack();
-                                        }
-                                        string delFile = "";
-                                        if (FunctionList.List.GetDeviceFunctionList().Count > 0)
-                                        {
-                                            for (int i = 0; i < FunctionList.List.GetDeviceFunctionList().Count;)
-                                            {
-                                                var localFunction = FunctionList.List.GetDeviceFunctionList()[i];
-                                                if (SPK.MusicSpkList().Contains(localFunction.spk))
-                                                {
-                                                    i++;
-                                                    continue;
-                                                }
-                                                var newFunction = deviceList.list.Find((obj) => obj.deviceId == localFunction.deviceId);
-
-                                                if (delFile == localFunction.savePath)
-                                                {
-                                                    i++;
-                                                    continue;
-                                                }
-                                                delFile = localFunction.savePath;
-                                                FunctionList.List.DeleteFunction(localFunction);
-                                            }
-                                        }
-                                        //澶勭悊鍓╀笅鐨勬柊澧炲姛鑳�
-                                        foreach (var newFunction in deviceList.list)
-                                        {
-                                            newFunction.SaveFunctionFile();
-                                            FunctionList.List.IniFunctionList(newFunction.savePath);
-                                        }
-                                    }
-                                    else
-                                    {
-                                        MainPage.Log($"璇诲彇浜戠璁惧鏁版嵁澶辫触:Code:{deviceResult.Code};  Msg:{deviceResult.message}");
-                                    }
                                 }
                                 //缃戝叧瀵嗛挜鍙樺寲
                                 else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/custom/mqtt/secret/change")
@@ -564,14 +536,21 @@
                                     }
                                 }
                                 #endregion
+                                //缇ゆ帶鐘舵��
+                                else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/device/group/control/property/send")
+                                {
+                                    var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, tuyaEncryptKey);
+                                    var revString = Encoding.UTF8.GetString(bytes);
+                                    MainPage.Log($"mqtt 缇ゆ帶鐘舵�佹洿鏂�:{revString}");
+                                    Control.Ins.UpdataGroupControlStatus(revString, null, true);
+                                }
                                 //A缃戝叧璁惧鐘舵��-鍖呭惈娑傞甫璁惧
                                 //Tag 缃戠粶鐘舵�佽В鏋�
                                 else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/property/send")
                                 {
-
                                     var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, tuyaEncryptKey);
                                     var revString = Encoding.UTF8.GetString(bytes);
-                                    MainPage.Log($"mqtt 鐘舵�佹洿鏂�:{revString}");
+                                    //MainPage.Log($"mqtt 鐘舵�佹洿鏂�:{revString}");
                                     Control.Ins.UpdataFunctionStatus(revString, null, true);
                                     //Control.Ins.MsgInfoList.Add($"mqtt 鐘舵�佹洿鏂�:{revString}");
                                     //Control.Ins.MsgInfoList.Add(revString + "\r\n");
@@ -665,7 +644,7 @@
                 }
                 catch (Exception ex)
                 {
-                    Utlis.WriteLine($"error:" + ex.Message);
+                    Utlis.WriteLine($"mqtt杩炴帴寮傚父 error:" + ex.Message);
                     //mqtt杩炴帴寮傚父锛屾竻绌烘湰鍦癿qtt淇℃伅锛屽彲鑳介渶瑕侀噸鏂拌幏鍙栵細wxr
                     MqttInfoConfig.Current.Refresh();
                 }
@@ -852,15 +831,13 @@
         /// </summary>
         static void ReceiveNotifySqueezeAsync(string mMes)
         {
-#if DEBUG
-            return;
-#endif
             if (mMes == PushSignStr) return;//鏄嚜宸辩殑鐧诲綍鎺ㄩ�佷笉澶勭悊//鎴栬�呭綋鍓嶄笉鏄繙绋嬮摼鎺ョ姸鎬�
             //娴嬭瘯璐﹀彿锛屼笉鎸や笅绾�
             switch (UserInfo.Current.userMobileInfo)
             {
                 case "15626203746":
-                case "464027401@qq.com":
+                case "13924245850":
+                case "13411390230":
                     return;
             }
 
@@ -911,9 +888,7 @@
         static void SendPushSignOut()
         {
             byte[] message = Encoding.UTF8.GetBytes(PushSignStr);
-#if DEBUG
             MqttRemoteSend(message, 4);
-#endif
         }
 
         /// <summary>
@@ -997,11 +972,11 @@
             var mqttInfoRequestResult_Obj = new HttpServerRequest().GetMqttRemoteInfo(GetRandomKey());
             if (mqttInfoRequestResult_Obj != null)
             {
-                MainPage.Log($"鑾峰彇mqtt info 鎴愬姛 \r\n clientId:{mqttInfoRequestResult_Obj.clientId}\r\n passWord:{mqttInfoRequestResult_Obj.passWord} \r\n url:{mqttInfoRequestResult_Obj.url}\r\n userName:{mqttInfoRequestResult_Obj.userName}");
+                MainPage.Log($"鑾峰彇mqtt info 鎴愬姛 /r/n clientId:{mqttInfoRequestResult_Obj.clientId}/r/n passWord:{mqttInfoRequestResult_Obj.passWord} /r/n url:{mqttInfoRequestResult_Obj.url}/r/n userName:{mqttInfoRequestResult_Obj.userName}");
 
 
                 MqttInfoConfig.Current.mMqttInfo = mqttInfoRequestResult_Obj;
-                await MQTTConnectAsync();
+                //await MQTTConnectAsync();
                 //1.鍒ゆ柇鏄惁缁戝畾浜嗙綉鍏筹紝鑾峰彇缃戝叧杩滅▼杩炴帴鐨勫姞瀵咾EY
                 //if (DB_ResidenceData.Instance.CheckWhetherGatewayIsBound())
                 {
@@ -1168,7 +1143,7 @@
             }
             catch (Exception ex)
             {
-                Console.WriteLine(ex.Message);
+                MainPage.Log(ex.Message);
             }
             return reData;
         }

--
Gitblit v1.8.0