| | |
| | | } |
| | | |
| | | if (aesDecryptTopic == $"/BusGateWayToClient/{CurRemoteMACInfo.macMark}/Common/CheckGateway") { |
| | | MainPage.WiFiStatus = "CrabtreeAdd/CloudUnlink.png"; |
| | | // = $"/ClientToBusGateWay/{CurRemoteMACInfo.macMark}/Common/OldON"; |
| | | var ss = CommonPage.MyEncodingUTF8.GetString (aesDecryptPayload); |
| | | var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack> (ss); |
| | |
| | | case "NoOnline": |
| | | case "NetworkAnomaly"://不在线 |
| | | MainPage.AddTip ("Gateway offline"); |
| | | Application.RunOnMainThread (() => { |
| | | Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; |
| | | }); |
| | | //Application.RunOnMainThread (() => { |
| | | // Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; |
| | | //}); |
| | | break; |
| | | case "NoRecord"://MAC不正确 |
| | | MainPage.AddTip (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.MACError)); |
| | | Application.RunOnMainThread (() => { |
| | | Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; |
| | | }); |
| | | //Application.RunOnMainThread (() => { |
| | | // Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; |
| | | //}); |
| | | break; |
| | | case "Success": |
| | | MainPage.AddTip (UserConfig.Instance.CurrentRegion.RegionName + ":" + Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.LinkSuccess)); |
| | | MainPage.WiFiStatus = "CrabtreeAdd/CloudLink.png"; |
| | | break; |
| | | default: |
| | | MainPage.AddTip (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.LinkLoser)); |
| | | Application.RunOnMainThread (() => { |
| | | Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; |
| | | }); |
| | | //Application.RunOnMainThread (() => { |
| | | // Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; |
| | | //}); |
| | | break; |
| | | } |
| | | Application.RunOnMainThread (() => { |
| | | UserMiddle.btnLinkStatus.UnSelectedImagePath = MainPage.WiFiStatus; |
| | | }); |
| | | } else { |
| | | if (!string.IsNullOrEmpty (mqttEncryptKey)) { |
| | | aesDecryptTopic = Shared.Securitys.EncryptionService.AesDecryptTopic (e.ApplicationMessage.Topic, mqttEncryptKey); |
| | |
| | | if (CommonPage.IsRemote) { |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.Loading.Hide (); |
| | | Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; |
| | | //Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; |
| | | }); |
| | | } |
| | | } else { |
| | |
| | | } |
| | | if (RemoteMqttClient.ConnectedHandler == null) { |
| | | RemoteMqttClient.UseConnectedHandler (async (e) => { |
| | | Shared.Application.RunOnMainThread (() => { |
| | | Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = 0xAA69E64A; |
| | | }); |
| | | //Shared.Application.RunOnMainThread (() => { |
| | | // Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = 0xAA69E64A; |
| | | //}); |
| | | Shared.SimpleControl.Phone.UserMiddle.ReadAllDeviceStatus (); |
| | | System.Console.WriteLine ($"远程连接成功"); |
| | | MainPage.WiFiStatus = "CrabtreeAdd/CloudLink.png"; |
| | |
| | | MainPage.AddTip ("Remote failed,gateway offline"); |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.Loading.Hide (); |
| | | Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; |
| | | //Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; |
| | | }); |
| | | } else { |
| | | MqttRemoteSend (new byte [] { 0 }, 3); |
| | |
| | | if (tempResult == null) { |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.Loading.Hide (); |
| | | Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; |
| | | //Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; |
| | | }); |
| | | return; |
| | | } |
| | |
| | | if (tempResult == null) { |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.Loading.Hide (); |
| | | Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; |
| | | //Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; |
| | | }); |
| | | return; |
| | | } |
| | | //--第一步:获取mqtt链接参数 |
| | | var mqttInfoUrl = @"https://developer.hdlcontrol.com/Center/Center/GetConnMqttInfo";//获取连接远程云端Emq Mqtt 服务器连接信息 |
| | | var mqttInfoRequestPar = new RemoteRequestParameters () { LoginAccessToken = mqttRequestParToken, RequestVersion = MainPage.CodeIDString, RequestProtocolType = 0, RequestSource = 1 }; |
| | | var mqttInfoRequestResult = MainPage.RequestHttps ("", Newtonsoft.Json.JsonConvert.SerializeObject (mqttInfoRequestPar), false, false, mqttInfoUrl); |
| | | |
| | | if (mqttInfoRequestResult != null && mqttInfoRequestResult.ResponseData != null) { |
| | | try { |
| | | try { |
| | | //--第一步:获取mqtt链接参数 |
| | | var mqttInfoUrl = @"https://developer.hdlcontrol.com/Center/Center/GetConnMqttInfo";//获取连接远程云端Emq Mqtt 服务器连接信息 |
| | | var mqttInfoRequestPar = new RemoteRequestParameters () { LoginAccessToken = mqttRequestParToken, RequestVersion = MainPage.CodeIDString, RequestProtocolType = 0, RequestSource = 1 }; |
| | | var mqttInfoRequestResult = MainPage.RequestHttps ("", Newtonsoft.Json.JsonConvert.SerializeObject (mqttInfoRequestPar), false, false, mqttInfoUrl); |
| | | if (mqttInfoRequestResult != null && mqttInfoRequestResult.ResponseData != null) { |
| | | var mqttInfoRequestResult_Obj = Newtonsoft.Json.JsonConvert.DeserializeObject<MqttInfo> (mqttInfoRequestResult.ResponseData.ToString ()); |
| | | if (mqttInfoRequestResult_Obj != null) { |
| | | url = mqttInfoRequestResult_Obj.connEmqDomainPort; |
| | |
| | | var gatewayListRequestResult_Obj = Newtonsoft.Json.JsonConvert.DeserializeObject<MqttRemoteInfo> (gatewayListRequestResult.ResponseData.ToString ()); |
| | | //--找出是否存在匹配当前住宅的mac,存在再进行远程。 |
| | | CurRemoteMACInfo = gatewayListRequestResult_Obj.pageData.Find ((obj) => obj.mac == UserConfig.Instance.CurrentRegion.MAC); |
| | | CurRemoteMACInfo = gatewayListRequestResult_Obj.pageData [0]; |
| | | if (CurRemoteMACInfo != null) { |
| | | CurRemoteMACInfo.LoginAccessToken = mqttRequestPar.Token; |
| | | mqttEncryptKey = CurRemoteMACInfo.aesKey; |
| | |
| | | await MqttRemoteSend (new byte [] { 0 }, 2); |
| | | } |
| | | } |
| | | } catch { } |
| | | |
| | | } |
| | | } catch (Exception ex) { |
| | | Console.WriteLine (ex.Message); |
| | | } |
| | | } catch (Exception ex) { |
| | | System.Console.WriteLine ("============>" + ex.Message); |
| | |
| | | //MainPage.Loading.Hide (); |
| | | //isConnecting = false.ToString (); |
| | | |
| | | Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; |
| | | //Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; |
| | | #if DEBUG |
| | | Alert a = new Alert (remoteMqttIsConnecting.ToString (), ex.Message, "Close"); |
| | | a.Show (); |