| | |
| | | { |
| | | try |
| | | { |
| | | System.Threading.Thread.Sleep(500); |
| | | System.Threading.Thread.Sleep(2000); |
| | | //进入后台不处理 |
| | | if (MainPage.IsEnterBackground) continue; |
| | | if (MqttInfoConfig.Current.HomeGatewayInfo == null) |
| | |
| | | Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/irCodeStudyDone/up", |
| | | QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce |
| | | }; |
| | | |
| | | #region 数据更新推送主题 |
| | | //appHomeRefresh:住宅数据刷新通知 |
| | | var appHomeRefresh = new MqttTopicFilter() |
| | |
| | | Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appDeviceRefresh/up", |
| | | QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce |
| | | }; |
| | | //一端口密钥更新通知 |
| | | var mqttkeyChange = new MqttTopicFilter() |
| | | { |
| | | Topic = $"/user/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/custom/mqtt/secret/change", |
| | | QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce |
| | | }; |
| | | |
| | | #endregion |
| | | |
| | | |
| | |
| | | var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { |
| | | pirStatus,pirStudy, |
| | | appDeviceRefresh,appHomeRefresh,appRoomRefresh, |
| | | topicFilterPush2, topicAlinkStatus }); |
| | | topicFilterPush2, topicAlinkStatus ,mqttkeyChange}); |
| | | if (result.Items[0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0) |
| | | { |
| | | isSubscribeSuccess = true; |
| | |
| | | { |
| | | var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, tuyaEncryptKey); |
| | | var revString = Encoding.UTF8.GetString(bytes); |
| | | HDL_ON.UI.UI2.PersonalCenter.PirDevice.Method.controldata = revString; |
| | | HDL_ON.UI.UI2.PersonalCenter.PirDevice.PirMethod.controldata = revString; |
| | | } |
| | | //App订阅遥控器自学按键学习成功通知 |
| | | else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/irCodeStudyDone/up") |
| | | { |
| | | var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, tuyaEncryptKey); |
| | | var revString = Encoding.UTF8.GetString(bytes); |
| | | UI.UI2.PersonalCenter.PirDevice.Method.buttondata = revString; |
| | | UI.UI2.PersonalCenter.PirDevice.PirMethod.buttondata = revString; |
| | | } |
| | | #region 数据更新推送主题 |
| | | //appHomeRefresh:住宅数据刷新通知 |
| | |
| | | MainPage.Log($"读取云端设备数据失败:Code:{deviceResult.Code}; Msg:{deviceResult.message}"); |
| | | } |
| | | } |
| | | //网关密钥变化 |
| | | else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/custom/mqtt/secret/change") |
| | | { |
| | | var pm = new HttpServerRequest(); |
| | | pm.GetHomeGatewayList(); |
| | | MainPage.Log($"网关密钥变更"); |
| | | MainPage.Log($"旧密钥:{mqttEncryptKey}"); |
| | | mqttEncryptKey = MqttInfoConfig.Current.HomeGatewayInfo.aesKey; |
| | | MainPage.Log($"新密钥:{mqttEncryptKey}"); |
| | | } |
| | | |
| | | #endregion |
| | | //A网关设备状态-包含涂鸦设备 |
| | | else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/property/send") |
| | |
| | | catch (Exception ex) |
| | | { |
| | | Utlis.WriteLine($"error:" + ex.Message); |
| | | //mqtt连接异常,清空本地mqtt信息,可能需要重新获取:wxr |
| | | MqttInfoConfig.Current.Refresh(); |
| | | } |
| | | finally |
| | | { |
| | |
| | | //重新中心服务器获取参数标记 |
| | | MqttInfoConfig.Current.IfGetMqttInfoSuccess = false; |
| | | Console.WriteLine("Connect error: " + ex.Message); |
| | | //mqtt连接异常,清空本地mqtt信息,可能需要重新获取:wxr |
| | | MqttInfoConfig.Current.Refresh(); |
| | | } |
| | | finally |
| | | { |
| | |
| | | { |
| | | if (mMes == PushSignStr) return;//是自己的登录推送不处理//或者当前不是远程链接状态 |
| | | //测试账号,不挤下线 |
| | | switch (UserInfo.Current.AccountString) |
| | | switch (UserInfo.Current.userMobileInfo) |
| | | { |
| | | case "13415629083": |
| | | case "18316120654": |
| | |
| | | case "18778381374": |
| | | case "18316672920": |
| | | case "15971583093": |
| | | case "15626203746": |
| | | case "551775569@qq.com": |
| | | return; |
| | | } |
| | | |
| | |
| | | /// <returns></returns> |
| | | static async Task GetMqttInfoAndMQTTConnectAsync() |
| | | { |
| | | var mqttInfoRequestResult_Obj = new Server.HttpServerRequest().GetMqttRemoteInfo(GetRandomKey()); |
| | | var mqttInfoRequestResult_Obj = new HttpServerRequest().GetMqttRemoteInfo(GetRandomKey()); |
| | | if (mqttInfoRequestResult_Obj != null) |
| | | { |
| | | MainPage.Log($"获取mqtt info 成功 /r/n clientId:{mqttInfoRequestResult_Obj.clientId}/r/n passWord:{mqttInfoRequestResult_Obj.passWord} /r/n url:{mqttInfoRequestResult_Obj.url}/r/n userName:{mqttInfoRequestResult_Obj.userName}"); |
| | | |
| | | |
| | | MqttInfoConfig.Current.mMqttInfo = mqttInfoRequestResult_Obj; |
| | | await MQTTConnectAsync(); |
| | | //1.判断是否绑定了网关,获取网关远程连接的加密KEY |