| | |
| | | static MqttCommon () |
| | | { |
| | | InitMqtt (); |
| | | InitCheckGateway (); |
| | | //InitCheckGateway (); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | if (RemoteMqttClient.ConnectedHandler == null) { |
| | | RemoteMqttClient.UseConnectedHandler (async (e) => { |
| | | IfNeedReadAllDeviceStatus = true; |
| | | mCheckGatewayTime = DateTime.Now; |
| | | CheckGatewayCount = 0; |
| | | bNeedStartTip = true; |
| | | |
| | | Utlis.WriteLine ($"============>Mqtt远程连接成功"); |
| | | if (CommonPage.IsRemote) { |
| | |
| | | } |
| | | MainPage.AddTip ("Remote failed,gateway offline"); |
| | | } else { |
| | | //Remote Connection Succeeded |
| | | |
| | | //网关在线 |
| | | |
| | | //重新一次所有设备状态 |
| | |
| | | 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") { |
| | |
| | | } |
| | | #endregion |
| | | //} |
| | | //正在获取连接参数..." |
| | | ShowStartTip (); |
| | | |
| | | mqttRequestParToken = MainPage.LoginUser.LoginTokenString; |
| | | //--第一步:获取mqtt链接参数 |
| | |
| | | Utlis.WriteLine ("============>Mqtt 取消连接,当前住宅没绑定网关"); |
| | | } |
| | | |
| | | } else { |
| | | Utlis.WriteLine ("============>Mqtt GetGatewayPagger 失败"); |
| | | } |
| | | |
| | | } else { |
| | | Utlis.WriteLine ("============>Mqtt GetInfo 失败"); |
| | | } |
| | | } else { |
| | | //如果是分享过来的住宅 走下面流程 |
| | |
| | | { |
| | | |
| | | 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; |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // 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> |
| | | ///// |
| | |
| | | if (CheckGatewayCount >= 3) { |
| | | //连续3次没回复,判定网关超时 |
| | | if (MainPage.WiFiStatus == "CrabtreeAdd/CloudLink.png") { |
| | | IsGatewayOnline = false; |
| | | //IsGatewayOnline = false; |
| | | Utlis.ShowAppLinkStatus (AppLinkStatus.CloudOffline); |
| | | MainPage.AddTip ("Gateway offline!"); |
| | | } |
| | |
| | | static void ReceiveCheckGatewayTopic () { |
| | | //Utlis.WriteLine ("============>Mqtt CheckGateway网关回复"); |
| | | SetGatewayOnlineResetCheck (); |
| | | |
| | | |
| | | |
| | | //旧网关方法 |