JLChen
2020-04-16 9ca2281d589fbd4b35177d1846974f17d12095ae
Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs
@@ -45,7 +45,7 @@
        static MqttCommon ()
        {
            InitMqtt ();
            InitCheckGateway ();
            //InitCheckGateway ();
        }
        /// <summary>
@@ -239,6 +239,9 @@
                        if (RemoteMqttClient.ConnectedHandler == null) {
                            RemoteMqttClient.UseConnectedHandler (async (e) => {
                                IfNeedReadAllDeviceStatus = true;
                            mCheckGatewayTime = DateTime.Now;
                            CheckGatewayCount = 0;
                            bNeedStartTip = true;
                                Utlis.WriteLine ($"============>Mqtt远程连接成功");
                                if (CommonPage.IsRemote) {
@@ -254,6 +257,8 @@
                                        }
                                        MainPage.AddTip ("Remote failed,gateway offline");
                                    } else {
                                    //Remote Connection Succeeded
                                        //网关在线
                                        //重新一次所有设备状态
@@ -261,6 +266,10 @@
                                        Shared.SimpleControl.Phone.UserMiddle.ReadAllDeviceStatus ();
                                        //
                                        MqttRemoteSend (new byte [] { 0 }, 3);
                                    if (CommonPage.IsRemote) {
                                        MainPage.AddTip (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.LinkSuccess));
                                    }
                                    }
                                    //if (CurRemoteMACInfo.isValid == "InValid") {
@@ -275,6 +284,8 @@
                        }
                        #endregion
                    //}
                    //正在获取连接参数..."
                    ShowStartTip ();
                        mqttRequestParToken = MainPage.LoginUser.LoginTokenString;
                        //--第一步:获取mqtt链接参数
@@ -307,8 +318,12 @@
                                        Utlis.WriteLine ("============>Mqtt 取消连接,当前住宅没绑定网关");
                                    }
                            } else {
                                Utlis.WriteLine ("============>Mqtt GetGatewayPagger 失败");
                                }
                        } else {
                            Utlis.WriteLine ("============>Mqtt GetInfo 失败");
                            }
                        } else {
                            //如果是分享过来的住宅 走下面流程
@@ -349,6 +364,9 @@
        {
            if (CurRemoteMACInfo != null && mMqttInfo != null) {
                MainPage.AddTip ("Successfully obtained parameters, starting to connect...");
                var url = mMqttInfo.connEmqDomainPort;
                var clientId = mMqttInfo.connEmqClientId;
                var username = mMqttInfo.connEmqUserName;
@@ -375,6 +393,27 @@
            }
        }
//        571=Starting remote connection mode...
//572=Getting remote connection parameters...
//573=Successfully obtained parameters, starting to connect...
        /// <summary>
        /// 从开始到连接成功,只提示1次
        /// </summary>
        static bool bNeedStartTip = true;
        /// <summary>
        /// 正在获取连接参数...
        /// </summary>
        static void ShowStartTip ()
        {
            if (bNeedStartTip) {
                bNeedStartTip = false;
                if (CommonPage.IsRemote) {
                    MainPage.AddTip ("Getting remote connection parameters...");
                }
            }
        }
        ///// <summary>
        ///// 
@@ -638,7 +677,7 @@
                            if (CheckGatewayCount >= 3) {
                                //连续3次没回复,判定网关超时
                                if (MainPage.WiFiStatus == "CrabtreeAdd/CloudLink.png") {
                                    IsGatewayOnline = false;
                                    //IsGatewayOnline = false;
                                    Utlis.ShowAppLinkStatus (AppLinkStatus.CloudOffline);
                                    MainPage.AddTip ("Gateway offline!");
                                }
@@ -671,7 +710,6 @@
        static void ReceiveCheckGatewayTopic () {
            //Utlis.WriteLine ("============>Mqtt CheckGateway网关回复");
            SetGatewayOnlineResetCheck ();
            //旧网关方法