| | |
| | | if (mFlagDateTime.AddSeconds (20).Ticks <= System.DateTime.Now.Ticks) { |
| | | mFlagDateTime = DateTime.Now; |
| | | if (isConnectiong) { |
| | | Console.WriteLine ("20s》isConnectiong true "); |
| | | Utlis.WriteLine ("20s》isConnectiong true "); |
| | | isConnectiong = false; |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | new System.Threading.Thread (async () => { |
| | | |
| | | bool IsRemoteLoadingShow = false; |
| | | |
| | | try { |
| | | if (status == 0) { |
| | | Application.RunOnMainThread (() => { |
| | |
| | | }); |
| | | bool canRemote = false; |
| | | |
| | | |
| | | |
| | | //1.如果本地没网关数据,提示WiFiOffline,并且判断是否需要断开远程 |
| | | if (gateWayList == null || gateWayList.Count == 0) { |
| | |
| | | if (status == 2) { |
| | | //var result = Control.ControlBytesSendHasReturn (Command.ReadGateway, common.SubnetID, common.DeviceID, new byte [] { (byte)new Random ().Next (255), (byte)new Random ().Next (255) }); |
| | | #region |
| | | //开始本地搜索网关... |
| | | MainPage.LoadingStart ("Searching local gateway..."); |
| | | |
| | | var control = new Control (); |
| | | control.Send (new Target () { |
| | | IPEndPoint = new System.Net.IPEndPoint (System.Net.IPAddress.Parse (new Net.NetWiFi ().BroadcastIpAddress.ToString ()), 6000), |
| | |
| | | UserMiddle.btnLinkStatus.UnSelectedImagePath = MainPage.WiFiStatus; |
| | | MainPage.Loading.Hide (); |
| | | }); |
| | | //搜索成功,启用本地连接 |
| | | MainPage.AddTip ("Gateway searched successfully, enable local connection."); |
| | | |
| | | Shared.SimpleControl.Phone.UserMiddle.ReadAllDeviceStatus (); |
| | | await SmartHome.MqttCommon.DisConnectRemoteMqttClient (); |
| | | return; |
| | | } else { |
| | | |
| | | } |
| | | } else { |
| | | //搜索失败,启用远程连接 |
| | | MainPage.AddTip ("Gateway cannot be searched locally."); |
| | | |
| | | } |
| | | } else { |
| | | break; |
| | |
| | | if (UserConfig.Instance.CheckHomeGateways ()) { |
| | | if (!string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.HomeGateways [0].GatewayUniqueId)) { |
| | | // 5.1能远程,显示CloudUnlink状态,IsRemote设为true开始远程 |
| | | Utlis.ShowAppLinkStatus (AppLinkStatus.CloudUnlink); |
| | | //MainPage.AddTip ("Please wait, starting remote connection..."); |
| | | //MainPage.LoadingStart ("Please wait, starting remote connection..."); |
| | | |
| | | MainPage.LoadingTipShow ("Please wait, starting remote connection..."); |
| | | |
| | | CommonPage.IsRemote = true; |
| | | SmartHome.MqttCommon.IsGatewayOnline = false; |
| | | //await SmartHome.MqttCommon.StartCloudMqtt (); |
| | | IsRemoteLoadingShow = true; |
| | | //重置参数状态 |
| | | SmartHome.MqttCommon.InitState (); |
| | | Utlis.ShowAppLinkStatus (AppLinkStatus.CloudUnlink); |
| | | |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | Console.WriteLine ("CheckLinkRemote : " + ex.ToString ()); |
| | | Utlis.WriteLine ("CheckLinkRemote : " + ex.ToString ()); |
| | | } finally { |
| | | isConnectiong = false; |
| | | //if (!IsRemoteLoadingShow) { |
| | | // Application.RunOnMainThread (() => { |
| | | // MainPage.Loading.Hide (); |
| | | // }); |
| | | //} |
| | | |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.Loading.Hide (); |
| | | }); |
| | |
| | | }) { IsBackground = true }.Start (); |
| | | } |
| | | |
| | | |
| | | //static bool IsRemoteLoadingShow = false; |
| | | |
| | | /// <summary> |
| | | /// 关闭远程连接模式,并断开MQTT |