| | |
| | | InitMqtt (); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保活重连和重订阅 线程 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static async System.Threading.Tasks.Task InitMqtt () |
| | | { |
| | | new System.Threading.Thread (async () => { |
| | |
| | | Topic = $"/BusGateWayToClient/{mMqttInfo.connEmqClientId}/Push/NotifySqueeze", |
| | | QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce |
| | | }; |
| | | |
| | | |
| | | |
| | | var topicFilters = new TopicFilter [] { topicFilterCommon, topicFilterGateWayInfoChange, topicFilterNotifySqueeze }; |
| | | var result = await RemoteMqttClient.SubscribeAsync (topicFilters); |
| | |
| | | public static async System.Threading.Tasks.Task StartCloudMqtt () |
| | | { |
| | | |
| | | //Application.RunOnMainThread (() => { |
| | | // if (5 < (DateTime.Now - dateTime).TotalSeconds) { |
| | | // return; |
| | | // } |
| | | // //MainPage.Loading.Start (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.Connecting)); |
| | | // dateTime = DateTime.Now; |
| | | //}); |
| | | if (!MainPage.LoginUser.IsLogin) { |
| | | return; |
| | | } |
| | | //追加:没有远程连接的权限 |
| | | if (remoteMqttIsConnecting |
| | | || remoteIsConnected) { |
| | | //System.Console.WriteLine ($"============>MqttremoteMqttIsConnecting:{remoteMqttIsConnecting} remoteIsConnected:{remoteIsConnected} "); |
| | | |
| | | if (remoteMqttIsConnecting || remoteIsConnected) { |
| | | return; |
| | | } |
| | | |
| | |
| | | if (CurRemoteMACInfo != null) { |
| | | if (CurRemoteMACInfo.isValid == "InValid") { |
| | | MainPage.AddTip ("Remote failed,gateway offline"); |
| | | //Application.RunOnMainThread (() => { |
| | | // MainPage.Loading.Hide (); |
| | | //}); |
| | | } else { |
| | | MqttRemoteSend (new byte [] { 0 }, 3); |
| | | } |
| | |
| | | public static async Task MqttRemoteSend (byte [] message, int optionType = 0) |
| | | { |
| | | try { |
| | | if (!remoteIsConnected) { |
| | | System.Console.WriteLine ($"============>Mqtt 未连接 取消发送"); |
| | | return; |
| | | } |
| | | |
| | | var topicName = @"/" + MainPage.LoginUser.AccountString.ToLower () + @"/" + UserConfig.Instance.GatewayMAC.Replace (".", "") + @"/" + currentGuid; |
| | | switch (optionType) { |
| | | case 0: |
| | |
| | | MainPage.LoginUser.LastTime = DateTime.Now.AddDays (-30); |
| | | MainPage.LoginUser.SaveUserInfo (); |
| | | |
| | | DisConnectRemoteMqttClient ("LoginOut"); |
| | | DisConnectRemoteMqttClient ("挤下线"); |
| | | |
| | | MainPage.ShowAlertOnMainThread (ErrorCode.LoginInAnotherDevice); |
| | | |