JLChen
2020-12-09 e87985ec1dcb69beedaf9f95e8e7aba14b7c08d6
HDL_ON/DAL/Mqtt/MqttClient.cs
@@ -10,6 +10,7 @@
using System.Security.Cryptography;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.UI;
namespace HDL_ON.DAL.Mqtt
{
@@ -20,7 +21,7 @@
        /// </summary>
        static string mqttEncryptKey = "";
        //static string checkGatewayTopicBase64 = "";
        static bool hadGateway = true;
        /// <summary>
        /// 挤下线主题
        /// </summary>
@@ -131,7 +132,7 @@
        static void InitMqtt()
        {
            new System.Threading.Thread(async () => {
                while (true)
                while (hadGateway)
                {
                    try
                    {
@@ -180,7 +181,7 @@
                    var topicAlinkStatus = new MqttTopicFilter()
                    {
                        Topic = $"/user/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/app/thing/property/#",
                        Topic = $"/user/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/app/thing/property/send",
                        QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
                    };
@@ -209,7 +210,6 @@
        /// </summary>
        public static async Task StartCloudMqtt()
        {
            if (OnAppConfig.Instance.internetStatus == 0)
            {
                return;
@@ -232,7 +232,7 @@
                try
                {
                    #region 初始化远程Mqtt
                    remoteMqttIsConnecting = true;
                    RemoteMqttClient = new MqttFactory().CreateMqttClient();
@@ -268,7 +268,9 @@
                                else
                                {
                                    SetGatewayOnlineResetCheck();
                                    if (Entity.DB_ResidenceData.residenceData.GatewayType == 0)
                                    Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, DB_ResidenceData.residenceData.HomeGateway.aesKey);
                                    //bus数据解析
                                    if (DB_ResidenceData.residenceData.GatewayType == 0)
                                    {
                                        var packet = new Packet();
@@ -285,6 +287,8 @@
                                    else
                                    {
                                        //A协议数据处理
                                        var revString = Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
                                        Control.Ins.UpdataFunctionStatus(revString);
                                    }
                                }
                            }
@@ -308,11 +312,7 @@
                            IfNeedReadAllDeviceStatus = true;
                            Utlis.WriteLine($"============>Mqtt远程连接成功");
                            SendPushSignOut();
                            //if (Control.Ins.IsRemote) {
                            //    //Utlis.ShowAppLinkStatus (AppLinkStatus.CloudLink);
                            //    MainPage.AddTip (Language.StringByID (SimpleControl.R.MyInternationalizationString.LinkSuccess));
                            //}
                            FunctionList.List.ReadAllFunctionStatus();
                        });
                    }
                    #endregion
@@ -634,7 +634,8 @@
        {
            if (Control.Ins.IsRemote)
            {
                Control.Ins.GatewayOnline = true;
                if (!Control.Ins.GatewayOnline)
                    Control.Ins.GatewayOnline = true;
            }
        }
@@ -661,6 +662,7 @@
                else
                {
                    Utlis.WriteLine("============>还没绑定网关");
                    hadGateway = false;
                }
            }
        }