| | |
| | | using System.Security.Cryptography; |
| | | using HDL_ON.DriverLayer; |
| | | using HDL_ON.Entity; |
| | | using HDL_ON.UI; |
| | | |
| | | namespace HDL_ON.DAL.Mqtt |
| | | { |
| | |
| | | /// </summary> |
| | | static string mqttEncryptKey = ""; |
| | | //static string checkGatewayTopicBase64 = ""; |
| | | |
| | | static bool hadGateway = true; |
| | | /// <summary> |
| | | /// 挤下线主题 |
| | | /// </summary> |
| | |
| | | static void InitMqtt() |
| | | { |
| | | new System.Threading.Thread(async () => { |
| | | while (true) |
| | | while (hadGateway) |
| | | { |
| | | try |
| | | { |
| | |
| | | //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; |
| | |
| | | /// </summary> |
| | | public static async Task StartCloudMqtt() |
| | | { |
| | | |
| | | if (OnAppConfig.Instance.internetStatus == 0) |
| | | if (MainPage.InternetStatus == 0) |
| | | { |
| | | return; |
| | | } |
| | |
| | | try |
| | | { |
| | | #region 初始化远程Mqtt |
| | | |
| | | remoteMqttIsConnecting = true; |
| | | RemoteMqttClient = new MqttFactory().CreateMqttClient(); |
| | | |
| | | |
| | |
| | | else |
| | | { |
| | | SetGatewayOnlineResetCheck(); |
| | | if (Entity.DB_ResidenceData.residenceData.GatewayType == 0) |
| | | var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, DB_ResidenceData.residenceData.HomeGateway.aesKey); |
| | | |
| | | //bus数据解析 |
| | | if (DB_ResidenceData.residenceData.GatewayType == 0) |
| | | { |
| | | var packet = new Packet(); |
| | | |
| | |
| | | else |
| | | { |
| | | //A协议数据处理 |
| | | var revString = Encoding.UTF8.GetString(bytes); |
| | | Control.Ins.UpdataFunctionStatus(revString); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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 |
| | |
| | | |
| | | //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; |
| | |
| | | { |
| | | if (Control.Ins.IsRemote) |
| | | { |
| | | Control.Ins.GatewayOnline = true; |
| | | if (!Control.Ins.GatewayOnline) |
| | | Control.Ins.GatewayOnline = true; |
| | | } |
| | | } |
| | | |
| | |
| | | else |
| | | { |
| | | Utlis.WriteLine("============>还没绑定网关"); |
| | | hadGateway = false; |
| | | } |
| | | } |
| | | } |