From 488efb508eb0648773fe7b68e810e04bcd7ca075 Mon Sep 17 00:00:00 2001 From: wei <kaede@kaededeMacBook-Air.local> Date: 星期五, 11 十二月 2020 15:58:15 +0800 Subject: [PATCH] 20201211 --- HDL_ON/DAL/Mqtt/MqttClient.cs | 39 ++++++++++++++++++++++++--------------- 1 files changed, 24 insertions(+), 15 deletions(-) diff --git a/HDL_ON/DAL/Mqtt/MqttClient.cs b/HDL_ON/DAL/Mqtt/MqttClient.cs index ea06685..3161a9f 100644 --- a/HDL_ON/DAL/Mqtt/MqttClient.cs +++ b/HDL_ON/DAL/Mqtt/MqttClient.cs @@ -10,6 +10,7 @@ using System.Security.Cryptography; using HDL_ON.DriverLayer; using HDL_ON.Entity; +using HDL_ON.UI; namespace HDL_ON.DAL.Mqtt { @@ -20,7 +21,7 @@ /// </summary> static string mqttEncryptKey = ""; //static string checkGatewayTopicBase64 = ""; - + static bool hadGateway = true; /// <summary> /// 鎸や笅绾夸富棰� /// </summary> @@ -131,7 +132,7 @@ static void InitMqtt() { new System.Threading.Thread(async () => { - while (true) + while (hadGateway) { try { @@ -178,8 +179,14 @@ //QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce }; + var topicAlinkStatus = new MqttTopicFilter() + { + Topic = $"/user/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/app/thing/property/send", + QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce + }; + Utlis.WriteLine("寮�濮嬭闃咃紒"); - var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { topicFilterBusGateWayToClient, topicFilterPush2 }); + var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { topicFilterBusGateWayToClient, topicFilterPush2 , topicAlinkStatus }); if (result.Items[0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0) { isSubscribeSuccess = true; @@ -203,8 +210,7 @@ /// </summary> public static async Task StartCloudMqtt() { - - if (OnAppConfig.Instance.internetStatus == 0) + if (MainPage.InternetStatus == 0) { return; } @@ -226,7 +232,7 @@ try { #region 鍒濆鍖栬繙绋婱qtt - + remoteMqttIsConnecting = true; RemoteMqttClient = new MqttFactory().CreateMqttClient(); @@ -262,7 +268,10 @@ else { SetGatewayOnlineResetCheck(); - if (Entity.DB_ResidenceData.residenceData.GatewayType == 0) + var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, DB_ResidenceData.residenceData.HomeGateway.aesKey); + + //bus鏁版嵁瑙f瀽 + if (DB_ResidenceData.residenceData.GatewayType == 0) { var packet = new Packet(); @@ -279,6 +288,8 @@ else { //A鍗忚鏁版嵁澶勭悊 + var revString = Encoding.UTF8.GetString(bytes); + Control.Ins.UpdataFunctionStatus(revString); } } } @@ -299,14 +310,11 @@ if (RemoteMqttClient.ConnectedHandler == null) { RemoteMqttClient.UseConnectedHandler(async (e) => { + Control.Ins.GatewayOnline = true; IfNeedReadAllDeviceStatus = true; Utlis.WriteLine($"============>Mqtt杩滅▼杩炴帴鎴愬姛"); SendPushSignOut(); - - //if (Control.Ins.IsRemote) { - // //Utlis.ShowAppLinkStatus (AppLinkStatus.CloudLink); - // MainPage.AddTip (Language.StringByID (SimpleControl.R.MyInternationalizationString.LinkSuccess)); - //} + FunctionList.List.ReadAllFunctionStatus(); }); } #endregion @@ -424,8 +432,7 @@ //url = HttpUtil.GetProxyEMQUrl (url); //#if DEBUG - // url = HttpUtil.GetProxyEMQUrl (url); - + //url = HttpUtil.GetProxyEMQUrl (url); //#endif var clientId = MqttInfoConfig.Current.mMqttInfo.clientId; var username = MqttInfoConfig.Current.mMqttInfo.userName; @@ -629,7 +636,8 @@ { if (Control.Ins.IsRemote) { - Control.Ins.GatewayOnline = true; + if (!Control.Ins.GatewayOnline) + Control.Ins.GatewayOnline = true; } } @@ -656,6 +664,7 @@ else { Utlis.WriteLine("============>杩樻病缁戝畾缃戝叧"); + hadGateway = false; } } } -- Gitblit v1.8.0