陈嘉乐
2021-03-16 e1ac4ab0e68024e6289e0b11756962d662749b04
HDL_ON/DAL/Mqtt/MqttClient.cs
@@ -191,15 +191,24 @@
                        Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.RegionID}/app/thing/property/send",
                        QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
                    };
                    //设备入网上报主题(目前只有红外宝)
                    var topicFilterPush3 = new MqttTopicFilter()
                    //App订阅红外宝 / 网关遥控器添加成功通知
                    var pirStatus = new MqttTopicFilter()
                    {
                        Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.RegionID}/app/thing/topo/found",
                        QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
                    };
                    //App订阅遥控器自学按键学习成功通知
                    var study = new MqttTopicFilter()
                    {
                        Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.RegionID}/app/thing/event/irCodeStudyDone/up",
                        QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
                    };
                    Utlis.WriteLine("开始订阅!");
                    var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { topicFilterPush2, topicAlinkStatus, topicFilterPush3 });
                    var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] {
                        pirStatus,
                         study,
                        topicFilterPush2, topicAlinkStatus });
                    if (result.Items[0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0)
                    {
                        isSubscribeSuccess = true;
@@ -236,7 +245,7 @@
            Utlis.WriteLine($"StartCloudMqtt: 开始");
            await Task.Factory.StartNew(async () => {
            await Task.Factory.StartNew((Func<Task>)(async () => {
                try
                {
                    #region 初始化远程Mqtt
@@ -248,7 +257,7 @@
                    if (RemoteMqttClient.ApplicationMessageReceivedHandler == null)
                    {
                        //处理接收到的数据
                        RemoteMqttClient.UseApplicationMessageReceivedHandler((e) => {
                        RemoteMqttClient.UseApplicationMessageReceivedHandler((Action<MqttApplicationMessageReceivedEventArgs>)((e) => {
                            try
                            {
                                var topic = e.ApplicationMessage.Topic;
@@ -284,6 +293,24 @@
                                    //新挤下线主题方案 收到挤下线主题
                                    ReceiveNotifySqueezeAsync(mMes);
                                }
                                //App订阅红外宝/网关遥控器添加成功通知
                                else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.RegionID}/app/thing/topo/found")
                                {
                                    var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, tuyaEncryptKey);
                                    var revString = Encoding.UTF8.GetString(bytes);
                                    HDL_ON.UI.UI2.PersonalCenter.PirDevice.Method.controldata = revString;
                                    //ReceiveCheckGateway(ss);
                                    //return;
                                }
                                //App订阅遥控器自学按键学习成功通知
                                else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.RegionID}/app/thing/event/irCodeStudyDone/up")
                                {
                                    var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, tuyaEncryptKey);
                                    var revString = Encoding.UTF8.GetString(bytes);
                                    HDL_ON.UI.UI2.PersonalCenter.PirDevice.Method.buttondata = revString;
                                    //ReceiveCheckGateway(ss);
                                    //return;
                                }
                                //A网关设备状态-包含涂鸦设备
                                else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.RegionID}/app/thing/property/send")
                                {
@@ -311,7 +338,7 @@
                                }
                            }
                            catch { }
                        });
                        }));
                    }
                    //(2)DisconnectedHandler
@@ -362,7 +389,7 @@
                    Utlis.WriteLine($"StartCloudMqtt: 结束");
                }
            });
            }));
        }