wxr
2020-12-19 e327510c7329aa9a95e62a460ec659ea0c9563ad
HDL_ON/DAL/Mqtt/MqttClient.cs
@@ -119,7 +119,7 @@
        /// <summary>
        /// 外网的MQTT是否正在连接
        /// </summary>
        public static bool remoteMqttIsConnecting;
        public static bool RemoteMqttIsConnecting;
        static bool remoteIsConnected;
        static MqttClient()
@@ -138,6 +138,8 @@
                    {
                        System.Threading.Thread.Sleep(500);
                        if (!Control.Ins.IsRemote) continue;
                        //进入后台不处理
                        if (MainPage.IsEnterBackground) continue;
                        await StartCloudMqtt();
                        await SubscribeTopics();
@@ -221,7 +223,7 @@
            }
            //追加:没有远程连接的权限
            if (remoteMqttIsConnecting || remoteIsConnected)
            if (RemoteMqttIsConnecting || remoteIsConnected)
            {
                return;
            }
@@ -232,7 +234,7 @@
                try
                {
                    #region 初始化远程Mqtt
                    remoteMqttIsConnecting = true;
                    RemoteMqttIsConnecting = true;
                    RemoteMqttClient = new MqttFactory().CreateMqttClient();
@@ -289,7 +291,7 @@
                                    {
                                        //A协议数据处理
                                        var revString = Encoding.UTF8.GetString(bytes);
                                        Control.Ins.UpdataFunctionStatus(revString);
                                        Control.Ins.UpdataFunctionStatus(revString,null);
                                    }
                                }
                            }
@@ -310,11 +312,27 @@
                    if (RemoteMqttClient.ConnectedHandler == null)
                    {
                        RemoteMqttClient.UseConnectedHandler(async (e) => {
                            Control.Ins.GatewayOnline = true;
                            if (DB_ResidenceData.Instance.HomeGateway.gatewayStatus)
                            {
                                Control.Ins.GatewayOnline = true;
                            }
                            else
                            {
                                //new System.Threading.Thread(() => {
                                //    while(true)
                                //    {
                                //        System.Threading.Thread.Sleep(1000);
                                //        if (DB_ResidenceData.Instance.HomeGateway.GatewayOnline)
                                //        {
                                //            Control.Ins.GatewayOnline = true;
                                //            break;
                                //        }
                                //    }
                                //}) { IsBackground = true }.Start();
                            }
                            IfNeedReadAllDeviceStatus = true;
                            Utlis.WriteLine($"============>Mqtt远程连接成功");
                            SendPushSignOut();
                            //FunctionList.List.ReadAllFunctionStatus();
                        });
                    }
                    #endregion
@@ -341,7 +359,7 @@
                finally
                {
                    //最终要释放连接状态
                    remoteMqttIsConnecting = false;
                    RemoteMqttIsConnecting = false;
                    Utlis.WriteLine($"StartCloudMqtt: 结束");
                }