From 9ca2281d589fbd4b35177d1846974f17d12095ae Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期四, 16 四月 2020 15:12:02 +0800 Subject: [PATCH] 2020-04-16 1.更新 --- Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs | 358 +++++++++++++++++++++++++++++++++-------------------------- 1 files changed, 198 insertions(+), 160 deletions(-) diff --git a/Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs b/Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs index 8650a0b..f580d57 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs @@ -45,7 +45,7 @@ static MqttCommon () { InitMqtt (); - InitCheckGateway (); + //InitCheckGateway (); } /// <summary> @@ -130,17 +130,17 @@ try { if (remoteIsConnected) { remoteIsConnected = false; - System.Console.WriteLine ($"============>MqttRemote涓诲姩鏂紑_{s}"); + Utlis.WriteLine ($"============>MqttRemote涓诲姩鏂紑_{s}"); //await RemoteMqttClient.DisconnectAsync(new MQTTnet.Client.Disconnecting.MqttClientDisconnectOptions { }, CancellationToken.None); await RemoteMqttClient.DisconnectAsync (); if (CommonPage.IsRemote) { Utlis.ShowAppLinkStatus (AppLinkStatus.CloudUnlink); } - System.Console.WriteLine ($"============>MqttRemoteDisConnectRemoteMqttClient"); + Utlis.WriteLine ($"============>MqttRemoteDisConnectRemoteMqttClient"); } } catch (Exception e) { - System.Console.WriteLine ($"============>MqttRemote鏂紑閫氳杩炴帴鍑哄紓甯�:{e.Message}"); + Utlis.WriteLine ($"============>MqttRemote鏂紑閫氳杩炴帴鍑哄紓甯�:{e.Message}"); } } static DateTime dateTime = DateTime.MinValue; @@ -177,164 +177,179 @@ await System.Threading.Tasks.Task.Factory.StartNew (async () => { try { //lock (RemoteMqttClient) { - //琛ㄧず鍚庨潰灏嗚繘琛岃繛鎺� + //琛ㄧず鍚庨潰灏嗚繘琛岃繛鎺� - #region 鍒濆鍖栬繙绋婱qtt - //(3)褰揫杩炴帴浜戠鐨凪qtt鎴愬姛鍚嶿鎴栬�匸浠ュ強鍚庨潰App閫氳繃浜戠Mqtt杞彂鏁版嵁缁欑綉鍏虫垚鍔熷悗],澶勭悊鎺ユ敹鍒颁簯绔暟鎹寘鍝嶅簲鏃跺湪mqttServerClient_ApplicationMessageReceived杩欎釜鏂规硶澶勭悊 - if (RemoteMqttClient.ApplicationMessageReceivedHandler == null) { - RemoteMqttClient.UseApplicationMessageReceivedHandler (async (e) => { - try { - if (!RemoteMqttClient.IsConnected || !CommonPage.IsRemote) { - return; + #region 鍒濆鍖栬繙绋婱qtt + //(3)褰揫杩炴帴浜戠鐨凪qtt鎴愬姛鍚嶿鎴栬�匸浠ュ強鍚庨潰App閫氳繃浜戠Mqtt杞彂鏁版嵁缁欑綉鍏虫垚鍔熷悗],澶勭悊鎺ユ敹鍒颁簯绔暟鎹寘鍝嶅簲鏃跺湪mqttServerClient_ApplicationMessageReceived杩欎釜鏂规硶澶勭悊 + if (RemoteMqttClient.ApplicationMessageReceivedHandler == null) { + RemoteMqttClient.UseApplicationMessageReceivedHandler (async (e) => { + try { + if (!RemoteMqttClient.IsConnected || !CommonPage.IsRemote) { + return; + } + var aesDecryptTopic = e.ApplicationMessage.Topic; + var aesDecryptPayload = e.ApplicationMessage.Payload; + //Utlis.WriteLine ("Topic={0}", aesDecryptTopic); + + //if (aesDecryptTopic == $"NotifyBusGateWayInfoChagne/{CurRemoteMACInfo.md5_mac_string}") {//缃戝叧涓婄嚎锛岄渶瑕佹洿鏂癮eskey + //2020-01-11 淇敼璁㈤槄涓婚鍦板潃 + if (aesDecryptTopic == $"/BusGateWayToClient/{CurRemoteMACInfo.macMark}/NotifyBusGateWayInfoChange") {//缃戝叧涓婄嚎锛岄渶瑕佹洿鏂癮eskey //----绗簩姝ワ細璇诲彇璐﹀彿涓嬮潰鐨勭綉鍏冲垪琛� + await ReceiveNotifyBusGateWayInfoChange (); + } else if (aesDecryptTopic == $"/BusGateWayToClient/{CurRemoteMACInfo.macMark}/NotifyGateWayOffline") {//缃戝叧鎺夌嚎 //----绗簩姝ワ細璇诲彇璐﹀彿涓嬮潰鐨勭綉鍏冲垪琛� + ReceiveNotifyGateWayOffline (); + } else if (aesDecryptTopic == $"/BusGateWayToClient/{mMqttInfo.connEmqClientId}/Push/NotifySqueeze") {//璁㈤槄鎸や笅绾块棶棰� + await ReceiveNotifySqueezeAsync (aesDecryptPayload); + } else if (aesDecryptTopic == $"/BusGateWayToClient/{CurRemoteMACInfo.macMark}/Common/CheckGateway") { + ReceiveCheckGatewayTopic (); + } else { + SetGatewayOnlineResetCheck (); + + if (!string.IsNullOrEmpty (mqttEncryptKey)) { + aesDecryptPayload = Shared.Securitys.EncryptionService.AesDecryptPayload (e.ApplicationMessage.Payload, mqttEncryptKey); } - var aesDecryptTopic = e.ApplicationMessage.Topic; - var aesDecryptPayload = e.ApplicationMessage.Payload; - //Console.WriteLine ("Topic={0}", aesDecryptTopic); - //if (aesDecryptTopic == $"NotifyBusGateWayInfoChagne/{CurRemoteMACInfo.md5_mac_string}") {//缃戝叧涓婄嚎锛岄渶瑕佹洿鏂癮eskey - //2020-01-11 淇敼璁㈤槄涓婚鍦板潃 - if (aesDecryptTopic == $"/BusGateWayToClient/{CurRemoteMACInfo.macMark}/NotifyBusGateWayInfoChange") {//缃戝叧涓婄嚎锛岄渶瑕佹洿鏂癮eskey //----绗簩姝ワ細璇诲彇璐﹀彿涓嬮潰鐨勭綉鍏冲垪琛� - await ReceiveNotifyBusGateWayInfoChange (); - } else if (aesDecryptTopic == $"/BusGateWayToClient/{CurRemoteMACInfo.macMark}/NotifyGateWayOffline") {//缃戝叧鎺夌嚎 //----绗簩姝ワ細璇诲彇璐﹀彿涓嬮潰鐨勭綉鍏冲垪琛� - ReceiveNotifyGateWayOffline (); - } else if (aesDecryptTopic == $"/BusGateWayToClient/{mMqttInfo.connEmqClientId}/Push/NotifySqueeze") {//璁㈤槄鎸や笅绾块棶棰� - await ReceiveNotifySqueezeAsync (aesDecryptPayload); - }else if (aesDecryptTopic == $"/BusGateWayToClient/{CurRemoteMACInfo.macMark}/Common/CheckGateway") { - ReceiveCheckGatewayTopic (); - } else { - SetGatewayOnlineResetCheck (); + var packet = new Packet (); + packet.IsLocal = false; + packet.Bytes = aesDecryptPayload; + packet.Manager (); - if (!string.IsNullOrEmpty (mqttEncryptKey)) { - aesDecryptPayload = Shared.Securitys.EncryptionService.AesDecryptPayload (e.ApplicationMessage.Payload, mqttEncryptKey); - } + } - var packet = new Packet (); - packet.IsLocal = false; - packet.Bytes = aesDecryptPayload; - packet.Manager (); + } catch { } + }); + } + if (RemoteMqttClient.DisconnectedHandler == null) { + RemoteMqttClient.UseDisconnectedHandler (async (e) => { + Utlis.WriteLine ($"============>Mqtt杩滅▼杩炴帴鏂紑"); + isSubscribeTopicSuccess = false; + await DisConnectRemoteMqttClient ("StartRemoteMqtt.DisconnectedHandler"); + //await StartRemoteMqtt(); + //if (thisShowTip) { + // if (CommonPage.IsRemote) { + // Application.RunOnMainThread (() => { + // MainPage.Loading.Hide (); + // }); + // } + //} else { + // thisShowTip = true; + //} + }); + } + if (RemoteMqttClient.ConnectedHandler == null) { + RemoteMqttClient.UseConnectedHandler (async (e) => { + IfNeedReadAllDeviceStatus = true; + mCheckGatewayTime = DateTime.Now; + CheckGatewayCount = 0; + bNeedStartTip = true; + + Utlis.WriteLine ($"============>Mqtt杩滅▼杩炴帴鎴愬姛"); + if (CommonPage.IsRemote) { + Utlis.ShowAppLinkStatus (AppLinkStatus.CloudLink); + } + + if (CurRemoteMACInfo != null) { + IsGatewayOnline = CurRemoteMACInfo.isValid != "InValid"; + if (!IsGatewayOnline) { + //缃戝叧涓嶅湪绾� + if (CommonPage.IsRemote) { + Utlis.ShowAppLinkStatus (AppLinkStatus.CloudOffline); } - - } catch { } - }); - } + MainPage.AddTip ("Remote failed,gateway offline"); + } else { + //Remote Connection Succeeded - if (RemoteMqttClient.DisconnectedHandler == null) { - RemoteMqttClient.UseDisconnectedHandler (async (e) => { - System.Console.WriteLine ($"============>Mqtt杩滅▼杩炴帴鏂紑"); - isSubscribeTopicSuccess = false; - await DisConnectRemoteMqttClient ("StartRemoteMqtt.DisconnectedHandler"); - //await StartRemoteMqtt(); - //if (thisShowTip) { - // if (CommonPage.IsRemote) { - // Application.RunOnMainThread (() => { - // MainPage.Loading.Hide (); - // }); - // } + //缃戝叧鍦ㄧ嚎 + + //閲嶆柊涓�娆℃墍鏈夎澶囩姸鎬� + IfNeedReadAllDeviceStatus = false; + 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") { + // MainPage.AddTip ("Remote failed,gateway offline"); //} else { - // thisShowTip = true; + // MqttRemoteSend (new byte [] { 0 }, 3); //} - }); - } - if (RemoteMqttClient.ConnectedHandler == null) { - RemoteMqttClient.UseConnectedHandler (async (e) => { - IfNeedReadAllDeviceStatus = true; - - System.Console.WriteLine ($"============>Mqtt杩滅▼杩炴帴鎴愬姛"); - if (CommonPage.IsRemote) { - Utlis.ShowAppLinkStatus (AppLinkStatus.CloudLink); - } - - if (CurRemoteMACInfo != null) { - IsGatewayOnline = CurRemoteMACInfo.isValid != "InValid"; - if (!IsGatewayOnline) { - //缃戝叧涓嶅湪绾� - if (CommonPage.IsRemote) { - Utlis.ShowAppLinkStatus (AppLinkStatus.CloudOffline); - } - MainPage.AddTip ("Remote failed,gateway offline"); - } else { - //缃戝叧鍦ㄧ嚎 - - //閲嶆柊涓�娆℃墍鏈夎澶囩姸鎬� - IfNeedReadAllDeviceStatus = false; - Shared.SimpleControl.Phone.UserMiddle.ReadAllDeviceStatus (); - // - MqttRemoteSend (new byte [] { 0 }, 3); - } - - //if (CurRemoteMACInfo.isValid == "InValid") { - // MainPage.AddTip ("Remote failed,gateway offline"); - //} else { - // MqttRemoteSend (new byte [] { 0 }, 3); - //} - } + } - }); - } - #endregion + }); + } + #endregion //} + //姝e湪鑾峰彇杩炴帴鍙傛暟..." + ShowStartTip (); - mqttRequestParToken = MainPage.LoginUser.LoginTokenString; - //--绗竴姝ワ細鑾峰彇mqtt閾炬帴鍙傛暟 - var mqttInfoRequestResult = new ResponsePack () { StateCode = "" }; - //--鍒ゆ柇鏄綋鍓嶆槸鍚﹀垎浜殑浣忓畢 - if (!UserConfig.Instance.CurrentRegion.IsOthreShare) { - var mqttInfoUrl = $"{MainPage.RequestHttpsHost}/EmqMqtt/GetConnMqttInfo";//鑾峰彇杩炴帴杩滅▼浜戠Emq Mqtt 鏈嶅姟鍣ㄨ繛鎺ヤ俊鎭� - var mqttInfoRequestPar = new GetConnMqttInfoObj () { - LoginAccessToken = mqttRequestParToken, - PlatformStr = "L1", - PublishPayloadJsonStr = PushSignStr, - }; - mqttInfoRequestResult = MainPage.RequestHttps ("", Newtonsoft.Json.JsonConvert.SerializeObject (mqttInfoRequestPar), mqttInfoUrl); - if (mqttInfoRequestResult != null && mqttInfoRequestResult.ResponseData != null) { - var mqttInfoRequestResult_info = Newtonsoft.Json.JsonConvert.DeserializeObject<MqttInfo> (mqttInfoRequestResult.ResponseData.ToString ()); - if (mqttInfoRequestResult_info != null) { - mMqttInfo = mqttInfoRequestResult_info; - //----绗簩姝ワ細璇诲彇璐﹀彿涓嬮潰鐨勭綉鍏冲垪琛� - var gatewayListUrl = $"{MainPage.RequestHttpsHostMqtt}/Center/Center/GetGatewayPagger"; //App銆丅uspro杞欢鐧诲綍鍚庤幏鍙栫綉鍏冲垪琛� http 璇锋眰 - var gatewayListRequestPar = new RemoteRequestParameters () { LoginAccessToken = mqttRequestParToken, RequestVersion = "RequestVersion1", RequestProtocolType = 0, RequestSource = 1 }; - var gatewayListRequestResult = MainPage.RequestHttps ("", Newtonsoft.Json.JsonConvert.SerializeObject (gatewayListRequestPar), gatewayListUrl); - var gatewayListRequestResult_Obj = Newtonsoft.Json.JsonConvert.DeserializeObject<MqttRemoteInfo> (gatewayListRequestResult.ResponseData.ToString ()); - //--鎵惧嚭鏄惁瀛樺湪鍖归厤褰撳墠浣忓畢鐨刴ac锛屽瓨鍦ㄥ啀杩涜杩滅▼銆� - if (UserConfig.Instance.CheckHomeGatewaysNotEmpty ()) { - CurRemoteMACInfo = gatewayListRequestResult_Obj.pageData.Find ((obj) => obj.mac == UserConfig.Instance.CurrentRegion.HomeGateways [0].GatewayUniqueId); - //CurRemoteMACInfo = gatewayListRequestResult_Obj.pageData [0]; - await MQTTConnectAsync (); + mqttRequestParToken = MainPage.LoginUser.LoginTokenString; + //--绗竴姝ワ細鑾峰彇mqtt閾炬帴鍙傛暟 + var mqttInfoRequestResult = new ResponsePack () { StateCode = "" }; + //--鍒ゆ柇鏄綋鍓嶆槸鍚﹀垎浜殑浣忓畢 + if (!UserConfig.Instance.CurrentRegion.IsOthreShare) { + var mqttInfoUrl = $"{MainPage.RequestHttpsHost}/EmqMqtt/GetConnMqttInfo";//鑾峰彇杩炴帴杩滅▼浜戠Emq Mqtt 鏈嶅姟鍣ㄨ繛鎺ヤ俊鎭� + var mqttInfoRequestPar = new GetConnMqttInfoObj () { + LoginAccessToken = mqttRequestParToken, + PlatformStr = "L1", + PublishPayloadJsonStr = PushSignStr, + }; + mqttInfoRequestResult = MainPage.RequestHttps ("", Newtonsoft.Json.JsonConvert.SerializeObject (mqttInfoRequestPar), mqttInfoUrl); + if (mqttInfoRequestResult != null && mqttInfoRequestResult.ResponseData != null) { + var mqttInfoRequestResult_info = Newtonsoft.Json.JsonConvert.DeserializeObject<MqttInfo> (mqttInfoRequestResult.ResponseData.ToString ()); + if (mqttInfoRequestResult_info != null) { + mMqttInfo = mqttInfoRequestResult_info; + //----绗簩姝ワ細璇诲彇璐﹀彿涓嬮潰鐨勭綉鍏冲垪琛� + var gatewayListUrl = $"{MainPage.RequestHttpsHostMqtt}/Center/Center/GetGatewayPagger"; //App銆丅uspro杞欢鐧诲綍鍚庤幏鍙栫綉鍏冲垪琛� http 璇锋眰 + var gatewayListRequestPar = new RemoteRequestParameters () { LoginAccessToken = mqttRequestParToken, RequestVersion = "RequestVersion1", RequestProtocolType = 0, RequestSource = 1 }; + var gatewayListRequestResult = MainPage.RequestHttps ("", Newtonsoft.Json.JsonConvert.SerializeObject (gatewayListRequestPar), gatewayListUrl); + var gatewayListRequestResult_Obj = Newtonsoft.Json.JsonConvert.DeserializeObject<MqttRemoteInfo> (gatewayListRequestResult.ResponseData.ToString ()); + //--鎵惧嚭鏄惁瀛樺湪鍖归厤褰撳墠浣忓畢鐨刴ac锛屽瓨鍦ㄥ啀杩涜杩滅▼銆� + if (UserConfig.Instance.CheckHomeGatewaysNotEmpty ()) { + CurRemoteMACInfo = gatewayListRequestResult_Obj.pageData.Find ((obj) => obj.mac == UserConfig.Instance.CurrentRegion.HomeGateways [0].GatewayUniqueId); + //CurRemoteMACInfo = gatewayListRequestResult_Obj.pageData [0]; + await MQTTConnectAsync (); - } else { - System.Console.WriteLine ("============>Mqtt 鍙栨秷杩炴帴锛屽綋鍓嶄綇瀹呮病缁戝畾缃戝叧"); - } - + } else { + Utlis.WriteLine ("============>Mqtt 鍙栨秷杩炴帴锛屽綋鍓嶄綇瀹呮病缁戝畾缃戝叧"); } + } else { + Utlis.WriteLine ("============>Mqtt GetGatewayPagger 澶辫触"); } + } else { - //濡傛灉鏄垎浜繃鏉ョ殑浣忓畢 璧颁笅闈㈡祦绋� - var mqttInfoRequestPar = new ShareMemberConnMqttInfoObj () { - LoginAccessToken = mqttRequestParToken, - PlatformStr = "L1", - PublishPayloadJsonStr = PushSignStr, - MainUserDistributedMark = UserConfig.Instance.CurrentRegion.MainUserDistributedMark, - HomeId = UserConfig.Instance.CurrentRegion.Id - }; - mqttInfoRequestResult = MainPage.RequestHttps (API.ShareMemberConnMqttInfo, Newtonsoft.Json.JsonConvert.SerializeObject (mqttInfoRequestPar)); - //--绗竴姝ワ細鑾峰彇mqtt閾炬帴鍙傛暟 - if (mqttInfoRequestResult != null && mqttInfoRequestResult.ResponseData != null) { - var mqttInfoRequestResult_info = Newtonsoft.Json.JsonConvert.DeserializeObject<MqttInfo> (mqttInfoRequestResult.ResponseData.ToString ()); - if (mqttInfoRequestResult_info != null) { - mMqttInfo = mqttInfoRequestResult_info; - //--绗簩姝ワ細鑾峰彇褰撳墠浣忓垎浜畢缃戝叧淇℃伅骞惰繛鎺QTT - await GetSingleHomeGatewayPaggerAndMQTTConnectAsync (); - - } + Utlis.WriteLine ("============>Mqtt GetInfo 澶辫触"); + } + } else { + //濡傛灉鏄垎浜繃鏉ョ殑浣忓畢 璧颁笅闈㈡祦绋� + var mqttInfoRequestPar = new ShareMemberConnMqttInfoObj () { + LoginAccessToken = mqttRequestParToken, + PlatformStr = "L1", + PublishPayloadJsonStr = PushSignStr, + MainUserDistributedMark = UserConfig.Instance.CurrentRegion.MainUserDistributedMark, + HomeId = UserConfig.Instance.CurrentRegion.Id + }; + mqttInfoRequestResult = MainPage.RequestHttps (API.ShareMemberConnMqttInfo, Newtonsoft.Json.JsonConvert.SerializeObject (mqttInfoRequestPar)); + //--绗竴姝ワ細鑾峰彇mqtt閾炬帴鍙傛暟 + if (mqttInfoRequestResult != null && mqttInfoRequestResult.ResponseData != null) { + var mqttInfoRequestResult_info = Newtonsoft.Json.JsonConvert.DeserializeObject<MqttInfo> (mqttInfoRequestResult.ResponseData.ToString ()); + if (mqttInfoRequestResult_info != null) { + mMqttInfo = mqttInfoRequestResult_info; + //--绗簩姝ワ細鑾峰彇褰撳墠浣忓垎浜畢缃戝叧淇℃伅骞惰繛鎺QTT + await GetSingleHomeGatewayPaggerAndMQTTConnectAsync (); } + } + } } catch (Exception ex) { - System.Console.WriteLine ($"============>Mqtt 杩滅▼杩炴帴閫氳杩炴帴鍑哄紓甯�:{ex.Message}"); + Utlis.WriteLine ($"============>Mqtt 杩滅▼杩炴帴閫氳杩炴帴鍑哄紓甯�:{ex.Message}"); } finally { //鏈�缁堣閲婃斁杩炴帴鐘舵�� remoteMqttIsConnecting = false; @@ -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; @@ -376,6 +394,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> + /// 姝e湪鑾峰彇杩炴帴鍙傛暟... + /// </summary> + static void ShowStartTip () + { + if (bNeedStartTip) { + bNeedStartTip = false; + if (CommonPage.IsRemote) { + MainPage.AddTip ("Getting remote connection parameters..."); + } + } + + } + ///// <summary> ///// ///// </summary> @@ -386,7 +425,7 @@ //{ // try { // if (!remoteIsConnected) { - // System.Console.WriteLine ($"============>Mqtt 鏈繛鎺� 鍙栨秷鍙戦��"); + // Utlis.WriteLine ($"============>Mqtt 鏈繛鎺� 鍙栨秷鍙戦��"); // return; // } @@ -420,10 +459,10 @@ // var m1 = new MqttApplicationMessage { Topic = topicName, Retain = false, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce }; // try { - // Console.WriteLine ("CheckGateway"); + // Utlis.WriteLine ("CheckGateway"); // RemoteMqttClient.PublishAsync (m1); // } catch (Exception e) { - // Console.WriteLine ($"CheckGateway Fail:{e.Message}"); + // Utlis.WriteLine ($"CheckGateway Fail:{e.Message}"); // //await DisConnectRemoteMqttClient (e.Message); // //await StartCloudMqtt (); // } @@ -446,7 +485,7 @@ { try { //if (!remoteIsConnected) { - // System.Console.WriteLine ($"============>Mqtt 鏈繛鎺� 鍙栨秷鍙戦��"); + // Utlis.WriteLine ($"============>Mqtt 鏈繛鎺� 鍙栨秷鍙戦��"); // return; //} @@ -461,12 +500,12 @@ break; case 3: topicName = $"/ClientToBusGateWay/{CurRemoteMACInfo.macMark}/Common/CheckGateway"; - //Console.WriteLine ("CheckGateway"); + //Utlis.WriteLine ("CheckGateway"); await RemoteMqttClient.PublishAsync (new MqttApplicationMessage { Topic = topicName, Retain = false, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce }); break; } } catch (Exception e) { - // System.Console.WriteLine ($"============>Mqtt MqttRemoteSend catch"); + // Utlis.WriteLine ($"============>Mqtt MqttRemoteSend catch"); if (!IsDisConnectingWithSendCatch) { IsDisConnectingWithSendCatch = true; await DisConnectRemoteMqttClient ("MqttRemoteSendCatch"); @@ -524,7 +563,7 @@ } else { - System.Console.WriteLine ("============>Mqtt 鍙栨秷杩炴帴锛屽綋鍓嶄綇瀹呮病缁戝畾缃戝叧"); + Utlis.WriteLine ("============>Mqtt 鍙栨秷杩炴帴锛屽綋鍓嶄綇瀹呮病缁戝畾缃戝叧"); } } else { var mGatewayRes = infoResult.PageData.Find ((obj) => obj.GatewayUniqueId == UserConfig.Instance.CurrentRegion.HomeGateways [0].GatewayUniqueId); @@ -549,7 +588,7 @@ /// </summary> static async Task ReceiveNotifyBusGateWayInfoChange () { - System.Console.WriteLine ("============>Mqtt 缃戝叧涓婄嚎"); + Utlis.WriteLine ("============>Mqtt 缃戝叧涓婄嚎"); SetGatewayOnlineResetCheck (); if (CommonPage.IsRemote) { @@ -586,7 +625,7 @@ /// </summary> static void ReceiveNotifyGateWayOffline () { - System.Console.WriteLine ("============>Mqtt GateWayOffline"); + Utlis.WriteLine ("============>Mqtt GateWayOffline"); IsGatewayOnline = false; if (CommonPage.IsRemote) { Utlis.ShowAppLinkStatus (AppLinkStatus.CloudOffline); @@ -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!"); } @@ -650,7 +689,7 @@ MqttRemoteSend (new byte [] { }, 3); CheckGatewayCount++; #if DEBUG - Console.WriteLine ("CheckGateway"); + Utlis.WriteLine ("CheckGateway"); #endif @@ -669,10 +708,9 @@ /// 鏀跺埌CheckGateway涓婚 /// </summary> static void ReceiveCheckGatewayTopic () { - //System.Console.WriteLine ("============>Mqtt CheckGateway缃戝叧鍥炲"); + //Utlis.WriteLine ("============>Mqtt CheckGateway缃戝叧鍥炲"); SetGatewayOnlineResetCheck (); - //鏃х綉鍏虫柟娉� //MainPage.WiFiStatus = "CrabtreeAdd/CloudUnlink.png"; @@ -720,7 +758,7 @@ /// </summary> static async Task ReceiveNotifySqueezeAsync (byte [] mes) { - Console.WriteLine ($"============>MqttNotifySqueeze: {ErrorCode.LoginInAnotherDevice}"); + Utlis.WriteLine ($"============>MqttNotifySqueeze: {ErrorCode.LoginInAnotherDevice}"); var mMes = CommonPage.MyEncodingUTF8.GetString (mes); if (mMes == PushSignStr) return;//鏄嚜宸辩殑鐧诲綍鎺ㄩ�佷笉澶勭悊 @@ -998,7 +1036,7 @@ RemoteMqttClient = null; } CommonPage.IsRemote = false; - Console.WriteLine ("Close Mqtt!!!"); + Utlis.WriteLine ("Close Mqtt!!!"); } catch { } } @@ -1088,7 +1126,7 @@ webPush.DeleteToken_Push (UserConfig.Instance.tokenID); }); } catch (Exception ex) { - Console.WriteLine (ex.Message); + Utlis.WriteLine (ex.Message); } finally { Application.RunOnMainThread (() => { Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.LinkStatusTipColor; @@ -1154,7 +1192,7 @@ }); RemoteMqttClient.UseDisconnectedHandler (e => { - //Console.WriteLine ("RemoteMqttClient UseDisconnectedHandler"); + //Utlis.WriteLine ("RemoteMqttClient UseDisconnectedHandler"); if (thisShowTip) { if (CommonPage.IsRemote) { //MainPage.AddTip (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.RemoteConnectionDisconnected)); @@ -1168,7 +1206,7 @@ } }); RemoteMqttClient.UseConnectedHandler (async e => { - //Console.WriteLine ("RemoteMqttClient IsRemote"); + //Utlis.WriteLine ("RemoteMqttClient IsRemote"); await MqttCheckGateway (); }); } @@ -1181,14 +1219,14 @@ MainPage.Loading.Hide (); Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; }); - System.Console.WriteLine ($"閲嶆柊杩炴帴杩滅▼閫氳澶辫触锛屽洜涓鸿幏鍙栨柊鐨凨EY澶辫触"); + Utlis.WriteLine ($"閲嶆柊杩炴帴杩滅▼閫氳澶辫触锛屽洜涓鸿幏鍙栨柊鐨凨EY澶辫触"); return; } //var messgae = System.Text.Encoding.UTF8.GetString (tempResult); var responsePack = tempResult.ResponseData;// Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>> (messgae); //if (responsePack == null || responsePack ["ResponseData"] == null) { - // Console.WriteLine ("鏂紑鍚庨噸鏂伴摼鎺ラ渶瑕侀噸鏂扮櫥褰曡幏鍙栬繛鎺ョ殑瀵嗙爜澶辫触"); + // Utlis.WriteLine ("鏂紑鍚庨噸鏂伴摼鎺ラ渶瑕侀噸鏂扮櫥褰曡幏鍙栬繛鎺ョ殑瀵嗙爜澶辫触"); // return; //} var dictrionaryResult = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>> (tempResult.ResponseData.ToString ()); @@ -1216,7 +1254,7 @@ await Close (); await RemoteMqttClient.ConnectAsync (options); } catch (Exception ex) { - System.Console.WriteLine ("============>" + ex.Message); + Utlis.WriteLine ("============>" + ex.Message); Application.RunOnMainThread (() => { MainPage.Loading.Hide (); isConnecting = false.ToString (); @@ -1310,7 +1348,7 @@ return; } var topicName = @"/" + MainPage.LoginUser.AccountString.ToLower () + @"/CheckGateway/" + UserConfig.Instance.GatewayMAC.Replace (".", ""); - Console.WriteLine ("MqttCheckGateway : " + topicName); + Utlis.WriteLine ("MqttCheckGateway : " + topicName); //base64鍔犲瘑涓婚 var topicNameBase64 = Shared.Securitys.EncryptionService.AesEncryptTopic (topicName, mqttEncryptKey); -- Gitblit v1.8.0