wxr
2023-07-19 6fe1c5ebeb8312edc479a4576f05d80c5051a6c6
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);
        }
@@ -159,7 +161,7 @@
            StartCloudMqtt();
        }
        static bool isSubscribeSuccess;
        public static bool isSubscribeSuccess;
        /// <summary>
        /// 订阅主题
        /// </summary>
@@ -202,6 +204,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 +263,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 +376,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())
                                {
@@ -449,6 +462,7 @@
                                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:房间数据刷新通知
@@ -563,11 +577,18 @@
                                    }
                                }
                                #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}");
@@ -664,7 +685,7 @@
                }
                catch (Exception ex)
                {
                    Utlis.WriteLine($"error:" + ex.Message);
                    Utlis.WriteLine($"mqtt连接异常 error:" + ex.Message);
                    //mqtt连接异常,清空本地mqtt信息,可能需要重新获取:wxr
                    MqttInfoConfig.Current.Refresh();
                }
@@ -852,7 +873,7 @@
        static void ReceiveNotifySqueezeAsync(string mMes)
        {
#if DEBUG
            return;
            //return;
#endif
            if (mMes == PushSignStr) return;//是自己的登录推送不处理//或者当前不是远程链接状态
            //测试账号,不挤下线
@@ -1167,7 +1188,7 @@
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MainPage.Log(ex.Message);
            }
            return reData;
        }