| | |
| | | Topic = $"/user/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/app/thing/property/send", |
| | | QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce |
| | | }; |
| | | var topicBusStatus = new MqttTopicFilter() |
| | | { |
| | | Topic = $"/BusGateWayToClient/MacMask/Common", |
| | | QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce |
| | | }; |
| | | |
| | | Utlis.WriteLine("开始订阅!"); |
| | | var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { topicFilterBusGateWayToClient, topicFilterPush2 , topicAlinkStatus }); |
| | | var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { topicFilterBusGateWayToClient, topicFilterPush2, topicAlinkStatus, topicBusStatus }); |
| | | if (result.Items[0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0) |
| | | { |
| | | isSubscribeSuccess = true; |
| | |
| | | } |
| | | else |
| | | { |
| | | MainPage.Log($"mqtt data"); |
| | | SetGatewayOnlineResetCheck(); |
| | | var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, DB_ResidenceData.Instance.HomeGateway.aesKey); |
| | | |
| | |
| | | { |
| | | packet.Bytes = e.ApplicationMessage.Payload; |
| | | } |
| | | #if DEBUG |
| | | string ddd = ""; |
| | | foreach (var bb in packet.Bytes) |
| | | { |
| | | ddd += bb + ","; |
| | | } |
| | | MainPage.Log($"mqtt bus data:{ddd}"); |
| | | #endif |
| | | packet.Manager(); |
| | | } |
| | | else |
| | | { |
| | | MainPage.Log($"mqtt A-Link data"); |
| | | //A协议数据处理 |
| | | var revString = Encoding.UTF8.GetString(bytes); |
| | | Control.Ins.UpdataFunctionStatus(revString,null); |
| | |
| | | //(3)ConnectedHandler |
| | | if (RemoteMqttClient.ConnectedHandler == null) |
| | | { |
| | | RemoteMqttClient.UseConnectedHandler(async (e) => { |
| | | if (DB_ResidenceData.Instance.HomeGateway.gatewayStatus) |
| | | { |
| | | Control.Ins.GatewayOnline = true; |
| | | } |
| | | else |
| | | { |
| | | //new System.Threading.Thread(() => { |
| | | // while(true) |
| | | // { |
| | | // System.Threading.Thread.Sleep(1000); |
| | | // if (DB_ResidenceData.Instance.HomeGateway.GatewayOnline) |
| | | // { |
| | | // Control.Ins.GatewayOnline = true; |
| | | // break; |
| | | // } |
| | | // } |
| | | //}) { IsBackground = true }.Start(); |
| | | } |
| | | RemoteMqttClient.UseConnectedHandler(async (e) => |
| | | { |
| | | Control.Ins.GatewayOnline = true; |
| | | IfNeedReadAllDeviceStatus = true; |
| | | Utlis.WriteLine($"============>Mqtt远程连接成功"); |
| | | SendPushSignOut(); |
| | |
| | | /// 是否需要读取一次所有设备状态 |
| | | /// </summary> |
| | | static bool IfNeedReadAllDeviceStatus = true; |
| | | //public static bool IsGatewayOnline = true; |
| | | |
| | | /// <summary> |
| | | /// 设置网关在线标志,并重置CheckGateway参数 |