| | |
| | | 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 |
| | | }; |
| | | |
| | | |
| | | #region 数据更新推送主题 |
| | | //appHomeRefresh:住宅数据刷新通知--杨涛 |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 订阅绑定第三方iot账号结果 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static async Task<bool> SubscribeAsync3tyIotbind() |
| | | { |
| | | var topicFilter = new MqttTopicFilter() |
| | | { |
| | | Topic = $"/user/{UserInfo.Current.ID}/app/third/bind/send", |
| | | QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce |
| | | }; |
| | | var result = await RemoteMqttClient.SubscribeAsync(topicFilter); |
| | | if (result.Items[0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0) |
| | | { |
| | | Utlis.WriteLine("订阅绑定第三方iot账号结果成功!"); |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | /// <summary> |
| | | /// 取消订阅绑定第三方iot账号结果 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static async Task<bool> UnsubscribeAsync3tyIotbind() |
| | | { |
| | | string[] strs = new string[] { |
| | | $"/user/{UserInfo.Current.ID}/app/third/bind/send" |
| | | }; |
| | | |
| | | var result = await RemoteMqttClient.UnsubscribeAsync(strs); |
| | | |
| | | if (result.Items[0].ReasonCode == MQTTnet.Client.Unsubscribing.MqttClientUnsubscribeResultCode.Success) |
| | | { |
| | | Utlis.WriteLine("取消订阅绑定第三方iot账号结果成功!"); |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | /// <summary> |
| | | /// 绑定第三方平台接收回调事件 |
| | | /// </summary> |
| | | public static Action Bind3tyIotAction; |
| | | |
| | | /// <summary> |
| | | /// 启动远程Mqtt |
| | | /// </summary> |
| | | public static async Task StartCloudMqtt() |
| | | { |
| | | if (MainPage.InternetStatus == 0) |
| | | //没有网络的状态下尝试一下连接mqtt ,安卓的网络状态变化监听有异常,修改底层麻烦 |
| | | if (MainPage.InternetStatus == 0 && MainPage.LinkHdlMqttCount > 1) |
| | | { |
| | | return; |
| | | } |
| | | MainPage.LinkHdlMqttCount++; |
| | | |
| | | if (!UserInfo.Current.IsLogin) |
| | | { |
| | |
| | | //新挤下线主题方案 收到挤下线主题 |
| | | ReceiveNotifySqueezeAsync(mMes); |
| | | } |
| | | //绑定第三方平台结果通知 |
| | | else if(topic == $"/user/{UserInfo.Current.ID}/app/third/bind/send") |
| | | { |
| | | var revString = Encoding.UTF8.GetString(e.ApplicationMessage.Payload); |
| | | Bind3tyIotAction?.Invoke(); |
| | | } |
| | | //设备在线离线状态推送 |
| | | else if(topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/son/session/online") |
| | | else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/son/session/online") |
| | | { |
| | | try |
| | | { |
| | |
| | | //} |
| | | |
| | | } |
| | | catch(Exception ex) |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | } |
| | |
| | | } |
| | | #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("住宅数据刷新通知"); |
| | | new HttpServerRequest().GetHomePager(); |
| | |
| | | } |
| | | HomePage.LoadEvent_RefreshSecurityStatus(); |
| | | } |
| | | }catch(Exception ex) |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"安防远程信息异常:{ex.Message}"); |
| | | } |
| | | } |
| | | } |
| | | #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") |
| | |
| | | Control.Ins.UpdataFunctionStatus(revString, null, true); |
| | | //Control.Ins.MsgInfoList.Add($"mqtt 状态更新:{revString}"); |
| | | //Control.Ins.MsgInfoList.Add(revString + "\r\n"); |
| | | //if (FunctionList.List.OtherBrandFunction.Find((obj) => obj.sid == updateTemp.sid) == null) |
| | | //{ |
| | | // return; |
| | | //} |
| | | } |
| | | //一端口数据解析 |
| | | else |
| | |
| | | { |
| | | IfNeedReadAllDeviceStatus = true; |
| | | Control.Ins.GatewayOnline_Cloud = true; |
| | | if(MainPage.InternetStatus == 0) |
| | | { |
| | | MainPage.InternetStatus = 1; |
| | | } |
| | | Utlis.WriteLine($"============>Mqtt远程连接成功"); |
| | | SendPushSignOut(); |
| | | }); |