| | |
| | | using HDL_ON.Entity; |
| | | using HDL_ON.UI; |
| | | using HDL_ON.DAL.Server; |
| | | using HDL_ON; |
| | | |
| | | namespace HDL_ON.DAL.Mqtt |
| | | { |
| | |
| | | { |
| | | MqttInfoConfig.Current.IfGetMqttInfoSuccess = false; |
| | | } |
| | | //Control.Ins.GatewayOnline_Cloud = Control.Ins.GatewayOnline_Local = false; |
| | | await DisConnectRemoteMqttClient(s); |
| | | } |
| | | |
| | |
| | | |
| | | await StartCloudMqtt(); |
| | | await SubscribeTopics(); |
| | | |
| | | } |
| | | catch { } |
| | | } |
| | |
| | | StartCloudMqtt(); |
| | | } |
| | | |
| | | static bool isSubscribeSuccess; |
| | | public static bool isSubscribeSuccess; |
| | | /// <summary> |
| | | /// 订阅主题 |
| | | /// </summary> |
| | |
| | | var pirStudy = new MqttTopicFilter() |
| | | { |
| | | Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/irCodeStudyDone/up", |
| | | QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce |
| | | }; |
| | | //App订阅群控状态主题 |
| | | var groupControlStatus = new MqttTopicFilter() |
| | | { |
| | | Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/device/group/control/property/send", |
| | | QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce |
| | | }; |
| | | |
| | |
| | | #endregion |
| | | |
| | | |
| | | Utlis.WriteLine("开始订阅!"); |
| | | var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { |
| | | Utlis.WriteLine("开始订阅!"); |
| | | var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { |
| | | pirStatus,pirStudy, |
| | | appDeviceRefresh,appHomeRefresh,appRoomRefresh,residenceChange, |
| | | topicFilterPush2, topicAlinkStatus ,mqttkeyChange, |
| | | deviceOnlinePush, |
| | | securityStatusChange}); |
| | | //订阅群控状态 |
| | | if (DB_ResidenceData.Instance.HomeGateway.isSupportGroupControl) |
| | | { |
| | | await RemoteMqttClient.SubscribeAsync(groupControlStatus); |
| | | } |
| | | if (result.Items[0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0) |
| | | { |
| | | isSubscribeSuccess = true; |
| | |
| | | try |
| | | { |
| | | var topic = e.ApplicationMessage.Topic; |
| | | //MainPage.Log($"收到mqtt主题:{topic}"); |
| | | MainPage.Log($"收到mqtt主题:{topic}"); |
| | | //一端口主题处理 |
| | | if (DB_ResidenceData.Instance.GatewayType == 0 && !DB_ResidenceData.Instance.CheckWhetherGatewayIdIsNull()) |
| | | { |
| | |
| | | } |
| | | #region 数据更新推送主题 |
| | | //appHomeRefresh:住宅数据刷新通知 |
| | | else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appHomeRefresh/up" |
| | | || topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appDeviceRefresh/up") |
| | | else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appHomeRefresh/up") |
| | | { |
| | | MainPage.Log("住宅数据刷新通知"); |
| | | System.Threading.Thread.Sleep(2000); |
| | | new HttpServerRequest().GetHomePager(); |
| | | } |
| | | //appRoomRefresh:房间数据刷新通知 |
| | |
| | | else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appDeviceRefresh/up") |
| | | { |
| | | MainPage.Log("设备数据刷新通知"); |
| | | var deviceResult = new HttpServerRequest().GetDeviceList(); |
| | | if (deviceResult.Code == StateCode.SUCCESS) |
| | | { |
| | | MainPage.Log($"读取设备信息成功"); |
| | | var deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString()); |
| | | if (deviceList == null) |
| | | { |
| | | deviceList = new DevcieApiPack(); |
| | | } |
| | | string delFile = ""; |
| | | if (FunctionList.List.GetDeviceFunctionList().Count > 0) |
| | | { |
| | | for (int i = 0; i < FunctionList.List.GetDeviceFunctionList().Count;) |
| | | { |
| | | var localFunction = FunctionList.List.GetDeviceFunctionList()[i]; |
| | | if (SPK.MusicSpkList().Contains(localFunction.spk)) |
| | | { |
| | | i++; |
| | | continue; |
| | | } |
| | | var newFunction = deviceList.list.Find((obj) => obj.deviceId == localFunction.deviceId); |
| | | |
| | | if (delFile == localFunction.savePath) |
| | | { |
| | | i++; |
| | | continue; |
| | | } |
| | | delFile = localFunction.savePath; |
| | | FunctionList.List.DeleteFunction(localFunction); |
| | | } |
| | | } |
| | | //处理剩下的新增功能 |
| | | foreach (var newFunction in deviceList.list) |
| | | { |
| | | newFunction.SaveFunctionFile(); |
| | | FunctionList.List.IniFunctionList(newFunction.savePath); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | MainPage.Log($"读取云端设备数据失败:Code:{deviceResult.Code}; Msg:{deviceResult.message}"); |
| | | } |
| | | } |
| | | //网关密钥变化 |
| | | else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/custom/mqtt/secret/change") |
| | |
| | | } |
| | | } |
| | | #endregion |
| | | //群控状态 |
| | | else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/device/group/control/property/send") |
| | | { |
| | | var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, tuyaEncryptKey); |
| | | var revString = Encoding.UTF8.GetString(bytes); |
| | | MainPage.Log($"mqtt 群控状态更新:{revString}"); |
| | | Control.Ins.UpdataGroupControlStatus(revString, null, true); |
| | | } |
| | | //A网关设备状态-包含涂鸦设备 |
| | | //Tag 网络状态解析 |
| | | else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/property/send") |
| | | { |
| | | |
| | | var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, tuyaEncryptKey); |
| | | var revString = Encoding.UTF8.GetString(bytes); |
| | | MainPage.Log($"mqtt 状态更新:{revString}"); |
| | | //MainPage.Log($"mqtt 状态更新:{revString}"); |
| | | Control.Ins.UpdataFunctionStatus(revString, null, true); |
| | | //Control.Ins.MsgInfoList.Add($"mqtt 状态更新:{revString}"); |
| | | //Control.Ins.MsgInfoList.Add(revString + "\r\n"); |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Utlis.WriteLine($"error:" + ex.Message); |
| | | Utlis.WriteLine($"mqtt连接异常 error:" + ex.Message); |
| | | //mqtt连接异常,清空本地mqtt信息,可能需要重新获取:wxr |
| | | MqttInfoConfig.Current.Refresh(); |
| | | } |
| | |
| | | /// </summary> |
| | | static void ReceiveNotifySqueezeAsync(string mMes) |
| | | { |
| | | #if DEBUG |
| | | return; |
| | | #endif |
| | | if (mMes == PushSignStr) return;//是自己的登录推送不处理//或者当前不是远程链接状态 |
| | | //测试账号,不挤下线 |
| | | switch (UserInfo.Current.userMobileInfo) |
| | | { |
| | | case "15626203746": |
| | | case "464027401@qq.com": |
| | | case "13924245850": |
| | | case "13411390230": |
| | | return; |
| | | } |
| | | |
| | |
| | | static void SendPushSignOut() |
| | | { |
| | | byte[] message = Encoding.UTF8.GetBytes(PushSignStr); |
| | | #if DEBUG |
| | | MqttRemoteSend(message, 4); |
| | | #endif |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | 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}"); |
| | | 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(); |
| | | //await MQTTConnectAsync(); |
| | | //1.判断是否绑定了网关,获取网关远程连接的加密KEY |
| | | //if (DB_ResidenceData.Instance.CheckWhetherGatewayIsBound()) |
| | | { |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine(ex.Message); |
| | | MainPage.Log(ex.Message); |
| | | } |
| | | return reData; |
| | | } |