old mode 100644
new mode 100755
| | |
| | | using System.Net.Sockets; |
| | | using System.Net; |
| | | using Newtonsoft.Json.Linq; |
| | | using MQTTnet.Core.Client; |
| | | using MQTTnet; |
| | | using Shared.Common; |
| | | using Shared.Phone.UserView; |
| | | using MQTTnet.Client; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace ZigBee.Device |
| | | { |
| | |
| | | { |
| | | this.Type = DeviceType.ZbGateway; |
| | | } |
| | | |
| | | |
| | | |
| | | #region 网关特殊信息处理 |
| | | /// <summary> |
| | |
| | | public bool IsMainGateWay |
| | | { |
| | | get |
| | | {
|
| | | return getGatewayBaseInfo != null && getGatewayBaseInfo.IsMainGateWay; |
| | | { |
| | | return getGatewayBaseInfo != null && getGatewayBaseInfo.IsMainGateWay; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 远程网关 |
| | | /// 是否使用远程连接模式 |
| | | /// </summary> |
| | | /// <value><c>true</c> if is remote; otherwise, <c>false</c>.</value> |
| | | public static bool IsRemote |
| | | { |
| | | get |
| | | { |
| | | return ZigBee.Device.ZbGateway.RemoteMqttClient != null && ZigBee.Device.ZbGateway.RemoteMqttClient.IsConnected; |
| | | } |
| | | } |
| | | public static bool IsRemote; |
| | | |
| | | /// <summary>
|
| | | /// 是否拥有远程连接的权限
|
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public static bool AllowRemoteCtrl = true; |
| | | |
| | | /// <summary> |
| | | /// 网关保存路径 |
| | |
| | | |
| | | /// <summary> |
| | | /// 同步到远程的当前时间戳 |
| | | /// </summary> |
| | | /// </summary>Re |
| | | public static ulong CurrentTimeStamp |
| | | { |
| | | get |
| | |
| | | DebugPrintLog("GwReName_Actions 启动" + System.DateTime.Now.ToString()); |
| | | try |
| | | { |
| | | //账号ID |
| | | string accountId = string.Empty; |
| | | if (homeId != string.Empty)
|
| | | {
|
| | | if (Shared.Phone.UserCenter.UserCenterResourse.UserInfo.AuthorityNo == 1)
|
| | | {
|
| | | //主账号
|
| | | accountId = Config.Instance.Guid;
|
| | | }
|
| | | else
|
| | | {
|
| | | accountId = Config.Instance.Home.MainUserDistributedMark;
|
| | | }
|
| | | } |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 82 } }; |
| | | var data = new JObject { { "HomeId", homeId } }; |
| | | var data = new JObject { { "HomeId", homeId }, { "AccountId", accountId } }; |
| | | jObject.Add("Data", data); |
| | | Send("GwSetHomeId", jObject.ToString()); |
| | | //住宅ID的设置,固定使用局域网,不存在远程的说法 |
| | | SendLocation("GwSetHomeId", System.Text.Encoding.UTF8.GetBytes(jObject.ToString())); |
| | | } |
| | | catch { } |
| | | |
| | |
| | | }
|
| | | var deviceID = jobject.Value<int>("Device_ID");
|
| | | switch ((DeviceType)(deviceID))
|
| | | {
|
| | | //case DeviceType.DimmableLight:
|
| | | // var dimmableLight = new DimmableLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
|
| | | // dimmableLight.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight.DeviceInfoData>(jobject["Data"].ToString());
|
| | | // if (dimmableLight.DeviceInfo == null)
|
| | | // {
|
| | | // return;
|
| | | // }
|
| | | // var light = DeviceList.Find(obj => obj.DeviceID == dimmableLight.DeviceID && obj.DeviceAddr == dimmableLight.DeviceAddr && obj.DeviceEpoint == dimmableLight.DeviceEpoint);
|
| | | // if (light == null)
|
| | | // {
|
| | | // DeviceList.Add(dimmableLight);
|
| | | // dimmableLight.DeviceName = dimmableLight.DeviceInfo.MacName;
|
| | | // dimmableLight.DeviceEpointName = dimmableLight.DeviceInfo.DeviceName;
|
| | | // dimmableLight.ImgVersion = dimmableLight.DeviceInfo.ImgVersion;
|
| | | // dimmableLight.HwVersion = dimmableLight.DeviceInfo.HwVersion;
|
| | | // dimmableLight.IsOnline = dimmableLight.DeviceInfo.IsOnline;
|
| | | // dimmableLight.DriveCode = dimmableLight.DeviceInfo.DriveCode;
|
| | | // dimmableLight.ImgTypeId = dimmableLight.DeviceInfo.ImgTypeId;
|
| | | // dimmableLight.IasDeviceType = dimmableLight.DeviceInfo.DeviceType;
|
| | | // dimmableLight.Profile = dimmableLight.DeviceInfo.Profile;
|
| | | // dimmableLight.InClusterList = dimmableLight.DeviceInfo.InClusterList;
|
| | | // dimmableLight.OutClusterList = dimmableLight.DeviceInfo.OutClusterList;
|
| | | // dimmableLight.AttributeStatus = dimmableLight.DeviceInfo.AttributeStatus;
|
| | | // //dimmableLight.Save();
|
| | | // }
|
| | | // else
|
| | | // {
|
| | | // light.DeviceInfo = dimmableLight.DeviceInfo;
|
| | | // light.DeviceName = dimmableLight.DeviceInfo.MacName;
|
| | | // light.DeviceEpointName = dimmableLight.DeviceInfo.DeviceName;
|
| | | // light.ImgVersion = dimmableLight.DeviceInfo.ImgVersion;
|
| | | // light.HwVersion = dimmableLight.DeviceInfo.HwVersion;
|
| | | // light.IsOnline = dimmableLight.DeviceInfo.IsOnline;
|
| | | // light.DriveCode = dimmableLight.DeviceInfo.DriveCode;
|
| | | // light.ImgTypeId = dimmableLight.DeviceInfo.ImgTypeId;
|
| | | // light.IasDeviceType = dimmableLight.DeviceInfo.DeviceType;
|
| | | // light.Profile = dimmableLight.DeviceInfo.Profile;
|
| | | // light.InClusterList = dimmableLight.DeviceInfo.InClusterList;
|
| | | // light.OutClusterList = dimmableLight.DeviceInfo.OutClusterList;
|
| | | // light.AttributeStatus = dimmableLight.DeviceInfo.AttributeStatus;
|
| | | // //dimmableLight.ReSave();
|
| | | // }
|
| | | // DebugPrintLog($"UI收到通知后的主题_{ topic}");
|
| | |
|
| | | // break;
|
| | | //case DeviceType.OnOffSwitch:
|
| | | // var panel = new Panel() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
|
| | | // panel.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceInfoData>(jobject["Data"].ToString());
|
| | | // if (panel.DeviceInfo == null)
|
| | | // {
|
| | | // return;
|
| | | // }
|
| | | // var panelInfo = DeviceList.Find(obj => obj.DeviceID == panel.DeviceID && obj.DeviceAddr == panel.DeviceAddr && obj.DeviceEpoint == panel.DeviceEpoint);
|
| | | // if (panelInfo == null)
|
| | | // {
|
| | | // DeviceList.Add(panel);
|
| | | // panel.DeviceName = panel.DeviceInfo.MacName;
|
| | | // panel.DeviceEpointName = panel.DeviceInfo.DeviceName;
|
| | | // panel.ImgTypeId = panel.DeviceInfo.ImgTypeId;
|
| | | // panel.ImgVersion = panel.DeviceInfo.ImgVersion;
|
| | | // panel.HwVersion = panel.DeviceInfo.HwVersion;
|
| | | // panel.IasDeviceType = panel.DeviceInfo.DeviceType;
|
| | | // panel.IsOnline = panel.DeviceInfo.IsOnline;
|
| | | // panel.DriveCode = panel.DeviceInfo.DriveCode;
|
| | | // panel.Profile = panel.DeviceInfo.Profile;
|
| | | // panel.InClusterList = panel.DeviceInfo.InClusterList;
|
| | | // panel.OutClusterList = panel.DeviceInfo.OutClusterList;
|
| | | // panel.AttributeStatus = panel.DeviceInfo.AttributeStatus;
|
| | | // //panel.Save();
|
| | | // }
|
| | | // else
|
| | | // {
|
| | | // panelInfo.DeviceInfo = panel.DeviceInfo;
|
| | | // panelInfo.DeviceName = panel.DeviceInfo.MacName;
|
| | | // panelInfo.DeviceEpointName = panel.DeviceInfo.DeviceName;
|
| | | // panelInfo.ImgVersion = panel.DeviceInfo.ImgVersion;
|
| | | // panelInfo.HwVersion = panel.DeviceInfo.HwVersion;
|
| | | // panelInfo.IsOnline = panel.DeviceInfo.IsOnline;
|
| | | // panelInfo.DriveCode = panel.DeviceInfo.DriveCode;
|
| | | // panelInfo.IasDeviceType = panel.DeviceInfo.DeviceType;
|
| | | // panelInfo.Profile = panel.DeviceInfo.Profile;
|
| | | // panelInfo.ImgTypeId = panel.DeviceInfo.ImgTypeId;
|
| | | // panelInfo.InClusterList = panel.DeviceInfo.InClusterList;
|
| | | // panelInfo.OutClusterList = panel.DeviceInfo.OutClusterList;
|
| | | // panelInfo.AttributeStatus = panel.DeviceInfo.AttributeStatus;
|
| | | // //panel.ReSave();
|
| | | // }
|
| | | // DebugPrintLog($"UI收到通知后的主题_{ topic}");
|
| | |
|
| | | // break;
|
| | | //case DeviceType.OnOffOutput:
|
| | | // var toggleLight = new ToggleLight() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
|
| | | // toggleLight.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight.DeviceInfoData>(jobject["Data"].ToString());
|
| | | // if (toggleLight.DeviceInfo == null)
|
| | | // {
|
| | | // return;
|
| | | // }
|
| | | // var toggleLightInfo = DeviceList.Find(obj => obj.DeviceID == toggleLight.DeviceID && obj.DeviceAddr == toggleLight.DeviceAddr && obj.DeviceEpoint == toggleLight.DeviceEpoint);
|
| | | // if (toggleLightInfo == null)
|
| | | // {
|
| | | // DeviceList.Add(toggleLight);
|
| | | // toggleLight.DeviceName = toggleLight.DeviceInfo.MacName;
|
| | | // toggleLight.DeviceEpointName = toggleLight.DeviceInfo.DeviceName;
|
| | | // toggleLight.ImgVersion = toggleLight.DeviceInfo.ImgVersion;
|
| | | // toggleLight.HwVersion = toggleLight.DeviceInfo.HwVersion;
|
| | | // toggleLight.IsOnline = toggleLight.DeviceInfo.IsOnline;
|
| | | // toggleLight.DriveCode = toggleLight.DeviceInfo.DriveCode;
|
| | | // toggleLight.IasDeviceType = toggleLight.DeviceInfo.DeviceType;
|
| | | // toggleLight.Profile = toggleLight.DeviceInfo.Profile;
|
| | | // toggleLight.ImgTypeId = toggleLight.DeviceInfo.ImgTypeId;
|
| | | // toggleLight.InClusterList = toggleLight.DeviceInfo.InClusterList;
|
| | | // toggleLight.OutClusterList = toggleLight.DeviceInfo.OutClusterList;
|
| | | // toggleLight.AttributeStatus = toggleLight.DeviceInfo.AttributeStatus;
|
| | | // //toggleLight.Save();
|
| | | // }
|
| | | // else
|
| | | // {
|
| | | // toggleLightInfo.DeviceName = toggleLight.DeviceInfo.MacName;
|
| | | // toggleLightInfo.DeviceEpointName = toggleLight.DeviceInfo.DeviceName;
|
| | | // toggleLightInfo.ImgVersion = toggleLight.DeviceInfo.ImgVersion;
|
| | | // toggleLightInfo.HwVersion = toggleLight.DeviceInfo.HwVersion;
|
| | | // toggleLightInfo.IsOnline = toggleLight.DeviceInfo.IsOnline;
|
| | | // toggleLightInfo.DriveCode = toggleLight.DeviceInfo.DriveCode;
|
| | | // toggleLightInfo.IasDeviceType = toggleLight.DeviceInfo.DeviceType;
|
| | | // toggleLightInfo.Profile = toggleLight.DeviceInfo.Profile;
|
| | | // toggleLightInfo.ImgTypeId = toggleLight.DeviceInfo.ImgTypeId;
|
| | | // toggleLightInfo.InClusterList = toggleLight.DeviceInfo.InClusterList;
|
| | | // toggleLightInfo.OutClusterList = toggleLight.DeviceInfo.OutClusterList;
|
| | | // toggleLightInfo.AttributeStatus = toggleLight.DeviceInfo.AttributeStatus;
|
| | | // toggleLightInfo.DeviceInfo = toggleLight.DeviceInfo;
|
| | | // //toggleLightInfo.ReSave();
|
| | | // }
|
| | | // DebugPrintLog($"UI收到通知后的主题_{ topic}");
|
| | |
|
| | | // break;
|
| | | //case DeviceType.AirSwitch:
|
| | | // var airSwitch = new AirSwitch() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
|
| | | // airSwitch.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch.DeviceInfoData>(jobject["Data"].ToString());
|
| | | // if (airSwitch.DeviceInfo == null)
|
| | | // {
|
| | | // return;
|
| | | // }
|
| | | // var airSwitchInfo = DeviceList.Find(obj => obj.DeviceID == airSwitch.DeviceID && obj.DeviceAddr == airSwitch.DeviceAddr && obj.DeviceEpoint == airSwitch.DeviceEpoint);
|
| | | // if (airSwitchInfo == null)
|
| | | // {
|
| | | // DeviceList.Add(airSwitch);
|
| | | // airSwitch.DeviceName = airSwitch.DeviceInfo.MacName;
|
| | | // airSwitch.DeviceEpointName = airSwitch.DeviceInfo.DeviceName;
|
| | | // airSwitch.ImgVersion = airSwitch.DeviceInfo.ImgVersion;
|
| | | // airSwitch.HwVersion = airSwitch.DeviceInfo.HwVersion;
|
| | | // airSwitch.IsOnline = airSwitch.DeviceInfo.IsOnline;
|
| | | // airSwitch.DriveCode = airSwitch.DeviceInfo.DriveCode;
|
| | | // airSwitch.IasDeviceType = airSwitch.DeviceInfo.DeviceType;
|
| | | // airSwitch.Profile = airSwitch.DeviceInfo.Profile;
|
| | | // airSwitch.ImgTypeId = airSwitch.DeviceInfo.ImgTypeId;
|
| | | // airSwitch.InClusterList = airSwitch.DeviceInfo.InClusterList;
|
| | | // airSwitch.OutClusterList = airSwitch.DeviceInfo.OutClusterList;
|
| | | // airSwitch.AttributeStatus = airSwitch.DeviceInfo.AttributeStatus;
|
| | | // //airSwitch.Save();
|
| | | // }
|
| | | // else
|
| | | // {
|
| | | // airSwitchInfo.DeviceName = airSwitch.DeviceInfo.MacName;
|
| | | // airSwitchInfo.DeviceEpointName = airSwitch.DeviceInfo.DeviceName;
|
| | | // airSwitchInfo.ImgVersion = airSwitch.DeviceInfo.ImgVersion;
|
| | | // airSwitchInfo.HwVersion = airSwitch.DeviceInfo.HwVersion;
|
| | | // airSwitchInfo.IsOnline = airSwitch.DeviceInfo.IsOnline;
|
| | | // airSwitchInfo.DriveCode = airSwitch.DeviceInfo.DriveCode;
|
| | | // airSwitchInfo.IasDeviceType = airSwitch.DeviceInfo.DeviceType;
|
| | | // airSwitchInfo.Profile = airSwitch.DeviceInfo.Profile;
|
| | | // airSwitchInfo.ImgTypeId = airSwitch.DeviceInfo.ImgTypeId;
|
| | | // airSwitchInfo.InClusterList = airSwitch.DeviceInfo.InClusterList;
|
| | | // airSwitchInfo.OutClusterList = airSwitch.DeviceInfo.OutClusterList;
|
| | | // airSwitchInfo.AttributeStatus = airSwitch.DeviceInfo.AttributeStatus;
|
| | | // airSwitchInfo.DeviceInfo = airSwitch.DeviceInfo;
|
| | | // // airSwitchInfo.ReSave();
|
| | | // }
|
| | | // DebugPrintLog($"UI收到通知后的主题_{ topic}");
|
| | |
|
| | | // break;
|
| | | //case DeviceType.WindowCoveringDevice:
|
| | | // var windowCovering = new Rollershade() { DeviceID = jobject.Value<int>((object)"Device_ID"), DeviceAddr = jobject.Value<string>((object)"DeviceAddr"), DeviceEpoint = jobject.Value<int>((object)"Epoint"), DataID = jobject.Value<int>((object)"Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
|
| | | // windowCovering.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade.DeviceInfoData>(jobject["Data"].ToString());
|
| | | // if (windowCovering.DeviceInfo == null)
|
| | | // {
|
| | | // return;
|
| | | // }
|
| | | // var wc = DeviceList.Find(obj => obj.DeviceID == windowCovering.DeviceID && obj.DeviceAddr == windowCovering.DeviceAddr && obj.DeviceEpoint == windowCovering.DeviceEpoint);
|
| | | // if (wc == null)
|
| | | // {
|
| | | // DeviceList.Add(windowCovering);
|
| | | // windowCovering.DeviceName = windowCovering.DeviceInfo.MacName;
|
| | | // windowCovering.DeviceEpointName = windowCovering.DeviceInfo.DeviceName;
|
| | | // windowCovering.ImgVersion = windowCovering.DeviceInfo.ImgVersion;
|
| | | // windowCovering.HwVersion = windowCovering.DeviceInfo.HwVersion;
|
| | | // windowCovering.IsOnline = windowCovering.DeviceInfo.IsOnline;
|
| | | // windowCovering.DriveCode = windowCovering.DeviceInfo.DriveCode;
|
| | | // windowCovering.IasDeviceType = windowCovering.DeviceInfo.DeviceType;
|
| | | // windowCovering.Profile = windowCovering.DeviceInfo.Profile;
|
| | | // windowCovering.ImgTypeId = windowCovering.DeviceInfo.ImgTypeId;
|
| | | // windowCovering.InClusterList = windowCovering.DeviceInfo.InClusterList;
|
| | | // windowCovering.OutClusterList = windowCovering.DeviceInfo.OutClusterList;
|
| | | // windowCovering.AttributeStatus = windowCovering.DeviceInfo.AttributeStatus;
|
| | | // //windowCovering.Save();
|
| | | // }
|
| | | // else
|
| | | // {
|
| | | // wc.DeviceName = windowCovering.DeviceInfo.MacName;
|
| | | // wc.DeviceEpointName = windowCovering.DeviceInfo.DeviceName;
|
| | | // wc.DeviceInfo = windowCovering.DeviceInfo;
|
| | | // wc.ImgVersion = windowCovering.DeviceInfo.ImgVersion;
|
| | | // wc.HwVersion = windowCovering.DeviceInfo.HwVersion;
|
| | | // wc.IsOnline = windowCovering.DeviceInfo.IsOnline;
|
| | | // wc.DriveCode = windowCovering.DeviceInfo.DriveCode;
|
| | | // wc.IasDeviceType = windowCovering.DeviceInfo.DeviceType;
|
| | | // wc.Profile = windowCovering.DeviceInfo.Profile;
|
| | | // wc.ImgTypeId = windowCovering.DeviceInfo.ImgTypeId;
|
| | | // wc.InClusterList = windowCovering.DeviceInfo.InClusterList;
|
| | | // wc.OutClusterList = windowCovering.DeviceInfo.OutClusterList;
|
| | | // wc.AttributeStatus = windowCovering.DeviceInfo.AttributeStatus;
|
| | | // // wc.ReSave();
|
| | | // }
|
| | | // DebugPrintLog($"UI收到通知后的主题_{ topic}");
|
| | | // break;
|
| | | //case DeviceType.IASZone:
|
| | | // var ias = new IASZone() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
|
| | | // ias.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.DeviceInfoData>(jobject["Data"].ToString());
|
| | | // if (ias.DeviceInfo == null)
|
| | | // {
|
| | | // return;
|
| | | // }
|
| | | // var infoIAS = DeviceList.Find(obj => obj.DeviceID == ias.DeviceID && obj.DeviceAddr == ias.DeviceAddr && obj.DeviceEpoint == ias.DeviceEpoint);
|
| | | // if (infoIAS == null)
|
| | | // {
|
| | | // DeviceList.Add(ias);
|
| | | // ias.DeviceName = ias.DeviceInfo.MacName;
|
| | | // ias.DeviceEpointName = ias.DeviceInfo.DeviceName;
|
| | | // ias.ImgVersion = ias.DeviceInfo.ImgVersion;
|
| | | // ias.HwVersion = ias.DeviceInfo.HwVersion;
|
| | | // ias.IsOnline = ias.DeviceInfo.IsOnline;
|
| | | // ias.DriveCode = ias.DeviceInfo.DriveCode;
|
| | | // ias.IasDeviceType = ias.DeviceInfo.DeviceType;
|
| | | // ias.Profile = ias.DeviceInfo.Profile;
|
| | | // ias.ImgTypeId = ias.DeviceInfo.ImgTypeId;
|
| | | // ias.InClusterList = ias.DeviceInfo.InClusterList;
|
| | | // ias.OutClusterList = ias.DeviceInfo.OutClusterList;
|
| | | // ias.AttributeStatus = ias.DeviceInfo.AttributeStatus;
|
| | | // //ias.Save();
|
| | | // }
|
| | | // else
|
| | | // {
|
| | | // infoIAS.DeviceName = ias.DeviceInfo.MacName;
|
| | | // infoIAS.DeviceEpointName = ias.DeviceInfo.DeviceName;
|
| | | // infoIAS.DeviceEpointName = ias.DeviceInfo.DeviceName;
|
| | | // infoIAS.ImgVersion = ias.DeviceInfo.ImgVersion;
|
| | | // infoIAS.HwVersion = ias.DeviceInfo.HwVersion;
|
| | | // infoIAS.IsOnline = ias.DeviceInfo.IsOnline;
|
| | | // infoIAS.DriveCode = ias.DeviceInfo.DriveCode;
|
| | | // infoIAS.IasDeviceType = ias.DeviceInfo.DeviceType;
|
| | | // infoIAS.Profile = ias.DeviceInfo.Profile;
|
| | | // infoIAS.ImgTypeId = ias.DeviceInfo.ImgTypeId;
|
| | | // infoIAS.InClusterList = ias.DeviceInfo.InClusterList;
|
| | | // infoIAS.OutClusterList = ias.DeviceInfo.OutClusterList;
|
| | | // infoIAS.AttributeStatus = ias.DeviceInfo.AttributeStatus;
|
| | | // infoIAS.DeviceInfo = ias.DeviceInfo;
|
| | | // //ias.ReSave();
|
| | | // }
|
| | | // DebugPrintLog($"UI收到通知后的主题_{ topic}");
|
| | | // break;
|
| | | //case DeviceType.OtaDevice:
|
| | | //case DeviceType.OtaPanelDevice:
|
| | | //var ota = new OTADevice() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
|
| | | //ota.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceInfoData>(jobject["Data"].ToString());
|
| | | //if (ota.DeviceInfo == null)
|
| | | //{
|
| | | // return;
|
| | | //}
|
| | | //var infoOta = DeviceList.Find(obj => obj.DeviceID == ota.DeviceID && obj.DeviceAddr == ota.DeviceAddr && obj.DeviceEpoint == ota.DeviceEpoint);
|
| | | //if (infoOta == null)
|
| | | //{
|
| | | // DeviceList.Add(ota);
|
| | | // ota.DeviceName = ota.DeviceInfo.MacName;
|
| | | // ota.DeviceEpointName = ota.DeviceInfo.DeviceName;
|
| | | // ota.ImgVersion = ota.DeviceInfo.ImgVersion;
|
| | | // ota.HwVersion = ota.DeviceInfo.HwVersion;
|
| | | // ota.IsOnline = ota.DeviceInfo.IsOnline;
|
| | | // ota.DriveCode = ota.DeviceInfo.DriveCode;
|
| | | // ota.IasDeviceType = ota.DeviceInfo.DeviceType;
|
| | | // ota.Profile = ota.DeviceInfo.Profile;
|
| | | // ota.ImgTypeId = ota.DeviceInfo.ImgTypeId;
|
| | | // ota.InClusterList = ota.DeviceInfo.InClusterList;
|
| | | // ota.OutClusterList = ota.DeviceInfo.OutClusterList;
|
| | | // ota.AttributeStatus = ota.DeviceInfo.AttributeStatus;
|
| | | // //ota.Save();
|
| | | //}
|
| | | //else
|
| | | //{
|
| | | // infoOta.DeviceName = ota.DeviceInfo.MacName;
|
| | | // infoOta.DeviceEpointName = ota.DeviceInfo.DeviceName;
|
| | | // infoOta.DeviceEpointName = ota.DeviceInfo.DeviceName;
|
| | | // infoOta.ImgVersion = ota.DeviceInfo.ImgVersion;
|
| | | // infoOta.HwVersion = ota.DeviceInfo.HwVersion;
|
| | | // infoOta.IsOnline = ota.DeviceInfo.IsOnline;
|
| | | // infoOta.DriveCode = ota.DeviceInfo.DriveCode;
|
| | | // infoOta.IasDeviceType = ota.DeviceInfo.DeviceType;
|
| | | // infoOta.Profile = ota.DeviceInfo.Profile;
|
| | | // infoOta.ImgTypeId = ota.DeviceInfo.ImgTypeId;
|
| | | // infoOta.InClusterList = ota.DeviceInfo.InClusterList;
|
| | | // infoOta.OutClusterList = ota.DeviceInfo.OutClusterList;
|
| | | // infoOta.AttributeStatus = ota.DeviceInfo.AttributeStatus;
|
| | | // infoOta.DeviceInfo = ota.DeviceInfo;
|
| | | // //ota.ReSave();
|
| | | //}
|
| | | //DebugPrintLog($"UI收到通知后的主题_{ topic}");
|
| | | //break;
|
| | | //case DeviceType.Thermostat:
|
| | | //var thermostat = new ThermostatObj() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID };
|
| | | //thermostat.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ThermostatObj.DeviceInfoData>(jobject["Data"].ToString());
|
| | | //if (thermostat.DeviceInfo == null)
|
| | | //{
|
| | | // return;
|
| | | //}
|
| | | //var ther = gateway.DeviceList.Find(obj => obj.DeviceID == thermostat.DeviceID && obj.DeviceAddr == thermostat.DeviceAddr && obj.DeviceEpoint == thermostat.DeviceEpoint);
|
| | | //if (ther == null)
|
| | | //{
|
| | | // gateway.DeviceList.Add(thermostat);
|
| | | // thermostat.DeviceName = thermostat.DeviceInfo.DeviceName;
|
| | | // IO.LocalFileUtils.SaveDeviceInfo(thermostat, thermostat.DeviceEpoint.ToString());
|
| | | //}
|
| | | //else
|
| | | //{
|
| | | // ther.DeviceName = thermostat.DeviceInfo.DeviceName;
|
| | | // ther.DeviceInfo = thermostat.DeviceInfo;
|
| | | // ZigBee.IO.LocalFileUtils.SaveDeviceInfo(ther, ther.DeviceEpoint.ToString());
|
| | | //}
|
| | | //break;
|
| | | //case DeviceType.TemperatureSensor:
|
| | | //var temperatureSensor = new TemperatureSensor() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID };
|
| | | //temperatureSensor.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<TemperatureSensor.DeviceInfoData>(jobject["Data"].ToString());
|
| | | //if (temperatureSensor.DeviceInfo == null)
|
| | | //{
|
| | | // return;
|
| | | //}
|
| | | //var ts = gateway.DeviceList.Find(obj => obj.DeviceID == temperatureSensor.DeviceID && obj.DeviceAddr == temperatureSensor.DeviceAddr && obj.DeviceEpoint == temperatureSensor.DeviceEpoint);
|
| | | //if (ts == null)
|
| | | //{
|
| | | // gateway.DeviceList.Add(temperatureSensor);
|
| | | // temperatureSensor.DeviceName = temperatureSensor.DeviceInfo.DeviceName;
|
| | | // IO.LocalFileUtils.SaveDeviceInfo(temperatureSensor, temperatureSensor.DeviceEpoint.ToString());
|
| | | //}
|
| | | //else
|
| | | //{
|
| | | // ts.DeviceName = temperatureSensor.DeviceInfo.DeviceName;
|
| | | // ts.DeviceInfo = temperatureSensor.DeviceInfo;
|
| | | // IO.LocalFileUtils.SaveDeviceInfo(ts, ts.DeviceEpoint.ToString());
|
| | | //}
|
| | | //break;
|
| | |
|
| | | { |
| | | //case DeviceType.DimmableLight: |
| | | // var dimmableLight = new DimmableLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | // dimmableLight.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight.DeviceInfoData>(jobject["Data"].ToString()); |
| | | // if (dimmableLight.DeviceInfo == null) |
| | | // { |
| | | // return; |
| | | // } |
| | | // var light = DeviceList.Find(obj => obj.DeviceID == dimmableLight.DeviceID && obj.DeviceAddr == dimmableLight.DeviceAddr && obj.DeviceEpoint == dimmableLight.DeviceEpoint); |
| | | // if (light == null) |
| | | // { |
| | | // DeviceList.Add(dimmableLight); |
| | | // dimmableLight.DeviceName = dimmableLight.DeviceInfo.MacName; |
| | | // dimmableLight.DeviceEpointName = dimmableLight.DeviceInfo.DeviceName; |
| | | // dimmableLight.ImgVersion = dimmableLight.DeviceInfo.ImgVersion; |
| | | // dimmableLight.HwVersion = dimmableLight.DeviceInfo.HwVersion; |
| | | // dimmableLight.IsOnline = dimmableLight.DeviceInfo.IsOnline; |
| | | // dimmableLight.DriveCode = dimmableLight.DeviceInfo.DriveCode; |
| | | // dimmableLight.ImgTypeId = dimmableLight.DeviceInfo.ImgTypeId; |
| | | // dimmableLight.IasDeviceType = dimmableLight.DeviceInfo.DeviceType; |
| | | // dimmableLight.Profile = dimmableLight.DeviceInfo.Profile; |
| | | // dimmableLight.InClusterList = dimmableLight.DeviceInfo.InClusterList; |
| | | // dimmableLight.OutClusterList = dimmableLight.DeviceInfo.OutClusterList; |
| | | // dimmableLight.AttributeStatus = dimmableLight.DeviceInfo.AttributeStatus; |
| | | // //dimmableLight.Save(); |
| | | // } |
| | | // else |
| | | // { |
| | | // light.DeviceInfo = dimmableLight.DeviceInfo; |
| | | // light.DeviceName = dimmableLight.DeviceInfo.MacName; |
| | | // light.DeviceEpointName = dimmableLight.DeviceInfo.DeviceName; |
| | | // light.ImgVersion = dimmableLight.DeviceInfo.ImgVersion; |
| | | // light.HwVersion = dimmableLight.DeviceInfo.HwVersion; |
| | | // light.IsOnline = dimmableLight.DeviceInfo.IsOnline; |
| | | // light.DriveCode = dimmableLight.DeviceInfo.DriveCode; |
| | | // light.ImgTypeId = dimmableLight.DeviceInfo.ImgTypeId; |
| | | // light.IasDeviceType = dimmableLight.DeviceInfo.DeviceType; |
| | | // light.Profile = dimmableLight.DeviceInfo.Profile; |
| | | // light.InClusterList = dimmableLight.DeviceInfo.InClusterList; |
| | | // light.OutClusterList = dimmableLight.DeviceInfo.OutClusterList; |
| | | // light.AttributeStatus = dimmableLight.DeviceInfo.AttributeStatus; |
| | | // //dimmableLight.ReSave(); |
| | | // } |
| | | // DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | |
| | | // break; |
| | | //case DeviceType.OnOffSwitch: |
| | | // var panel = new Panel() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | // panel.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceInfoData>(jobject["Data"].ToString()); |
| | | // if (panel.DeviceInfo == null) |
| | | // { |
| | | // return; |
| | | // } |
| | | // var panelInfo = DeviceList.Find(obj => obj.DeviceID == panel.DeviceID && obj.DeviceAddr == panel.DeviceAddr && obj.DeviceEpoint == panel.DeviceEpoint); |
| | | // if (panelInfo == null) |
| | | // { |
| | | // DeviceList.Add(panel); |
| | | // panel.DeviceName = panel.DeviceInfo.MacName; |
| | | // panel.DeviceEpointName = panel.DeviceInfo.DeviceName; |
| | | // panel.ImgTypeId = panel.DeviceInfo.ImgTypeId; |
| | | // panel.ImgVersion = panel.DeviceInfo.ImgVersion; |
| | | // panel.HwVersion = panel.DeviceInfo.HwVersion; |
| | | // panel.IasDeviceType = panel.DeviceInfo.DeviceType; |
| | | // panel.IsOnline = panel.DeviceInfo.IsOnline; |
| | | // panel.DriveCode = panel.DeviceInfo.DriveCode; |
| | | // panel.Profile = panel.DeviceInfo.Profile; |
| | | // panel.InClusterList = panel.DeviceInfo.InClusterList; |
| | | // panel.OutClusterList = panel.DeviceInfo.OutClusterList; |
| | | // panel.AttributeStatus = panel.DeviceInfo.AttributeStatus; |
| | | // //panel.Save(); |
| | | // } |
| | | // else |
| | | // { |
| | | // panelInfo.DeviceInfo = panel.DeviceInfo; |
| | | // panelInfo.DeviceName = panel.DeviceInfo.MacName; |
| | | // panelInfo.DeviceEpointName = panel.DeviceInfo.DeviceName; |
| | | // panelInfo.ImgVersion = panel.DeviceInfo.ImgVersion; |
| | | // panelInfo.HwVersion = panel.DeviceInfo.HwVersion; |
| | | // panelInfo.IsOnline = panel.DeviceInfo.IsOnline; |
| | | // panelInfo.DriveCode = panel.DeviceInfo.DriveCode; |
| | | // panelInfo.IasDeviceType = panel.DeviceInfo.DeviceType; |
| | | // panelInfo.Profile = panel.DeviceInfo.Profile; |
| | | // panelInfo.ImgTypeId = panel.DeviceInfo.ImgTypeId; |
| | | // panelInfo.InClusterList = panel.DeviceInfo.InClusterList; |
| | | // panelInfo.OutClusterList = panel.DeviceInfo.OutClusterList; |
| | | // panelInfo.AttributeStatus = panel.DeviceInfo.AttributeStatus; |
| | | // //panel.ReSave(); |
| | | // } |
| | | // DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | |
| | | // break; |
| | | //case DeviceType.OnOffOutput: |
| | | // var toggleLight = new ToggleLight() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | // toggleLight.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight.DeviceInfoData>(jobject["Data"].ToString()); |
| | | // if (toggleLight.DeviceInfo == null) |
| | | // { |
| | | // return; |
| | | // } |
| | | // var toggleLightInfo = DeviceList.Find(obj => obj.DeviceID == toggleLight.DeviceID && obj.DeviceAddr == toggleLight.DeviceAddr && obj.DeviceEpoint == toggleLight.DeviceEpoint); |
| | | // if (toggleLightInfo == null) |
| | | // { |
| | | // DeviceList.Add(toggleLight); |
| | | // toggleLight.DeviceName = toggleLight.DeviceInfo.MacName; |
| | | // toggleLight.DeviceEpointName = toggleLight.DeviceInfo.DeviceName; |
| | | // toggleLight.ImgVersion = toggleLight.DeviceInfo.ImgVersion; |
| | | // toggleLight.HwVersion = toggleLight.DeviceInfo.HwVersion; |
| | | // toggleLight.IsOnline = toggleLight.DeviceInfo.IsOnline; |
| | | // toggleLight.DriveCode = toggleLight.DeviceInfo.DriveCode; |
| | | // toggleLight.IasDeviceType = toggleLight.DeviceInfo.DeviceType; |
| | | // toggleLight.Profile = toggleLight.DeviceInfo.Profile; |
| | | // toggleLight.ImgTypeId = toggleLight.DeviceInfo.ImgTypeId; |
| | | // toggleLight.InClusterList = toggleLight.DeviceInfo.InClusterList; |
| | | // toggleLight.OutClusterList = toggleLight.DeviceInfo.OutClusterList; |
| | | // toggleLight.AttributeStatus = toggleLight.DeviceInfo.AttributeStatus; |
| | | // //toggleLight.Save(); |
| | | // } |
| | | // else |
| | | // { |
| | | // toggleLightInfo.DeviceName = toggleLight.DeviceInfo.MacName; |
| | | // toggleLightInfo.DeviceEpointName = toggleLight.DeviceInfo.DeviceName; |
| | | // toggleLightInfo.ImgVersion = toggleLight.DeviceInfo.ImgVersion; |
| | | // toggleLightInfo.HwVersion = toggleLight.DeviceInfo.HwVersion; |
| | | // toggleLightInfo.IsOnline = toggleLight.DeviceInfo.IsOnline; |
| | | // toggleLightInfo.DriveCode = toggleLight.DeviceInfo.DriveCode; |
| | | // toggleLightInfo.IasDeviceType = toggleLight.DeviceInfo.DeviceType; |
| | | // toggleLightInfo.Profile = toggleLight.DeviceInfo.Profile; |
| | | // toggleLightInfo.ImgTypeId = toggleLight.DeviceInfo.ImgTypeId; |
| | | // toggleLightInfo.InClusterList = toggleLight.DeviceInfo.InClusterList; |
| | | // toggleLightInfo.OutClusterList = toggleLight.DeviceInfo.OutClusterList; |
| | | // toggleLightInfo.AttributeStatus = toggleLight.DeviceInfo.AttributeStatus; |
| | | // toggleLightInfo.DeviceInfo = toggleLight.DeviceInfo; |
| | | // //toggleLightInfo.ReSave(); |
| | | // } |
| | | // DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | |
| | | // break; |
| | | //case DeviceType.AirSwitch: |
| | | // var airSwitch = new AirSwitch() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | // airSwitch.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch.DeviceInfoData>(jobject["Data"].ToString()); |
| | | // if (airSwitch.DeviceInfo == null) |
| | | // { |
| | | // return; |
| | | // } |
| | | // var airSwitchInfo = DeviceList.Find(obj => obj.DeviceID == airSwitch.DeviceID && obj.DeviceAddr == airSwitch.DeviceAddr && obj.DeviceEpoint == airSwitch.DeviceEpoint); |
| | | // if (airSwitchInfo == null) |
| | | // { |
| | | // DeviceList.Add(airSwitch); |
| | | // airSwitch.DeviceName = airSwitch.DeviceInfo.MacName; |
| | | // airSwitch.DeviceEpointName = airSwitch.DeviceInfo.DeviceName; |
| | | // airSwitch.ImgVersion = airSwitch.DeviceInfo.ImgVersion; |
| | | // airSwitch.HwVersion = airSwitch.DeviceInfo.HwVersion; |
| | | // airSwitch.IsOnline = airSwitch.DeviceInfo.IsOnline; |
| | | // airSwitch.DriveCode = airSwitch.DeviceInfo.DriveCode; |
| | | // airSwitch.IasDeviceType = airSwitch.DeviceInfo.DeviceType; |
| | | // airSwitch.Profile = airSwitch.DeviceInfo.Profile; |
| | | // airSwitch.ImgTypeId = airSwitch.DeviceInfo.ImgTypeId; |
| | | // airSwitch.InClusterList = airSwitch.DeviceInfo.InClusterList; |
| | | // airSwitch.OutClusterList = airSwitch.DeviceInfo.OutClusterList; |
| | | // airSwitch.AttributeStatus = airSwitch.DeviceInfo.AttributeStatus; |
| | | // //airSwitch.Save(); |
| | | // } |
| | | // else |
| | | // { |
| | | // airSwitchInfo.DeviceName = airSwitch.DeviceInfo.MacName; |
| | | // airSwitchInfo.DeviceEpointName = airSwitch.DeviceInfo.DeviceName; |
| | | // airSwitchInfo.ImgVersion = airSwitch.DeviceInfo.ImgVersion; |
| | | // airSwitchInfo.HwVersion = airSwitch.DeviceInfo.HwVersion; |
| | | // airSwitchInfo.IsOnline = airSwitch.DeviceInfo.IsOnline; |
| | | // airSwitchInfo.DriveCode = airSwitch.DeviceInfo.DriveCode; |
| | | // airSwitchInfo.IasDeviceType = airSwitch.DeviceInfo.DeviceType; |
| | | // airSwitchInfo.Profile = airSwitch.DeviceInfo.Profile; |
| | | // airSwitchInfo.ImgTypeId = airSwitch.DeviceInfo.ImgTypeId; |
| | | // airSwitchInfo.InClusterList = airSwitch.DeviceInfo.InClusterList; |
| | | // airSwitchInfo.OutClusterList = airSwitch.DeviceInfo.OutClusterList; |
| | | // airSwitchInfo.AttributeStatus = airSwitch.DeviceInfo.AttributeStatus; |
| | | // airSwitchInfo.DeviceInfo = airSwitch.DeviceInfo; |
| | | // // airSwitchInfo.ReSave(); |
| | | // } |
| | | // DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | |
| | | // break; |
| | | //case DeviceType.WindowCoveringDevice: |
| | | // var windowCovering = new Rollershade() { DeviceID = jobject.Value<int>((object)"Device_ID"), DeviceAddr = jobject.Value<string>((object)"DeviceAddr"), DeviceEpoint = jobject.Value<int>((object)"Epoint"), DataID = jobject.Value<int>((object)"Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | // windowCovering.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade.DeviceInfoData>(jobject["Data"].ToString()); |
| | | // if (windowCovering.DeviceInfo == null) |
| | | // { |
| | | // return; |
| | | // } |
| | | // var wc = DeviceList.Find(obj => obj.DeviceID == windowCovering.DeviceID && obj.DeviceAddr == windowCovering.DeviceAddr && obj.DeviceEpoint == windowCovering.DeviceEpoint); |
| | | // if (wc == null) |
| | | // { |
| | | // DeviceList.Add(windowCovering); |
| | | // windowCovering.DeviceName = windowCovering.DeviceInfo.MacName; |
| | | // windowCovering.DeviceEpointName = windowCovering.DeviceInfo.DeviceName; |
| | | // windowCovering.ImgVersion = windowCovering.DeviceInfo.ImgVersion; |
| | | // windowCovering.HwVersion = windowCovering.DeviceInfo.HwVersion; |
| | | // windowCovering.IsOnline = windowCovering.DeviceInfo.IsOnline; |
| | | // windowCovering.DriveCode = windowCovering.DeviceInfo.DriveCode; |
| | | // windowCovering.IasDeviceType = windowCovering.DeviceInfo.DeviceType; |
| | | // windowCovering.Profile = windowCovering.DeviceInfo.Profile; |
| | | // windowCovering.ImgTypeId = windowCovering.DeviceInfo.ImgTypeId; |
| | | // windowCovering.InClusterList = windowCovering.DeviceInfo.InClusterList; |
| | | // windowCovering.OutClusterList = windowCovering.DeviceInfo.OutClusterList; |
| | | // windowCovering.AttributeStatus = windowCovering.DeviceInfo.AttributeStatus; |
| | | // //windowCovering.Save(); |
| | | // } |
| | | // else |
| | | // { |
| | | // wc.DeviceName = windowCovering.DeviceInfo.MacName; |
| | | // wc.DeviceEpointName = windowCovering.DeviceInfo.DeviceName; |
| | | // wc.DeviceInfo = windowCovering.DeviceInfo; |
| | | // wc.ImgVersion = windowCovering.DeviceInfo.ImgVersion; |
| | | // wc.HwVersion = windowCovering.DeviceInfo.HwVersion; |
| | | // wc.IsOnline = windowCovering.DeviceInfo.IsOnline; |
| | | // wc.DriveCode = windowCovering.DeviceInfo.DriveCode; |
| | | // wc.IasDeviceType = windowCovering.DeviceInfo.DeviceType; |
| | | // wc.Profile = windowCovering.DeviceInfo.Profile; |
| | | // wc.ImgTypeId = windowCovering.DeviceInfo.ImgTypeId; |
| | | // wc.InClusterList = windowCovering.DeviceInfo.InClusterList; |
| | | // wc.OutClusterList = windowCovering.DeviceInfo.OutClusterList; |
| | | // wc.AttributeStatus = windowCovering.DeviceInfo.AttributeStatus; |
| | | // // wc.ReSave(); |
| | | // } |
| | | // DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | // break; |
| | | //case DeviceType.IASZone: |
| | | // var ias = new IASZone() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | // ias.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.DeviceInfoData>(jobject["Data"].ToString()); |
| | | // if (ias.DeviceInfo == null) |
| | | // { |
| | | // return; |
| | | // } |
| | | // var infoIAS = DeviceList.Find(obj => obj.DeviceID == ias.DeviceID && obj.DeviceAddr == ias.DeviceAddr && obj.DeviceEpoint == ias.DeviceEpoint); |
| | | // if (infoIAS == null) |
| | | // { |
| | | // DeviceList.Add(ias); |
| | | // ias.DeviceName = ias.DeviceInfo.MacName; |
| | | // ias.DeviceEpointName = ias.DeviceInfo.DeviceName; |
| | | // ias.ImgVersion = ias.DeviceInfo.ImgVersion; |
| | | // ias.HwVersion = ias.DeviceInfo.HwVersion; |
| | | // ias.IsOnline = ias.DeviceInfo.IsOnline; |
| | | // ias.DriveCode = ias.DeviceInfo.DriveCode; |
| | | // ias.IasDeviceType = ias.DeviceInfo.DeviceType; |
| | | // ias.Profile = ias.DeviceInfo.Profile; |
| | | // ias.ImgTypeId = ias.DeviceInfo.ImgTypeId; |
| | | // ias.InClusterList = ias.DeviceInfo.InClusterList; |
| | | // ias.OutClusterList = ias.DeviceInfo.OutClusterList; |
| | | // ias.AttributeStatus = ias.DeviceInfo.AttributeStatus; |
| | | // //ias.Save(); |
| | | // } |
| | | // else |
| | | // { |
| | | // infoIAS.DeviceName = ias.DeviceInfo.MacName; |
| | | // infoIAS.DeviceEpointName = ias.DeviceInfo.DeviceName; |
| | | // infoIAS.DeviceEpointName = ias.DeviceInfo.DeviceName; |
| | | // infoIAS.ImgVersion = ias.DeviceInfo.ImgVersion; |
| | | // infoIAS.HwVersion = ias.DeviceInfo.HwVersion; |
| | | // infoIAS.IsOnline = ias.DeviceInfo.IsOnline; |
| | | // infoIAS.DriveCode = ias.DeviceInfo.DriveCode; |
| | | // infoIAS.IasDeviceType = ias.DeviceInfo.DeviceType; |
| | | // infoIAS.Profile = ias.DeviceInfo.Profile; |
| | | // infoIAS.ImgTypeId = ias.DeviceInfo.ImgTypeId; |
| | | // infoIAS.InClusterList = ias.DeviceInfo.InClusterList; |
| | | // infoIAS.OutClusterList = ias.DeviceInfo.OutClusterList; |
| | | // infoIAS.AttributeStatus = ias.DeviceInfo.AttributeStatus; |
| | | // infoIAS.DeviceInfo = ias.DeviceInfo; |
| | | // //ias.ReSave(); |
| | | // } |
| | | // DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | // break; |
| | | //case DeviceType.OtaDevice: |
| | | //case DeviceType.OtaPanelDevice: |
| | | //var ota = new OTADevice() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | //ota.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceInfoData>(jobject["Data"].ToString()); |
| | | //if (ota.DeviceInfo == null) |
| | | //{ |
| | | // return; |
| | | //} |
| | | //var infoOta = DeviceList.Find(obj => obj.DeviceID == ota.DeviceID && obj.DeviceAddr == ota.DeviceAddr && obj.DeviceEpoint == ota.DeviceEpoint); |
| | | //if (infoOta == null) |
| | | //{ |
| | | // DeviceList.Add(ota); |
| | | // ota.DeviceName = ota.DeviceInfo.MacName; |
| | | // ota.DeviceEpointName = ota.DeviceInfo.DeviceName; |
| | | // ota.ImgVersion = ota.DeviceInfo.ImgVersion; |
| | | // ota.HwVersion = ota.DeviceInfo.HwVersion; |
| | | // ota.IsOnline = ota.DeviceInfo.IsOnline; |
| | | // ota.DriveCode = ota.DeviceInfo.DriveCode; |
| | | // ota.IasDeviceType = ota.DeviceInfo.DeviceType; |
| | | // ota.Profile = ota.DeviceInfo.Profile; |
| | | // ota.ImgTypeId = ota.DeviceInfo.ImgTypeId; |
| | | // ota.InClusterList = ota.DeviceInfo.InClusterList; |
| | | // ota.OutClusterList = ota.DeviceInfo.OutClusterList; |
| | | // ota.AttributeStatus = ota.DeviceInfo.AttributeStatus; |
| | | // //ota.Save(); |
| | | //} |
| | | //else |
| | | //{ |
| | | // infoOta.DeviceName = ota.DeviceInfo.MacName; |
| | | // infoOta.DeviceEpointName = ota.DeviceInfo.DeviceName; |
| | | // infoOta.DeviceEpointName = ota.DeviceInfo.DeviceName; |
| | | // infoOta.ImgVersion = ota.DeviceInfo.ImgVersion; |
| | | // infoOta.HwVersion = ota.DeviceInfo.HwVersion; |
| | | // infoOta.IsOnline = ota.DeviceInfo.IsOnline; |
| | | // infoOta.DriveCode = ota.DeviceInfo.DriveCode; |
| | | // infoOta.IasDeviceType = ota.DeviceInfo.DeviceType; |
| | | // infoOta.Profile = ota.DeviceInfo.Profile; |
| | | // infoOta.ImgTypeId = ota.DeviceInfo.ImgTypeId; |
| | | // infoOta.InClusterList = ota.DeviceInfo.InClusterList; |
| | | // infoOta.OutClusterList = ota.DeviceInfo.OutClusterList; |
| | | // infoOta.AttributeStatus = ota.DeviceInfo.AttributeStatus; |
| | | // infoOta.DeviceInfo = ota.DeviceInfo; |
| | | // //ota.ReSave(); |
| | | //} |
| | | //DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | //break; |
| | | //case DeviceType.Thermostat: |
| | | //var thermostat = new ThermostatObj() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID }; |
| | | //thermostat.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ThermostatObj.DeviceInfoData>(jobject["Data"].ToString()); |
| | | //if (thermostat.DeviceInfo == null) |
| | | //{ |
| | | // return; |
| | | //} |
| | | //var ther = gateway.DeviceList.Find(obj => obj.DeviceID == thermostat.DeviceID && obj.DeviceAddr == thermostat.DeviceAddr && obj.DeviceEpoint == thermostat.DeviceEpoint); |
| | | //if (ther == null) |
| | | //{ |
| | | // gateway.DeviceList.Add(thermostat); |
| | | // thermostat.DeviceName = thermostat.DeviceInfo.DeviceName; |
| | | // IO.LocalFileUtils.SaveDeviceInfo(thermostat, thermostat.DeviceEpoint.ToString()); |
| | | //} |
| | | //else |
| | | //{ |
| | | // ther.DeviceName = thermostat.DeviceInfo.DeviceName; |
| | | // ther.DeviceInfo = thermostat.DeviceInfo; |
| | | // ZigBee.IO.LocalFileUtils.SaveDeviceInfo(ther, ther.DeviceEpoint.ToString()); |
| | | //} |
| | | //break; |
| | | //case DeviceType.TemperatureSensor: |
| | | //var temperatureSensor = new TemperatureSensor() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID }; |
| | | //temperatureSensor.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<TemperatureSensor.DeviceInfoData>(jobject["Data"].ToString()); |
| | | //if (temperatureSensor.DeviceInfo == null) |
| | | //{ |
| | | // return; |
| | | //} |
| | | //var ts = gateway.DeviceList.Find(obj => obj.DeviceID == temperatureSensor.DeviceID && obj.DeviceAddr == temperatureSensor.DeviceAddr && obj.DeviceEpoint == temperatureSensor.DeviceEpoint); |
| | | //if (ts == null) |
| | | //{ |
| | | // gateway.DeviceList.Add(temperatureSensor); |
| | | // temperatureSensor.DeviceName = temperatureSensor.DeviceInfo.DeviceName; |
| | | // IO.LocalFileUtils.SaveDeviceInfo(temperatureSensor, temperatureSensor.DeviceEpoint.ToString()); |
| | | //} |
| | | //else |
| | | //{ |
| | | // ts.DeviceName = temperatureSensor.DeviceInfo.DeviceName; |
| | | // ts.DeviceInfo = temperatureSensor.DeviceInfo; |
| | | // IO.LocalFileUtils.SaveDeviceInfo(ts, ts.DeviceEpoint.ToString()); |
| | | //} |
| | | //break; |
| | | |
| | | }
|
| | | }
|
| | | else if (topic == gatewayID + "/" + "DeviceInfoResponEnd")
|
| | |
| | | ///<para>Result2:数据解析错误</para> |
| | | ///<para>Result3:发送数据大小超出限制</para> |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<Panel.PanelSwitchLevelInfo> ClientDataPassthroughBytesAsync(string deviceAddr, int devicePoint,long dataLength, byte[] passData) |
| | | public async System.Threading.Tasks.Task<Panel.PanelSwitchLevelInfo> ClientDataPassthroughBytesAsync(string deviceAddr, int devicePoint, long dataLength, byte[] passData) |
| | | { |
| | | Panel.PanelSwitchLevelInfo result = null; |
| | | Panel.PanelSwitchLevelInfo result = null; |
| | | if (Gateway == null) |
| | | { |
| | | result = new Panel.PanelSwitchLevelInfo { errorMessageBase = "当前没有网关" }; |
| | |
| | | sendDataBytes[1] = Convert.ToByte(devicePoint); |
| | | //设备mac地址,小端结构,8个bytes |
| | | //var addrAllBytes = new byte[8]; |
| | | int j=0; |
| | | int j = 0; |
| | | for (int i = 14; i >= 0; i = i - 2) |
| | | { |
| | | var curByte= deviceAddr.Substring(i, 2); //00 0d 6f ff fe 04 51 52 |
| | | var curByte = deviceAddr.Substring(i, 2); //00 0d 6f ff fe 04 51 52 |
| | | |
| | | sendDataBytes[2 + j] = Convert.ToByte(string.Format("0x{0}", curByte), 16); |
| | | j++; |
| | |
| | | var gateway = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString()); |
| | | dataRes = new SendFileResponseAllData { Result = result }; |
| | | if(result ==0) |
| | | if (result == 0) |
| | | { |
| | | isRespond = true; |
| | | } |
| | |
| | | { |
| | | if (WaitReceiveDataTime < (DateTime.Now - dateTime).TotalMilliseconds) |
| | | { |
| | | return new SendFileResponseAllData { errorMessageBase = "回复超时,请重新操作" }; ; |
| | | return new SendFileResponseAllData { errorMessageBase = "回复超时,请重新操作" }; ; |
| | | } |
| | | await System.Threading.Tasks.Task.Delay(10); |
| | | } |
| | |
| | | } |
| | | } |
| | | catch { } |
| | | finally{ |
| | | finally |
| | | { |
| | | Actions -= action; |
| | | } |
| | | DebugPrintLog("Security/ChangeAdminPassword_Actions 退出" + System.DateTime.Now.ToString()); |
| | |
| | | if (tempData.Result == 0) |
| | | { |
| | | ZbGateway.byteSource.Clear(); |
| | | } |
| | | } |
| | | tempDa.Result = tempData.Result; |
| | | dataRes.setDownloadFileResponseData = tempDa; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | |
| | | /// <summary> |
| | | /// 局域网的MQTT |
| | | /// </summary> |
| | | IMqttClient mqttClient; |
| | | IMqttClient localMqttClient = new MqttFactory().CreateMqttClient(); |
| | | bool localMqttIsConnecting; |
| | | public bool localIsConnected; |
| | | /// <summary> |
| | | /// 手机标识 |
| | | /// </summary> |
| | | static Guid currentGuid = Guid.NewGuid(); |
| | | /// <summary> |
| | | /// 局域网的MQTT是否正在连接 |
| | | /// </summary> |
| | | object mqttIsConnecting=false.ToString(); |
| | | |
| | | public async System.Threading.Tasks.Task SendAesKey()
|
| | | {
|
| | | if (PubKey != null)
|
| | | {
|
| | | IsEncry = false;
|
| | | var rsaString = ZigBee.Common.SecuritySet.RSAEncrypt(PubKey, Password);
|
| | | var resultVerityfy = await SendAesKeyAsync(rsaString);
|
| | | if (resultVerityfy == null)
|
| | | {
|
| | | resultVerityfy = await SendAesKeyAsync(rsaString);
|
| | | }
|
| | |
|
| | | if (resultVerityfy != null && resultVerityfy.Result == 0)
|
| | | {
|
| | | IsEncry = true;
|
| | | }
|
| | | } |
| | | } |
| | | |
| | | public async System.Threading.Tasks.Task StartLocalMqtt(string brokerName) |
| | | { |
| | | await System.Threading.Tasks.Task.Factory.StartNew(async() => |
| | | {
|
| | | if (localMqttIsConnecting
|
| | | || !Shared.Common.Config.Instance.IsLogin
|
| | | || Shared.Common.Config.Instance.HomeId == ""
|
| | | || localIsConnected)
|
| | | {
|
| | | return;
|
| | | } |
| | | await System.Threading.Tasks.Task.Factory.StartNew(async () => |
| | | { |
| | | try |
| | | { |
| | | lock (mqttIsConnecting) |
| | | lock (localMqttClient) |
| | | { |
| | | if (mqttIsConnecting.ToString() == true.ToString() || brokerName == null) |
| | | { |
| | | return; |
| | | } |
| | | mqttIsConnecting = true.ToString(); |
| | | //表示后面将进行连接 |
| | | localMqttIsConnecting = true; |
| | | |
| | | if (mqttClient == null) |
| | | //(3)当[连接Mqtt成功后]或者[Mqtt转发数据给网关成功后],处理接收到数据包响应时在mqttClient_ApplicationMessageReceived这个方法处理 |
| | | if (localMqttClient.ApplicationMessageReceivedHandler == null) |
| | | { |
| | | //(2)创建Mqtt客户端 |
| | | mqttClient = new MqttClientFactory().CreateMqttClient(); |
| | | //(3)当[连接Mqtt成功后]或者[Mqtt转发数据给网关成功后],处理接收到数据包响应时在mqttClient_ApplicationMessageReceived这个方法处理 |
| | | mqttClient.ApplicationMessageReceived += (sender, e) => |
| | | { |
| | | if (mqttClient == null || !mqttClient.IsConnected) |
| | | localMqttClient.UseApplicationMessageReceivedHandler((e) => |
| | | { |
| | | return; |
| | | } |
| | | mqttClient_MqttMsgPublishReceived(sender, e); |
| | | }; |
| | | mqttClient.Disconnected += (sender, e) => |
| | | { |
| | | IsEncry = false; |
| | | #if DEBUG |
| | | DebugPrintLog($" 本地连接断开_网关IP:{brokerName}_网关是否加:{IsEncry}_{System.DateTime.Now.ToString()}"); |
| | | #endif |
| | | }; |
| | | mqttClient.Connected += async (sender, e) => |
| | | { |
| | | #if DEBUG |
| | | DebugPrintLog($" 本地连接成功_网关IP:{brokerName}_网关是否加:{IsEncry}_当前密码:{Password}_{System.DateTime.Now.ToString()}"); |
| | | #endif |
| | | |
| | | //if (PubKey != null) |
| | | //{ |
| | | // var rsaString = ZigBee.Common.SecuritySet.RSAEncrypt(PubKey, Password); |
| | | // var resultVerityfy = await SendAesKeyAsync(rsaString); |
| | | // if (resultVerityfy == null) |
| | | // { |
| | | // resultVerityfy = await SendAesKeyAsync(rsaString); |
| | | // } |
| | | // if (resultVerityfy != null && resultVerityfy.Result == 0) |
| | | // { |
| | | // IsEncry = true; |
| | | // } |
| | | //} |
| | | Shared.Common.LocalGateway.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.WIFI); |
| | | System.Console.WriteLine($"当前是网关Wi-Fi在通讯_{System.DateTime.Now.ToString()}"); |
| | | |
| | | }; |
| | | if (!localMqttClient.IsConnected) |
| | | { |
| | | return; |
| | | } |
| | | mqttClient_MqttMsgPublishReceived(e); |
| | | }); |
| | | } |
| | | |
| | | if (RemoteMqttClient != null && RemoteMqttClient.IsConnected == true) |
| | | if (localMqttClient.DisconnectedHandler == null) |
| | | { |
| | | RemoteMqttClient?.DisconnectAsync(); |
| | | System.Console.WriteLine($"收到局域网网关,远程连接主动断开_{System.DateTime.Now.ToString()}"); |
| | | RemoteMqttClient = null; |
| | | localMqttClient.UseDisconnectedHandler(async (e) => |
| | | {
|
| | | DebugPrintLog($" 本地连接断开_网关IP:{brokerName}_网关是否加:{IsEncry}"); |
| | | await DisConnectLocalMqttClient("StartLocalMqtt.DisconnectedHandler"); |
| | | //await StartLocalMqtt("ReConnect"); |
| | | }); |
| | | } |
| | | |
| | | if (mqttClient.IsConnected) |
| | | if (localMqttClient.ConnectedHandler == null) |
| | | { |
| | | return; |
| | | } |
| | | } |
| | | //(1)连接到Mqtt客户端连接参数 |
| | | var connectCloudMqttClientOptions = new MqttClientTcpOptions |
| | | { |
| | | Server = brokerName, //ip地址 |
| | | ClientId = currentGuid.ToString(), |
| | | CleanSession = true,// 设置是否清空session,这里如果设置为false表示服务器会保留客户端的连接记录,这里设置为true表示每次连接到服务器都以新的身份连接 |
| | | KeepAlivePeriod = new TimeSpan(0, 5, 0),//设置心跳时间(最大值,2^16-1 = 65535秒 = 18小时。最小值可以为0,表示客户端不断开。一般设为几分钟,比如微信心跳周期为300秒。) |
| | | DefaultCommunicationTimeout = new TimeSpan(0, 0, 100),//设置超时时间 |
| | | };
|
| | | await mqttClient.ConnectAsync(connectCloudMqttClientOptions); |
| | | localMqttClient.UseConnectedHandler(async (e) =>
|
| | | {
|
| | | DebugPrintLog($" 本地连接成功_网关IP:{brokerName}_网关是否加:{IsEncry}_当前密码:{Password}");
|
| | | IsRemote = false;
|
| | | Shared.Phone.UserCenter.HdlGatewayLogic.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.WIFI);
|
| | | }); |
| | | }
|
| | |
|
| | | var dateTime = DateTime.Now;
|
| | |
|
| | | new System.Threading.Thread(async () =>
|
| | | {
|
| | | try
|
| | | {
|
| | | if (localMqttClient.Options == null)
|
| | | {
|
| | | var options = new MQTTnet.Client.Options.MqttClientOptionsBuilder().WithClientId(currentGuid.ToString())
|
| | | .WithTcpServer(brokerName, 1883)
|
| | | .WithKeepAlivePeriod(TimeSpan.FromSeconds(20))
|
| | | .WithCleanSession()
|
| | | //.WithCommunicationTimeout(TimeSpan.FromSeconds(10))
|
| | | .WithCredentials("", "")
|
| | | .Build();
|
| | | await localMqttClient.ConnectAsync(options, CancellationToken.None);
|
| | | }
|
| | | else
|
| | | {
|
| | | await DisConnectLocalMqttClient("StartLocalMqtt");
|
| | | await localMqttClient.ReconnectAsync();
|
| | | }
|
| | | localIsConnected = true;
|
| | | await SendAesKey();
|
| | | }
|
| | | catch { }
|
| | | dateTime = DateTime.MinValue;
|
| | | })
|
| | | { IsBackground = true }.Start();
|
| | | while (dateTime != DateTime.MinValue)
|
| | | {
|
| | | System.Threading.Thread.Sleep(100);
|
| | | }
|
| | | }
|
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | #if DEBUG |
| | | DebugPrintLog($"局域网通讯连接出异常:{ex.Message}"); |
| | | #endif |
| | | } |
| | | finally |
| | | { |
| | | mqttIsConnecting = false.ToString(); |
| | | localMqttIsConnecting = false; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | class GateWayBaseInfomation |
| | | { |
| | | //public string GatewayUniqueId;//"Emq网关1", <!-- 网关Mac --> |
| | | public bool MqttOnlineStatus;//: true, <!-- 网关在云端Emq是否在线 --> |
| | | public string AesKey;// : "a5d8da8a-ddea-48", <!-- 与此网关在云端Emq通信时,负载加解的16位Aes密钥 --> |
| | | public string MacMark;//: "61eaa0ea-4812-4a7a-86d6-3098c61e64ed" <!-- 网关对应的唯一码 --> |
| | | } |
| | | /// <summary> |
| | | /// 当前有帐号下所有的网关列表及信息 |
| | | /// </summary> |
| | | static Dictionary<string, GateWayBaseInfomation> GateWayBaseInfomations = new Dictionary<string, GateWayBaseInfomation> { }; |
| | | /// <summary> |
| | | /// 获取当前帐号所有的网关信息 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | static async System.Threading.Tasks.Task initGateWayBaseInfomation() |
| | | {
|
| | | if (AllowRemoteCtrl == false)
|
| | | {
|
| | | //没有远程连接的权限
|
| | | return;
|
| | | }
|
| | | string loginToken = Config.Instance.Token;
|
| | | if (Config.Instance.Home.IsOthreShare == true)
|
| | | {
|
| | | //获取成员的特殊Token
|
| | | var pra = new
|
| | | {
|
| | | CommonPage.RequestVersion,
|
| | | LoginAccessToken = Config.Instance.Token,
|
| | | MainAccountId = Config.Instance.Home.MainUserDistributedMark,
|
| | | SharedHid = Config.Instance.Home.Id
|
| | | };
|
| | |
|
| | | var listNotShow = new List<string>() { "NotSetAgain" };
|
| | | var resultData = await Shared.Phone.UserCenter.UserCenterLogic.GetByteResponseDataByRequestHttps("App/GetSharedHomeApiControl", false, pra, listNotShow);
|
| | | if (resultData == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | var revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.ResponsePack>(Encoding.UTF8.GetString(resultData));
|
| | | //分享链接
|
| | | var info = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Phone.UserCenter.MemberAdministratorResult>(revertObj.ResponseData.ToString());
|
| | | loginToken = info.RequestToken;
|
| | | }
|
| | |
|
| | | try |
| | | { |
| | | //设置访问接口的参数
|
| | | var pra2 = new Shared.Phone.UserCenter.GetGatewayPra();
|
| | | pra2.IsOtherAccountCtrl = Config.Instance.Home.IsOthreShare;
|
| | | pra2.ReqDto.PageSetting.Page = 1;
|
| | | pra2.ReqDto.PageSetting.PageSize = 20;
|
| | | pra2.ReqDto.LoginAccessToken = loginToken; |
| | | var bytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(pra2)); |
| | | |
| | | var result = await CommonPage.Instance.DoRequestZigbeeHttpsInterface("https://global.hdlcontrol.com/HangZhouHdlCloudApi/App/GetSingleHomeGatewayPagger", bytes, loginToken);
|
| | | if (result != null)
|
| | | {
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(Encoding.UTF8.GetString(result));
|
| | |
|
| | | var statuCode = jobject["StateCode"].ToString();
|
| | | if (statuCode != "Success")
|
| | | {
|
| | | //序列化对象
|
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(pra2);
|
| | | //Log出力
|
| | | string errorMsg = "接口访问失败★:App/GetSingleHomeGatewayPagger " + statuCode + "\r\n";
|
| | | errorMsg += "参数:\r\n" + requestJson;
|
| | | Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(-1, errorMsg);
|
| | | return;
|
| | | }
|
| | |
|
| | | var responseData = jobject["ResponseData"];
|
| | | if (responseData != null)
|
| | | {
|
| | | if (responseData["PageData"] != null)
|
| | | {
|
| | | var list = JArray.Parse(responseData["PageData"].ToString());
|
| | | foreach (var v in list)
|
| | | {
|
| | | GateWayBaseInfomations[v["GatewayUniqueId"].ToString()] = new GateWayBaseInfomation { AesKey = v["AesKey"].ToString(), MacMark = v["MacMark"].ToString(), MqttOnlineStatus = bool.Parse(v["MqttOnlineStatus"].ToString()) };
|
| | | //if (RemoteMqttClient.IsConnected)
|
| | | {
|
| | | await RemoteMqttClient.SubscribeAsync($"/ZigbeeGateWayToClient/{v["MacMark"].ToString()}/#", MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | } |
| | | } |
| | | catch (Exception ex)
|
| | | { |
| | | Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(ex); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 外网的MQTT是否正在连接 |
| | | /// </summary> |
| | | static bool remoteMqttIsConnecting; static bool IsLoginAgain; |
| | | static bool remoteMqttIsConnecting; |
| | | static bool IsLoginAgain; |
| | | /// <summary> |
| | | /// 远程MqttClient |
| | | /// </summary> |
| | | public static IMqttClient RemoteMqttClient; |
| | | public static IMqttClient RemoteMqttClient= new MqttFactory().CreateMqttClient(); |
| | | static bool remoteIsConnected; |
| | | private int IsLogin = 0; |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | static Action actionTemp; |
| | | |
| | | /// <summary> |
| | | /// 启动远程Mqtt |
| | | /// </summary> |
| | | /// <returns>The start.</returns> |
| | | /// <param name="brokerName">Broker name.</param> |
| | | public static async System.Threading.Tasks.Task StartCloudMqtt() |
| | | { |
| | | public static async System.Threading.Tasks.Task StartRemoteMqtt() |
| | | {
|
| | | //追加:没有远程连接的权限
|
| | | if (AllowRemoteCtrl == false
|
| | | || remoteMqttIsConnecting
|
| | | || !Shared.Common.Config.Instance.IsLogin
|
| | | || Shared.Common.Config.Instance.HomeId == ""
|
| | | || remoteIsConnected)
|
| | | {
|
| | | return;
|
| | | } |
| | | await System.Threading.Tasks.Task.Factory.StartNew(async () => |
| | | { |
| | | try |
| | | { |
| | | if (remoteMqttIsConnecting) |
| | | lock (RemoteMqttClient) |
| | | { |
| | | return; |
| | | } |
| | | remoteMqttIsConnecting = true; |
| | | //表示后面将进行连接 |
| | | remoteMqttIsConnecting = true; |
| | | |
| | | var url = Shared.Common.Config.Instance.ZigbeeMqttBrokerLoadSubDomain;//.Replace("6688","6689"); |
| | | if (string.IsNullOrEmpty(url) || !url.StartsWith("tcp://") || url.Split(':').Length != 3) |
| | | { |
| | | return; |
| | | } |
| | | if (RemoteMqttClient == null) |
| | | { |
| | | //(2)创建Mqtt客户端 |
| | | RemoteMqttClient = new MqttClientFactory().CreateMqttClient(); |
| | | #region 初始化远程Mqtt |
| | | //(3)当[连接云端的Mqtt成功后]或者[以及后面App通过云端Mqtt转发数据给网关成功后],处理接收到云端数据包响应时在mqttServerClient_ApplicationMessageReceived这个方法处理 |
| | | RemoteMqttClient.ApplicationMessageReceived += (sender, e) => |
| | | if (RemoteMqttClient.ApplicationMessageReceivedHandler == null) |
| | | { |
| | | if (RemoteMqttClient == null || !RemoteMqttClient.IsConnected) |
| | | RemoteMqttClient.UseApplicationMessageReceivedHandler((e) => |
| | | { |
| | | return; |
| | | } |
| | | mqttRemoteClient_MqttMsgPublishReceived(sender, e); |
| | | }; |
| | | RemoteMqttClient.Disconnected += (sender, e) => |
| | | { |
| | | #if DEBUG |
| | | DebugPrintLog($"远程连接断开_{System.DateTime.Now.ToString()}"); |
| | | #endif |
| | | }; |
| | | RemoteMqttClient.Connected += async (sender, e) =>
|
| | | {
|
| | | #if DEBUG |
| | | DebugPrintLog($"远程连接成功_{System.DateTime.Now.ToString()}");
|
| | | #endif |
| | | Shared.Common.LocalGateway.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.Remote); |
| | | //没有主网关时主动读取,获取主网关信息 |
| | | var gateWayList = GateWayList.FindAll(obj => obj.getGatewayBaseInfo.HomeId == Shared.Common.Config.Instance.HomeId); |
| | | if (gateWayList.Find(obj => obj.getGatewayBaseInfo.IsMainGateWay == true) == null) |
| | | { |
| | | if (gateWayList.Count == 1) |
| | | { |
| | | gateWayList[0].getGatewayBaseInfo.IsMainGateWay = true; |
| | | } |
| | | else |
| | | { |
| | | for (int i = 0; i < gateWayList.Count; i++) |
| | | { |
| | | var gateWay = gateWayList[i]; |
| | | var info = await gateWay.GetZbGwInfoAsync(); |
| | | if (info == null || info.getGwData == null) |
| | | { |
| | | continue; |
| | | } |
| | | if (info.getGwData.IsDominant == 1) |
| | | { |
| | | gateWay.getGatewayBaseInfo.IsMainGateWay = true; |
| | | for (int j = i + 1; j < gateWayList.Count; j++) |
| | | { |
| | | gateWayList[j].getGatewayBaseInfo.IsMainGateWay = false; |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | } |
| | | |
| | | if (RemoteMqttClient.IsConnected) |
| | | {
|
| | | //当网关的连接方式改变时,检测网关,然后显示特效(可重复调用)
|
| | | return; |
| | | } |
| | | for (int i = 0; i < GateWayList.Count; i++) |
| | | { |
| | | var gateWay = GateWayList[i]; |
| | | try |
| | | { |
| | | gateWay.IsVirtual = true; |
| | | await gateWay.DisConnect("本地搜素不到网关,准备调用远程,关闭当前局域网中所有网关"); |
| | | if (!RemoteMqttClient.IsConnected || !IsRemote) |
| | | { |
| | | return; |
| | | } |
| | | mqttRemoteClient_MqttMsgPublishReceived(e); |
| | | }); |
| | | } |
| | | catch { } |
| | | } |
| | | //断开后重新链接需要重新登录获取连接的密码 |
| | | var tempResult = await Shared.Phone.UserView.HomePage.Instance.LoginByPWDAsync(Shared.Common.Config.Instance.Account, Shared.Common.Config.Instance.Password); |
| | | if (tempResult != 1) |
| | | { |
| | | #if DEBUG |
| | | DebugPrintLog($"重新连接远程通讯失败,因为获取新的KEY失败"); |
| | | #endif |
| | | return; |
| | | |
| | | if (RemoteMqttClient.DisconnectedHandler == null) |
| | | { |
| | | RemoteMqttClient.UseDisconnectedHandler(async (e) => |
| | | { |
| | | DebugPrintLog($"远程连接断开"); |
| | | await DisConnectRemoteMqttClient("StartRemoteMqtt.DisconnectedHandler"); |
| | | //await StartRemoteMqtt(); |
| | | }); |
| | | } |
| | | if (RemoteMqttClient.ConnectedHandler == null) |
| | | { |
| | | RemoteMqttClient.UseConnectedHandler(async (e) =>
|
| | | {
|
| | | DebugPrintLog($"远程连接成功");
|
| | |
|
| | | if (Config.Instance.Home.IsOthreShare == true)
|
| | | {
|
| | | //订阅一个成员被删除的主题
|
| | | string myGuid = Config.Instance.Guid;
|
| | | await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + myGuid + "/Push/Deleted");
|
| | | //订阅一个分享数据已经变更的主题
|
| | | await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + myGuid + "/Push/DeletedShareData");
|
| | | }
|
| | | //订阅一个挤下线的主题
|
| | | await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + Config.Instance.ConnEmqClientId + "/Push/NotifySqueeze");
|
| | |
|
| | | await initGateWayBaseInfomation(); |
| | | Shared.Phone.UserCenter.HdlGatewayLogic.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.Remote);
|
| | | //没有主网关时主动读取,获取主网关信息
|
| | | var gateWayList = GateWayList.FindAll(obj => obj.getGatewayBaseInfo.HomeId == Shared.Common.Config.Instance.HomeId);
|
| | | if (gateWayList.Find(obj => obj.getGatewayBaseInfo.IsMainGateWay == true) == null)
|
| | | {
|
| | | if (gateWayList.Count == 1)
|
| | | {
|
| | | gateWayList[0].getGatewayBaseInfo.IsMainGateWay = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | for (int i = 0; i < gateWayList.Count; i++)
|
| | | {
|
| | | var gateWay = gateWayList[i];
|
| | | var info = await gateWay.GetZbGwInfoAsync();
|
| | | if (info == null || info.getGwData == null)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | if (info.getGwData.IsDominant == 1)
|
| | | {
|
| | | for (int j = 0; j < gateWayList.Count; j++)
|
| | | {
|
| | | if (gateWayList[i].getGatewayBaseInfo.gwID == info.getGwData.GwId)
|
| | | {
|
| | | gateWayList[i].getGatewayBaseInfo.IsMainGateWay = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | gateWayList[i].getGatewayBaseInfo.IsMainGateWay = false;
|
| | | }
|
| | | }
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }); |
| | | } |
| | | #endregion |
| | | } |
| | | |
| | | //还有种情况是同一个ID 有多个设备用这个id连接(会导致中断) |
| | | string clientId = Shared.Common.Config.Instance.ConnectZigbeeMqttClientId; |
| | | string username = Shared.Common.Config.Instance.ConnectZigbeeMqttBrokerName; |
| | | string passwordRemote = Shared.Common.Config.Instance.ConnectZigbeeMqttBrokerPwd; |
| | | //(1)连接到云端的Mqtt客户端连接参数 |
| | | var connectCloudMqttClientOptions = new MqttClientTcpOptions |
| | | try |
| | | {
|
| | | byte[] result = null;
|
| | | if (Config.Instance.Home.IsOthreShare == false)
|
| | | {
|
| | | //主人
|
| | | var jsonData = new Dictionary<string, object>
|
| | | {
|
| | | ["RequestVersion"] = CommonPage.RequestVersion,
|
| | | ["RequestSource"] = 0,
|
| | | ["LoginAccessToken"] = Config.Instance.Token,
|
| | | ["RequestProtocolType"] = 0
|
| | | };
|
| | | var bytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(jsonData));
|
| | | result = await CommonPage.Instance.DoRequestZigbeeHttpsInterface("https://global.hdlcontrol.com/HangZhouHdlCloudApi/EmqMqtt/GetConnMqttInfo", bytes, Config.Instance.Token);
|
| | | } |
| | | else
|
| | | {
|
| | | //分享的
|
| | | var jsonData = new Dictionary<string, object>
|
| | | {
|
| | | ["RequestVersion"] = CommonPage.RequestVersion,
|
| | | ["RequestSource"] = 0,
|
| | | ["LoginAccessToken"] = Config.Instance.Token,
|
| | | ["RequestProtocolType"] = 0,
|
| | | ["MainUserDistributedMark"] = Config.Instance.Home.MainUserDistributedMark,
|
| | | ["HomeId"] = Config.Instance.Home.Id
|
| | | };
|
| | | var bytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(jsonData));
|
| | | result = await CommonPage.Instance.DoRequestZigbeeHttpsInterface("https://global.hdlcontrol.com/HangZhouHdlCloudApi/EmqMqtt/ShareMemberConnMqttInfo", bytes, Config.Instance.Token);
|
| | | } |
| | | if (result != null) |
| | | { |
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(Encoding.UTF8.GetString(result)); |
| | | if (jobject["StateCode"].ToString() == "NotAllowRemoteCtrl")
|
| | | {
|
| | | //没有远程连接的权限
|
| | | AllowRemoteCtrl = false;
|
| | | return;
|
| | | } |
| | | var responseData = jobject["ResponseData"]; |
| | | if (responseData != null) |
| | | { |
| | | var connEmqDomainPort = responseData["ConnEmqDomainPort"]?.ToString(); |
| | | var connEmqClientId = responseData["ConnEmqClientId"]?.ToString(); |
| | | var connEmqUserName = responseData["ConnEmqUserName"]?.ToString(); |
| | | var connEmqPwd = responseData["ConnEmqPwd"]?.ToString(); |
| | | //记录起当前的客户端ID |
| | | Config.Instance.ConnEmqClientId = connEmqClientId; |
| | | |
| | | var connEmqDomainPorts = connEmqDomainPort.Replace("//", "").Split(':'); |
| | | var domain = connEmqDomainPorts[1]; |
| | | var port = connEmqDomainPorts[2];
|
| | |
|
| | | var options = new MQTTnet.Client.Options.MqttClientOptionsBuilder()
|
| | | .WithClientId(connEmqClientId)
|
| | | .WithTcpServer(domain, int.Parse(port))
|
| | | .WithCredentials(connEmqUserName, connEmqPwd)
|
| | | .WithKeepAlivePeriod(TimeSpan.FromSeconds(20))
|
| | | .WithCleanSession()
|
| | | //.WithCommunicationTimeout(TimeSpan.FromSeconds(10))
|
| | | .Build();
|
| | | await DisConnectRemoteMqttClient("StartRemoteMqtt");
|
| | | await RemoteMqttClient.ConnectAsync(options, CancellationToken.None);
|
| | |
|
| | | remoteIsConnected = true; |
| | | } |
| | | } |
| | | } |
| | | catch { } |
| | | finally |
| | | { |
| | | Server = url.Split(':')[1].Substring("//".Length), //114.215.173.87 先写ip吧,这个地址可能后面会换成域名 |
| | | Port = int.Parse(url.Split(':')[2]), |
| | | ClientId = clientId, |
| | | UserName = username,//连接的用户名 |
| | | Password = passwordRemote,//连接的密码(App登录后获取到的连接云端Mqtt密码只能连接一次成功之后不能再使用相同的密码进行连接Mqtt否则会提示用户名密码失败,连接不上云端;) |
| | | CleanSession = true,// 设置是否清空session,这里如果设置为false表示服务器会保留客户端的连接记录,这里设置为true表示每次连接到服务器都以新的身份连接 |
| | | KeepAlivePeriod = new TimeSpan(0, 5, 0),//设置心跳时间(最大值,2^16-1 = 65535秒 = 18小时。最小值可以为0,表示客户端不断开。一般设为几分钟,比如微信心跳周期为300秒。) |
| | | DefaultCommunicationTimeout = new TimeSpan(0, 0, 100),//设置超时时间 |
| | | }; |
| | | await RemoteMqttClient.ConnectAsync(connectCloudMqttClientOptions); |
| | | //最终要释放连接状态 |
| | | remoteMqttIsConnecting = false;
|
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | #if DEBUG |
| | | DebugPrintLog($"远程连接通讯连接出异常:{ex.Message}"); |
| | | #endif |
| | | } |
| | | finally |
| | | { |
| | | remoteMqttIsConnecting = false; |
| | | } |
| | | }); |
| | | } |
| | |
| | | /// <summary> |
| | | /// 断开服务器连接 |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task DisConnect(string s) |
| | | public async System.Threading.Tasks.Task DisConnectLocalMqttClient(string s) |
| | | { |
| | | try |
| | | { |
| | | #if DEBUG |
| | | DebugPrintLog($"主动断开_{System.DateTime.Now.ToString()}_{s}"); |
| | | #endif |
| | | if (mqttClient != null && mqttClient.IsConnected == true)
|
| | | if (localIsConnected)
|
| | | {
|
| | | await mqttClient.DisconnectAsync();
|
| | | } |
| | | localIsConnected = false;
|
| | | DebugPrintLog($"Local主动断开_{s}");
|
| | | //await localMqttClient.DisconnectAsync(new MQTTnet.Client.Disconnecting.MqttClientDisconnectOptions { }, CancellationToken.None);
|
| | | await localMqttClient.DisconnectAsync(); |
| | | }
|
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | #if DEBUG |
| | | DebugPrintLog($"断开通讯连接出异常:{ex.Message}"); |
| | | #endif |
| | | DebugPrintLog($"Local断开通讯连接出异常:{ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 断开远程Mqtt的链接
|
| | | /// </summary> |
| | | public static async System.Threading.Tasks.Task DisConnectRemoteMqttClient(string s="")
|
| | | {
|
| | | try
|
| | | {
|
| | | if (remoteIsConnected)
|
| | | {
|
| | | remoteIsConnected = false;
|
| | | DebugPrintLog($"Remote主动断开_{s}");
|
| | | //await RemoteMqttClient.DisconnectAsync(new MQTTnet.Client.Disconnecting.MqttClientDisconnectOptions { }, CancellationToken.None);
|
| | | await RemoteMqttClient.DisconnectAsync();
|
| | | }
|
| | | }
|
| | | catch(Exception e) {
|
| | | DebugPrintLog($"Remote断开通讯连接出异常:{e.Message}");
|
| | | }
|
| | | } |
| | | |
| | | #endregion |
| | | |
| | | /// <summary> |
| | |
| | | /// <summary> |
| | | /// 远程发送数据格式 |
| | | /// </summary> |
| | | async System.Threading.Tasks.Task SendRemoteMsg(string topicName, byte[] message, MQTTnet.Core.Protocol.MqttQualityOfServiceLevel qosLevel = MQTTnet.Core.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, bool retain = false) |
| | | async System.Threading.Tasks.Task SendRemoteMsg(string topicName, byte[] message, bool retain = false) |
| | | { |
| | | #region MD5加密 token |
| | | var result = System.Text.Encoding.UTF8.GetBytes(Shared.Common.Config.Instance.Password); |
| | | var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); |
| | | var output = md5.ComputeHash(result); |
| | | var md5Password = BitConverter.ToString(output).Replace("-", "").ToUpper(); |
| | | #endregion |
| | | |
| | | //(1)生成[用户名:密码] |
| | | var userNameAndPwdStr = string.Concat(Shared.Common.Config.Instance.Account, RemoteOperatorConsts.CAP_NUMBER, md5Password); |
| | | |
| | | //(2)将(1)转成Base64字符串,生成格式[Base64(用户名:密码)] |
| | | var userNameAndPwdStrBaseSexFour = Convert.ToBase64String(ZigBee.Common.CommonInfo.EncodingUTF8.GetBytes(userNameAndPwdStr)); |
| | | |
| | | //(3)将(2)继续生成格式[Base64(用户名:密码):Timestamp] |
| | | var userNameAndPwdStrBaseSexFourAndTimestamp = string.Concat(userNameAndPwdStrBaseSexFour, RemoteOperatorConsts.CAP_NUMBER, CurrentTimeStamp.ToString()); |
| | | |
| | | ///[Zigbee.Buspro]App/id(帐号Id)/Base64(DES[Base64(用户名:密码):Timestamp ]/网关唯一Id/转发给网关的主题/XX/XX |
| | | //(4)生成上报主题,主题模式需要为 /ZigbeeApp/id(主子调试帐号Id)/Base64(DES[Base64(用户名:密码):Timestamp ]/网关唯一Id/topicName "000204022022" GateWayId 000204022022 |
| | | var reportTopic = string.Format("/{0}/{1}/{2}/{3}/{4}", RemoteOperatorConsts.ZIGBEE_APP_STARTS_WITH, Shared.Common.Config.Instance.Account, userNameAndPwdStrBaseSexFourAndTimestamp, this.getGatewayBaseInfo?.gwID, topicName); |
| | | |
| | | //(5)使用你登录成功时8位key,进行DES加密你需要上报的数据 |
| | | string topicEncStr = reportTopic; |
| | | //文件流不用加密 |
| | | topicEncStr = ZigBee.Common.SecuritySet.AesEncrypt(System.Text.Encoding.UTF8.GetBytes(topicEncStr), Shared.Common.Config.Instance.MqttKey); |
| | | topicEncStr = topicEncStr.Replace("/", "[[$-MQTT_TILT_SYMBOL_REPLACE-$]]").Replace("+", "[[$-MQTT_PLUS_SYMBOL_REPLACE-$]]"); |
| | | message = System.Text.Encoding.UTF8.GetBytes(SecuritySet.AesEncrypt(message, Shared.Common.Config.Instance.MqttKey)); |
| | | |
| | | //(6)构建Mqtt需要发布的数据包,发布给云端的MqttBroker |
| | | await RemoteMqttClient.PublishAsync(new MQTTnet.Core.MqttApplicationMessage(topicEncStr, message, qosLevel, retain)); |
| | | try
|
| | | {
|
| | | if (this.getGatewayBaseInfo?.gwID == null || !GateWayBaseInfomations.ContainsKey(this.getGatewayBaseInfo?.gwID))
|
| | | {
|
| | | return;
|
| | | }
|
| | | var gateWayBaseInfomation = GateWayBaseInfomations[this.getGatewayBaseInfo?.gwID];
|
| | | message = SecuritySet.AesEncryptBytes(message, gateWayBaseInfomation.AesKey);
|
| | | var topicEncStr = $"/ClientToZigbeeGateWay/{gateWayBaseInfomation.MacMark}/Common/{topicName}";
|
| | | //(6)构建Mqtt需要发布的数据包,发布给云端的MqttBroker
|
| | | if (remoteIsConnected)
|
| | | {
|
| | | try
|
| | | {
|
| | | await RemoteMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topicEncStr, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce });
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | await DisConnectRemoteMqttClient(e.Message);
|
| | | await StartRemoteMqtt();
|
| | | if (remoteIsConnected)
|
| | | {
|
| | | await RemoteMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topicEncStr, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce });
|
| | | }
|
| | | }
|
| | | } |
| | | }
|
| | | catch
|
| | | {
|
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <returns></returns> |
| | | /// <param name="topic"></param> |
| | | /// <param name="message"></param> |
| | | /// <param name="qosLevel"></param> |
| | | /// <param name="retain"></param> |
| | | public async System.Threading.Tasks.Task Send(string topic, byte[] message, MQTTnet.Core.Protocol.MqttQualityOfServiceLevel qosLevel = MQTTnet.Core.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, bool retain = false) |
| | | public async System.Threading.Tasks.Task Send(string topic, byte[] message, bool retain = false) |
| | | { |
| | | try |
| | | { |
| | | if (Shared.Common.Config.Instance.HomeId == "") |
| | | { |
| | | return; |
| | | } |
| | | |
| | | if (IsRemote) |
| | | { |
| | | #if DEBUG |
| | | DebugPrintLog($"远程 ——发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_当前网关{CurrentGateWayId}_{System.DateTime.Now.ToString()}"); |
| | | #endif |
| | | await SendRemoteMsg(topic, message, qosLevel, retain); |
| | | await SendRemoteMsg(topic, message, retain); |
| | | DebugPrintLog($"远程——发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_当前网关{CurrentGateWayId}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") |
| | | } |
| | | else |
| | | { |
| | | #if DEBUG |
| | | DebugPrintLog($"局域网——发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_当前网关{CurrentGateWayId}_{System.DateTime.Now.ToString()}"); |
| | | #endif |
| | | if (mqttClient == null || !mqttClient.IsConnected) |
| | | { |
| | | await StartLocalMqtt(getGatewayBaseInfo.IpAddress); |
| | | } |
| | | |
| | | DebugPrintLog($"局域网——发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_当前网关{CurrentGateWayId} 是否加密:{IsEncry}");
|
| | |
|
| | | if (IsEncry) |
| | | { |
| | | //文件流不用加密 |
| | | if (topic != "FileTransfer/SendFile") |
| | | { |
| | | topic = ZigBee.Common.SecuritySet.AesEncrypt(System.Text.Encoding.UTF8.GetBytes(topic), Password); |
| | | message = System.Text.Encoding.UTF8.GetBytes(SecuritySet.AesEncrypt(message, password)); |
| | | DebugPrintLog($"局域网——发送到网关的主题(秘文):{topic}_当前秘钥{Password}_发送到网关的数据(秘文):{System.Text.Encoding.UTF8.GetString(message)}_当前网关{CurrentGateWayId}_{System.DateTime.Now.ToString()}"); |
| | | |
| | | message = SecuritySet.AesEncryptBytes(message, password); |
| | | } |
| | | |
| | | await mqttClient.PublishAsync(new MQTTnet.Core.MqttApplicationMessage(topic, message, qosLevel, retain)); |
| | | } |
| | | else |
| | | { |
| | | await mqttClient.PublishAsync(new MQTTnet.Core.MqttApplicationMessage(topic, message, qosLevel, retain)); |
| | | } |
| | | }
|
| | | if (localIsConnected) |
| | | {
|
| | | try
|
| | | {
|
| | | await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
|
| | | }
|
| | | catch(Exception e)
|
| | | { |
| | | DebugPrintLog($"Local主动断开_{e.Message}");
|
| | | await DisConnectLocalMqttClient(e.Message); |
| | | await StartLocalMqtt("ReConnect");
|
| | | if (localIsConnected)
|
| | | {
|
| | | DebugPrintLog($"局域网——二次发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_当前网关{CurrentGateWayId} 是否加密:{IsEncry}");
|
| | | await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
|
| | | } |
| | | }
|
| | | }
|
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | #if DEBUG |
| | | DebugPrintLog($"Send:{ex.Message}"); |
| | | #endif |
| | | } |
| | | } |
| | | |
| | |
| | | /// <returns></returns> |
| | | /// <param name="topic"></param> |
| | | /// <param name="message"></param> |
| | | /// <param name="qosLevel"></param> |
| | | /// <param name="retain"></param> |
| | | public async System.Threading.Tasks.Task Send(string topic, string message, MQTTnet.Core.Protocol.MqttQualityOfServiceLevel qosLevel = MQTTnet.Core.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, bool retain = false) |
| | | public async System.Threading.Tasks.Task Send(string topic, string message, bool retain = false) |
| | | { |
| | | if(string.IsNullOrEmpty(message)){
|
| | | if (string.IsNullOrEmpty(message)) |
| | | {
|
| | | return; |
| | | } |
| | | await Send(topic, System.Text.Encoding.UTF8.GetBytes(message), qosLevel, retain); |
| | | await Send(topic, System.Text.Encoding.UTF8.GetBytes(message), retain); |
| | | }
|
| | |
|
| | | /// <summary> |
| | | /// 强制指定使用本地局域网发送消息到服务器 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | /// <param name="topic"></param> |
| | | /// <param name="message"></param> |
| | | /// <param name="retain"></param> |
| | | public async Task SendLocation(string topic, byte[] message, bool retain = false) |
| | | { |
| | | try |
| | | { |
| | | if (Shared.Common.Config.Instance.HomeId == "") |
| | | { |
| | | return; |
| | | }
|
| | |
|
| | | DebugPrintLog($"局域网——发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_当前网关{CurrentGateWayId} 是否加密:{IsEncry}");
|
| | |
|
| | | if (IsEncry)
|
| | | {
|
| | | //文件流不用加密
|
| | | if (topic != "FileTransfer/SendFile")
|
| | | {
|
| | | message = SecuritySet.AesEncryptBytes(message, password);
|
| | | }
|
| | | }
|
| | | if (localIsConnected)
|
| | | {
|
| | | try
|
| | | {
|
| | | await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | DebugPrintLog($"Local主动断开_{e.Message}");
|
| | | await DisConnectLocalMqttClient(e.Message);
|
| | | await StartLocalMqtt("ReConnect");
|
| | | if (localIsConnected)
|
| | | {
|
| | | DebugPrintLog($"局域网——二次发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_当前网关{CurrentGateWayId} 是否加密:{IsEncry}");
|
| | | await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
|
| | | }
|
| | | }
|
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | DebugPrintLog($"Send:{ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | |
| | | [Serializable] |
| | | public class CloudTimeResponse |
| | |
| | | /// </summary> |
| | | /// <param name="sender">Sender.</param> |
| | | /// <param name="e">E.</param> |
| | | static void mqttRemoteClient_MqttMsgPublishReceived(object sender, MqttApplicationMessageReceivedEventArgs e) |
| | | static void mqttRemoteClient_MqttMsgPublishReceived(MqttApplicationMessageReceivedEventArgs e) |
| | | { |
| | | try |
| | | { |
| | | var topic = e.ApplicationMessage.Topic.TrimStart('/'); |
| | | var payload = e.ApplicationMessage.Payload; |
| | | |
| | | var message = string.Empty; |
| | | //你当前的IP及端口在云端不存在,请重新登录连接下! |
| | | if (topic == "YouIpAndPortNoRecord") |
| | | { |
| | | message = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload); |
| | | } |
| | | //重新登录:帐号或者共享连接中的[子帐号分布式Id$Share$分布式住宅Id=XXX尚未登录,请重新登录后再连接后再进行发布操作,如果您当前是别人共享给你的连接,则请重新请求获取连接信息一下,再初始化连接再次发布远程控制即可!! |
| | | else if (topic == "AppNoLogin") |
| | | { |
| | | message = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload); |
| | | } |
| | | else |
| | | { |
| | | topic = topic.Replace("[[$-MQTT_TILT_SYMBOL_REPLACE-$]]", "/"); |
| | | topic = topic.Replace("[[$-MQTT_PLUS_SYMBOL_REPLACE-$]]", "+"); |
| | | topic = ZigBee.Common.SecuritySet.AesDecrypt(System.Text.Encoding.UTF8.GetBytes(topic), Shared.Common.Config.Instance.MqttKey).TrimStart('/'); ; |
| | | |
| | | if (!message.EndsWith("}")) |
| | | { |
| | | message = ZigBee.Common.SecuritySet.AesDecrypt(e.ApplicationMessage.Payload, Shared.Common.Config.Instance.MqttKey); |
| | | } |
| | | } |
| | | #if DEBUG |
| | | DebugPrintLog($"远程返回的主题:{ topic}_远程返回的数据_{message}_{System.DateTime.Now.ToString()}"); |
| | | #endif |
| | | var cloudMqttResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Common.CloudMqttResponsePack>(message); |
| | | if (cloudMqttResult != null) |
| | | var topics = topic.Split("/"); |
| | | if (topics.Length < 3) |
| | | { |
| | | if (topic == "AppConnectMqttBrokerSuccess") |
| | | return; |
| | | } |
| | | if (topics[0] != "ZigbeeGateWayToClient") |
| | | { |
| | | return; |
| | | } |
| | | if (topics[2]== "NotifyGateWayInfoChange") { |
| | | initGateWayBaseInfomation(); |
| | | return; |
| | | } |
| | | if (topics[2] == "Common") |
| | | { |
| | | var macMark = topics[1]; |
| | | topic = topic.Substring(topics[0].Length + topics[1].Length + topics[2].Length + 3); |
| | | if (payload[0] == (byte)'{' && payload[payload.Length - 1] == (byte)'}') |
| | | { |
| | | RemoteTimeStamp = ulong.Parse(cloudMqttResult.CloudTimestamp); |
| | | LoginRemoteDateTime = System.DateTime.Now; |
| | | #if DEBUG |
| | | DebugPrintLog($"远程返回主题:{topic}_当前时间戳:_+{CurrentTimeStamp} + _+ {System.DateTime.Now.ToString()}"); |
| | | #endif |
| | | return; |
| | | message = System.Text.Encoding.UTF8.GetString(payload); |
| | | } |
| | | else |
| | | { |
| | | switch (cloudMqttResult.StateCode) |
| | | foreach (var key in GateWayBaseInfomations.Keys) |
| | | { |
| | | case "GatewayIdNoIsYou": |
| | | message = cloudMqttResult.StateCode + ":" + cloudMqttResult.Info; |
| | | #if DEBUG |
| | | DebugPrintLog($"远程返回返回的提示内容:{message}_当前时间戳:_+{CurrentTimeStamp} + _+ {System.DateTime.Now.ToString()}"); |
| | | #endif |
| | | return; |
| | | case "AppTimeOut": |
| | | RemoteTimeStamp = ulong.Parse(cloudMqttResult.CloudTimestamp); |
| | | LoginRemoteDateTime = System.DateTime.Now; |
| | | message = cloudMqttResult.StateCode + ":" + cloudMqttResult.Info; |
| | | #if DEBUG |
| | | DebugPrintLog($"远程返回返回的提示内容:{message}_当前时间戳:_+{CurrentTimeStamp} + _+ {System.DateTime.Now.ToString()}"); |
| | | #endif |
| | | return; |
| | | case "AppReportSuccess": |
| | | RemoteTimeStamp = ulong.Parse(cloudMqttResult.CloudTimestamp); |
| | | LoginRemoteDateTime = System.DateTime.Now; |
| | | message = cloudMqttResult.StateCode + ":" + cloudMqttResult.Info; |
| | | #if DEBUG |
| | | DebugPrintLog($"远程返回返回的提示内容:{message}_当前时间戳:_+{CurrentTimeStamp} + _+ {System.DateTime.Now.ToString()}"); |
| | | #endif |
| | | return; |
| | | case "ForwardGatewayNoOnLine": |
| | | message = cloudMqttResult.StateCode + ":" + cloudMqttResult.Info; |
| | | #if DEBUG |
| | | DebugPrintLog($"远程返回返回的提示内容:{message}_当前时间戳:_+{CurrentTimeStamp} + _+ {System.DateTime.Now.ToString()}"); |
| | | #endif |
| | | return; |
| | | var value = GateWayBaseInfomations[key]; |
| | | if (value.MacMark == macMark) |
| | | { |
| | | topic = $"{key}/{topic}"; |
| | | message = System.Text.Encoding.UTF8.GetString(ZigBee.Common.SecuritySet.AesDecryptBytes(e.ApplicationMessage.Payload, value.AesKey)); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | ReceiveMessage(topic, message, e); |
| | | DebugPrintLog($"远程返回的主题:{ topic}_远程返回的数据_{message}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") |
| | | |
| | | ReceiveMessage(topic, message, payload); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | #if DEBUG |
| | | DebugPrintLog($"接收云端数据异常:{ex.Message}"); |
| | | #endif |
| | | DebugPrintLog($"接收云端数据异常:{ex.Message} "); |
| | | } |
| | | } |
| | | |
| | |
| | | /// </summary> |
| | | /// <param name="sender">Sender.</param> |
| | | /// <param name="e">E.</param> |
| | | void mqttClient_MqttMsgPublishReceived(object sender, MqttApplicationMessageReceivedEventArgs e) |
| | | void mqttClient_MqttMsgPublishReceived(MqttApplicationMessageReceivedEventArgs e) |
| | | { |
| | | try |
| | | { |
| | | var topic = e.ApplicationMessage.Topic; |
| | | var message = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload); |
| | | // DebugPrintLog($"网关返回的主题(秘文):{topic}_网关返回的负载(秘文):{message}_{System.DateTime.Now.ToString()}"); |
| | | string payloadString = ""; |
| | | |
| | | if (IsEncry) |
| | | { |
| | | //主题 |
| | | topic = Common.SecuritySet.AesDecrypt(System.Text.Encoding.UTF8.GetBytes(topic), Password); |
| | | //下载的字节流不需要解密 |
| | | if (topic.Split('/')[0] + "/" + topic.Split('/')[1] == topic.Split('/')[0] + "/" + "FileTransfer") |
| | | { |
| | | if (topic.Split('/')[2] != "DownloadFile") |
| | | { |
| | | message = Common.SecuritySet.AesDecrypt(e.ApplicationMessage.Payload, Password); |
| | | payloadString = System.Text.Encoding.UTF8.GetString(Common.SecuritySet.AesDecryptBytes(e.ApplicationMessage.Payload, Password)); |
| | | } |
| | | } |
| | | else if (topic == topic.Split('/')[0] + "/" + "SendAESKey_Respon") { }//回复主题是秘文,数据是明文 |
| | | else |
| | | { |
| | | message = Common.SecuritySet.AesDecrypt(e.ApplicationMessage.Payload, Password); |
| | | payloadString = System.Text.Encoding.UTF8.GetString(Common.SecuritySet.AesDecryptBytes(e.ApplicationMessage.Payload, Password)); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | topic = e.ApplicationMessage.Topic; |
| | | else
|
| | | {
|
| | | payloadString = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
|
| | | } |
| | | #if DEBUG |
| | | DebugPrintLog($"网关返回的主题:{topic}_网关返回的负载:{message}_{System.DateTime.Now.ToString()}"); |
| | | #endif |
| | | ReceiveMessage(topic, message, e); |
| | | DebugPrintLog($"网关返回的主题:{topic}_网关返回的负载:{payloadString}"); |
| | | ReceiveMessage(topic, payloadString, e.ApplicationMessage.Payload); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | #if DEBUG |
| | | DebugPrintLog($"接收网关数据异常:{ex.Message}"); |
| | | #endif |
| | | } |
| | | } |
| | | |
| | |
| | | /// <param name="topic">Topic.</param> |
| | | /// <param name="message">Message.</param> |
| | | /// <param name="e">E.</param> |
| | | static void ReceiveMessage(string topic, string message, MqttApplicationMessageReceivedEventArgs e) |
| | | static void ReceiveMessage(string topic, string message, byte []payload) |
| | | { |
| | | try |
| | | { |
| | | if(string .IsNullOrEmpty(message)) |
| | | if (string.IsNullOrEmpty(message)) |
| | | { |
| | | return; |
| | | message = "{}"; |
| | | } |
| | | var gatewayID = topic.Split('/')[0];//网关返回的网关ID |
| | | var reportStatus = topic.Split('/')[1];//主题为设备上报的主题 |
| | | var reportStatus = ""; |
| | | reportStatus = topic.Split('/')[1];//主题为设备上报的主题 |
| | | string addr = "";//上报的设备addr |
| | | string epoint = "";//上报的设备epoint |
| | | string cluID = "";//上报的设备cluID |
| | |
| | | epoint = topic.Split('/')[3]; |
| | | cluID = topic.Split('/')[4]; |
| | | attrId = topic.Split('/')[5]; |
| | | } |
| | | }
|
| | |
|
| | | //全局接收网关推送的的逻辑(为了执行速度,尽可能的别加耗时的操作)
|
| | | Shared.Phone.UserCenter.HdlGatewayReceiveLogic.Current.GatewayOverallMsgReceive(gatewayID, topic, reportStatus, message); |
| | | |
| | | var gwa = ZigBee.Device.ZbGateway.GateWayList.Find(obj => obj.getGatewayBaseInfo.gwID == gatewayID); |
| | | var gwa = GateWayList.Find(obj => obj.getGatewayBaseInfo.gwID == gatewayID); |
| | | if (gwa == null) |
| | | { |
| | | return; |
| | |
| | | gwa?.Actions(topic, message); |
| | | } |
| | | |
| | | if (gwa.GwResDataAction != null) |
| | | { |
| | | gwa.GwResDataAction(topic, message); |
| | | } |
| | | gwa.GwResDataAction?.Invoke(topic, message); |
| | | gwa.CurrentGateWayId = gatewayID; |
| | | |
| | | Newtonsoft.Json.Linq.JObject jobject = new Newtonsoft.Json.Linq.JObject(); |
| | | var jobject = new Newtonsoft.Json.Linq.JObject(); |
| | | if (topic.Split('/')[0] + "/" + topic.Split('/')[1] == topic.Split('/')[0] + "/" + "FileTransfer") |
| | | { |
| | | if (topic.Split('/')[2] == "DownloadFile") |
| | | { |
| | | gwa.DownloadFileConfirmAsync(e.ApplicationMessage.Payload); |
| | | message = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload); |
| | | if (gwa.FileContentAction != null) |
| | | { |
| | | gwa.FileContentAction(topic, e.ApplicationMessage.Payload); |
| | | } |
| | | DebugPrintLog($"网关返回数据流_{message}_{System.DateTime.Now.ToString()}"); |
| | | gwa.DownloadFileConfirmAsync(payload); |
| | | message = System.Text.Encoding.UTF8.GetString(payload); |
| | | gwa.FileContentAction?.Invoke(topic, payload); |
| | | DebugPrintLog($"网关返回数据流_{message}"); |
| | | return; |
| | | } |
| | | } |
| | |
| | | jobject = Newtonsoft.Json.Linq.JObject.Parse(message); |
| | | }
|
| | |
|
| | | #region 云端通知 |
| | | var cloudMqttResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Common.CloudMqttResponsePack>(message); |
| | | if (cloudMqttResult != null) |
| | | { |
| | | switch (cloudMqttResult.StateCode) |
| | | { |
| | | case "AppNoLogin": |
| | | if (gwa.CloudErrorAction != null) |
| | | { |
| | | DebugPrintLog("AppNoLogin已经通知"); |
| | | gwa.CloudErrorAction("AppNoLogin", "登录过期,请重新登录"); |
| | | } |
| | | break; |
| | | case "AppTimeOut": |
| | | if (gwa.CloudErrorAction != null) |
| | | { |
| | | DebugPrintLog("AppTimeOut已经通知"); |
| | | gwa.CloudErrorAction("AppTimeOut", "从云端获取数据超时,请重新获取"); |
| | | } |
| | | break; |
| | | case "ForwardGatewayNoOnLine": |
| | | if (gwa.CloudErrorAction != null) |
| | | { |
| | | DebugPrintLog("ForwardGatewayNoOnLine已经通知"); |
| | | gwa.CloudErrorAction("ForwardGatewayNoOnLine", "当前操作的网关不在线"); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | #endregion |
| | | #region 远程,主网关上报通知 |
| | | if(IsRemote) |
| | | if (IsRemote) |
| | | { |
| | | if (topic == gatewayID + "/" + "BeMainGw_Report") |
| | | { |
| | |
| | | if (gwData != null) |
| | | { |
| | | var gwList = GateWayList.FindAll(obj => obj.getGatewayBaseInfo.HomeId == Shared.Common.Config.Instance.HomeId); |
| | | |
| | | for (int i = 0; i < gwList.Count; i++) |
| | | { |
| | | var gwTemp = gwList[i]; |
| | | if (gwData.IsDominant == 1) |
| | | { |
| | | gwTemp.getGatewayBaseInfo.IsMainGateWay = true; |
| | | for (int j = i + 1; j < gwList.Count; j++) |
| | | { |
| | | gwList[j].getGatewayBaseInfo.IsMainGateWay = false; |
| | | } |
| | | if (gwList[i].getGatewayBaseInfo.gwID == gatewayID)
|
| | | {
|
| | | gwList[i].getGatewayBaseInfo.IsMainGateWay = true;
|
| | | } |
| | | else
|
| | | {
|
| | | gwList[i].getGatewayBaseInfo.IsMainGateWay = false;
|
| | | } |
| | | } |
| | | } |
| | |
| | | if (topic == gatewayID + "/" + "DeviceInComingRespon") |
| | | { |
| | | //新设备上报,重新发获取所有的设备 |
| | | var deviceID = jobject.Value<int>("Device_ID"); |
| | | switch ((DeviceType)(deviceID)) |
| | | { |
| | | case DeviceType.DimmableLight: |
| | | var dimmableLight = new DimmableLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | dimmableLight.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight.NewDeviceInfoData>(jobject["Data"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("DeviceInComingRespon已经通知"); |
| | | gwa.ReportAction("DeviceInComingRespon", dimmableLight.getNewDeviceInfo); |
| | | } |
| | | UpdateDeviceInfo(dimmableLight, "DeviceInComingRespon"); |
| | | UpdateDeviceStatus(gwa); |
| | | break; |
| | | case DeviceType.OnOffOutput: |
| | | var toggleLight = new ToggleLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | toggleLight.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight.NewDeviceInfoData>(jobject["Data"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("DeviceInComingRespon已经通知"); |
| | | gwa.ReportAction("DeviceInComingRespon", toggleLight.getNewDeviceInfo); |
| | | } |
| | | UpdateDeviceInfo(toggleLight, "DeviceInComingRespon"); |
| | | UpdateDeviceStatus(gwa); |
| | | break; |
| | | case DeviceType.AirSwitch: |
| | | var airSwitch = new AirSwitch() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | airSwitch.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch.NewDeviceInfoData>(jobject["Data"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("DeviceInComingRespon已经通知"); |
| | | gwa.ReportAction("DeviceInComingRespon", airSwitch.getNewDeviceInfo); |
| | | } |
| | | UpdateDeviceInfo(airSwitch, "DeviceInComingRespon"); |
| | | UpdateDeviceStatus(gwa); |
| | | break; |
| | | case DeviceType.OnOffSwitch: |
| | | var panel = new Panel() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | panel.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.NewDeviceInfoData>(jobject["Data"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("DeviceInComingRespon已经通知"); |
| | | gwa.ReportAction("DeviceInComingRespon", panel.getNewDeviceInfo); |
| | | } |
| | | UpdateDeviceInfo(panel, "DeviceInComingRespon"); |
| | | UpdateDeviceStatus(gwa); |
| | | break; |
| | | case DeviceType.WindowCoveringDevice: |
| | | var curtain = new Rollershade() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | curtain.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade.NewDeviceInfoData>(jobject["Data"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("DeviceInComingRespon已经通知"); |
| | | gwa.ReportAction("DeviceInComingRespon", curtain.getNewDeviceInfo); |
| | | } |
| | | UpdateDeviceInfo(curtain, "DeviceInComingRespon"); |
| | | UpdateDeviceStatus(gwa); |
| | | break; |
| | | case DeviceType.IASZone: |
| | | var ias = new IASZone() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | ias.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.NewDeviceInfoData>(jobject["Data"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("DeviceInComingRespon已经通知"); |
| | | gwa.ReportAction("DeviceInComingRespon", ias.getNewDeviceInfo); |
| | | } |
| | | UpdateDeviceInfo(ias, "DeviceInComingRespon"); |
| | | UpdateDeviceStatus(gwa); |
| | | break; |
| | | case DeviceType.Repeater: |
| | | var repeater = new Repeater() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | repeater.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Repeater.NewDeviceInfoData>(jobject["Data"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("DeviceInComingRespon已经通知"); |
| | | gwa.ReportAction("DeviceInComingRespon", repeater.getNewDeviceInfo); |
| | | } |
| | | UpdateDeviceInfo(repeater, "DeviceInComingRespon"); |
| | | UpdateDeviceStatus(gwa); |
| | | break; |
| | | case DeviceType.Thermostat: |
| | | var ac = new AC() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | ac.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<AC.NewDeviceInfoData>(jobject["Data"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("DeviceInComingRespon已经通知"); |
| | | gwa.ReportAction("DeviceInComingRespon", ac.getNewDeviceInfo); |
| | | } |
| | | UpdateDeviceInfo(ac, "DeviceInComingRespon"); |
| | | UpdateDeviceStatus(gwa); |
| | | break; |
| | | case DeviceType.Transverter : |
| | | var transverter = new Transverter() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | transverter.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Transverter.NewDeviceInfoData>(jobject["Data"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("DeviceInComingRespon已经通知"); |
| | | gwa.ReportAction("DeviceInComingRespon", transverter.getNewDeviceInfo); |
| | | } |
| | | UpdateDeviceInfo(transverter, "DeviceInComingRespon"); |
| | | UpdateDeviceStatus(gwa); |
| | | break; |
| | | } |
| | | var tempDevice = new CommonDevice() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | tempDevice.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.NewDeviceInfoData>(jobject["Data"].ToString()); |
| | | if (gwa.ReportAction != null)
|
| | | {
|
| | | DebugPrintLog("DeviceInComingRespon已经通知");
|
| | | gwa.ReportAction("DeviceInComingRespon", tempDevice.getNewDeviceInfo);
|
| | | }
|
| | | UpdateDeviceInfo(tempDevice, "DeviceInComingRespon");
|
| | | UpdateDeviceStatus(gwa); |
| | | } |
| | | #endregion |
| | | #region 设备在线状态更新反馈 |
| | | else if (topic == gatewayID + "/" + "OnlineStatusChange_Respon") |
| | | { |
| | | var deviceID = jobject.Value<int>("Device_ID"); |
| | | switch ((DeviceType)(deviceID)) |
| | | { |
| | | case DeviceType.DimmableLight: |
| | | var dimmableLight = new DimmableLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | dimmableLight.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString()); |
| | | |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("OnlineStatusChange已经通知"); |
| | | gwa.ReportAction("OnlineStatusChange", dimmableLight); |
| | | } |
| | | var lightDimmer = gwa.DeviceList.Find(obj => obj.DeviceID == dimmableLight.DeviceID && obj.DeviceAddr == dimmableLight.DeviceAddr); |
| | | if (lightDimmer == null) |
| | | { |
| | | gwa.DeviceList.Add(dimmableLight); |
| | | UpdateDeviceStatus(dimmableLight); |
| | | UpdateDeviceInfo(dimmableLight, "OnlineStatusChange"); |
| | | } |
| | | else |
| | | { |
| | | if (dimmableLight.DeviceInfo != null) |
| | | { |
| | | dimmableLight.DeviceInfo.IsOnline = dimmableLight.IsOnline; |
| | | } |
| | | UpdateDeviceInfo(dimmableLight, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(dimmableLight); |
| | | } |
| | | |
| | | break; |
| | | case DeviceType.OnOffOutput: |
| | | var toggleLight = new ToggleLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | toggleLight.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("OnlineStatusChange已经通知"); |
| | | gwa.ReportAction("OnlineStatusChange", toggleLight); |
| | | } |
| | | var toggleInfo = gwa.DeviceList.Find(obj => obj.DeviceID == toggleLight.DeviceID && obj.DeviceAddr == toggleLight.DeviceAddr); |
| | | if (toggleInfo == null) |
| | | { |
| | | gwa.DeviceList.Add(toggleLight); |
| | | UpdateDeviceInfo(toggleLight, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(toggleLight); |
| | | } |
| | | else |
| | | { |
| | | if (toggleLight.DeviceInfo != null) |
| | | { |
| | | toggleLight.DeviceInfo.IsOnline = toggleLight.IsOnline; |
| | | } |
| | | UpdateDeviceInfo(toggleLight, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(toggleLight); |
| | | } |
| | | break; |
| | | case DeviceType.AirSwitch: |
| | | var airSwitch = new AirSwitch() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | airSwitch.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("OnlineStatusChange已经通知"); |
| | | gwa.ReportAction("OnlineStatusChange", airSwitch); |
| | | } |
| | | var airSwitchInfo = gwa.DeviceList.Find(obj => obj.DeviceID == airSwitch.DeviceID && obj.DeviceAddr == airSwitch.DeviceAddr); |
| | | if (airSwitchInfo == null) |
| | | { |
| | | gwa.DeviceList.Add(airSwitch); |
| | | UpdateDeviceInfo(airSwitch, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(gwa); |
| | | } |
| | | else |
| | | { |
| | | if (airSwitchInfo.DeviceInfo != null) |
| | | { |
| | | airSwitchInfo.DeviceInfo.IsOnline = airSwitchInfo.IsOnline; |
| | | } |
| | | UpdateDeviceInfo(airSwitchInfo, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(airSwitchInfo); |
| | | } |
| | | break; |
| | | case DeviceType.OnOffSwitch: |
| | | var panel = new Panel() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | panel.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("OnlineStatusChange已经通知"); |
| | | gwa.ReportAction("OnlineStatusChange", panel); |
| | | } |
| | | var panelInfo = gwa.DeviceList.Find(obj => obj.DeviceID == panel.DeviceID && obj.DeviceAddr == panel.DeviceAddr); |
| | | if (panelInfo == null) |
| | | { |
| | | gwa.DeviceList.Add(panel); |
| | | UpdateDeviceInfo(panel, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(panel); |
| | | } |
| | | else |
| | | { |
| | | if (panelInfo.DeviceInfo != null) |
| | | { |
| | | panelInfo.DeviceInfo.IsOnline = panelInfo.IsOnline; |
| | | } |
| | | UpdateDeviceInfo(panelInfo, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(panelInfo); |
| | | } |
| | | break; |
| | | case DeviceType.WindowCoveringDevice: |
| | | var curtain = new Rollershade() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | curtain.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("OnlineStatusChange已经通知"); |
| | | gwa.ReportAction("OnlineStatusChange", curtain); |
| | | } |
| | | var curtainInfo = gwa.DeviceList.Find(obj => obj.DeviceID == curtain.DeviceID && obj.DeviceAddr == curtain.DeviceAddr); |
| | | if (curtainInfo == null) |
| | | { |
| | | gwa.DeviceList.Add(curtain); |
| | | UpdateDeviceInfo(curtain, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(gwa); |
| | | } |
| | | else |
| | | { |
| | | if (curtain.DeviceInfo != null) |
| | | { |
| | | curtain.DeviceInfo.IsOnline = curtain.IsOnline; |
| | | } |
| | | UpdateDeviceStatus(curtain); |
| | | UpdateDeviceInfo(curtain, "OnlineStatusChange"); |
| | | } |
| | | break; |
| | | case DeviceType.IASZone: |
| | | var ias = new IASZone() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | ias.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("OnlineStatusChange已经通知"); |
| | | gwa.ReportAction("OnlineStatusChange", ias); |
| | | } |
| | | var iasInfo = gwa.DeviceList.Find(obj => obj.DeviceID == ias.DeviceID && obj.DeviceAddr == ias.DeviceAddr); |
| | | if (iasInfo == null) |
| | | { |
| | | gwa.DeviceList.Add(iasInfo); |
| | | UpdateDeviceInfo(iasInfo, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(gwa); |
| | | } |
| | | else |
| | | { |
| | | if (iasInfo.DeviceInfo != null) |
| | | { |
| | | iasInfo.DeviceInfo.IsOnline = iasInfo.IsOnline; |
| | | } |
| | | UpdateDeviceInfo(iasInfo, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(iasInfo); |
| | | } |
| | | break; |
| | | case DeviceType.Repeater: |
| | | var repeater = new Repeater() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | repeater.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("OnlineStatusChange已经通知"); |
| | | gwa.ReportAction("OnlineStatusChange", repeater); |
| | | } |
| | | var repeaterInfo = gwa.DeviceList.Find(obj => obj.DeviceID == repeater.DeviceID && obj.DeviceAddr == repeater.DeviceAddr); |
| | | if (repeaterInfo == null) |
| | | { |
| | | gwa.DeviceList.Add(repeaterInfo); |
| | | UpdateDeviceInfo(repeaterInfo, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(gwa); |
| | | } |
| | | else |
| | | { |
| | | if (repeaterInfo.DeviceInfo != null) |
| | | { |
| | | repeaterInfo.DeviceInfo.IsOnline = repeaterInfo.IsOnline; |
| | | } |
| | | UpdateDeviceInfo(repeaterInfo, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(repeaterInfo); |
| | | } |
| | | break; |
| | | case DeviceType.Thermostat: |
| | | var ac = new AC() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | ac.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("OnlineStatusChange已经通知"); |
| | | gwa.ReportAction("OnlineStatusChange", ac); |
| | | } |
| | | var acInfo = gwa.DeviceList.Find(obj => obj.DeviceID == ac.DeviceID && obj.DeviceAddr == ac.DeviceAddr); |
| | | if (acInfo == null) |
| | | { |
| | | gwa.DeviceList.Add(acInfo); |
| | | UpdateDeviceInfo(acInfo, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(gwa); |
| | | } |
| | | else |
| | | { |
| | | if (acInfo.DeviceInfo != null) |
| | | { |
| | | acInfo.DeviceInfo.IsOnline = acInfo.IsOnline; |
| | | } |
| | | UpdateDeviceInfo(acInfo, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(acInfo); |
| | | } |
| | | break; |
| | | case DeviceType.Transverter: |
| | | var transverter = new Transverter() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | transverter.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("OnlineStatusChange已经通知"); |
| | | gwa.ReportAction("OnlineStatusChange", transverter); |
| | | } |
| | | var transverterInfo = gwa.DeviceList.Find(obj => obj.DeviceID == transverter.DeviceID && obj.DeviceAddr == transverter.DeviceAddr); |
| | | if (transverterInfo == null) |
| | | { |
| | | gwa.DeviceList.Add(transverterInfo); |
| | | UpdateDeviceInfo(transverterInfo, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(gwa); |
| | | } |
| | | else |
| | | { |
| | | if (transverterInfo.DeviceInfo != null) |
| | | { |
| | | transverterInfo.DeviceInfo.IsOnline = transverterInfo.IsOnline; |
| | | } |
| | | UpdateDeviceInfo(transverterInfo, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(transverterInfo); |
| | | } |
| | | break; |
| | | var tempDevice = new CommonDevice() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
|
| | | tempDevice.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString());
|
| | |
|
| | | if (gwa.ReportAction != null)
|
| | | {
|
| | | DebugPrintLog("OnlineStatusChange已经通知");
|
| | | gwa.ReportAction("OnlineStatusChange", tempDevice);
|
| | | }
|
| | | var infoTempDevice = gwa.DeviceList.Find(obj => obj.DeviceID == tempDevice.DeviceID && obj.DeviceAddr == tempDevice.DeviceAddr);
|
| | | if (infoTempDevice == null)
|
| | | {
|
| | | gwa.DeviceList.Add(tempDevice);
|
| | | UpdateDeviceStatus(tempDevice);
|
| | | UpdateDeviceInfo(tempDevice, "OnlineStatusChange");
|
| | | }
|
| | | else
|
| | | {
|
| | | if (infoTempDevice.DeviceInfo != null)
|
| | | {
|
| | | infoTempDevice.DeviceInfo.IsOnline = infoTempDevice.IsOnline;
|
| | | }
|
| | | UpdateDeviceInfo(infoTempDevice, "OnlineStatusChange");
|
| | | UpdateDeviceStatus(infoTempDevice);
|
| | | } |
| | | } |
| | | #endregion |
| | |
| | | { |
| | | foreach (var delD in gatewayTemp.removeDeviceResponseData.DeviceList) |
| | | { |
| | | var deviceID = delD.Device_ID; |
| | | switch ((DeviceType)(deviceID)) |
| | | { |
| | | case DeviceType.OnOffOutput: |
| | | var toggleLight = new ToggleLight() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | toggleLight.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (toggleLight.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | UpdateDeviceStatus(toggleLight); |
| | | UpdateDeviceInfo(toggleLight, "RemoveDeviceRespon"); |
| | | if (toggleLight.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var infoToggleLight = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == toggleLight.DeviceID && obj.DeviceAddr == toggleLight.DeviceAddr && obj.DeviceEpoint == toggleLight.DeviceEpoint); |
| | | if (infoToggleLight != null) |
| | | { |
| | | gwa.DeviceList.Remove(infoToggleLight); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.AirSwitch: |
| | | var airSwitch = new AirSwitch() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | airSwitch.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (airSwitch.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | UpdateDeviceStatus(airSwitch); |
| | | UpdateDeviceInfo(airSwitch, "RemoveDeviceRespon"); |
| | | if (airSwitch.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var infoAirSwitch = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == airSwitch.DeviceID && obj.DeviceAddr == airSwitch.DeviceAddr && obj.DeviceEpoint == airSwitch.DeviceEpoint); |
| | | if (infoAirSwitch != null) |
| | | { |
| | | gwa.DeviceList.Remove(infoAirSwitch); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.OnOffSwitch: |
| | | var panelObj = new Panel() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | panelObj.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (panelObj.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | UpdateDeviceStatus(panelObj); |
| | | UpdateDeviceInfo(panelObj, "RemoveDeviceRespon"); |
| | | if (panelObj.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var infoPanel = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == panelObj.DeviceID && obj.DeviceAddr == panelObj.DeviceAddr && obj.DeviceEpoint == panelObj.DeviceEpoint); |
| | | if (infoPanel != null) |
| | | { |
| | | gwa.DeviceList.Remove(infoPanel); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.WindowCoveringDevice: |
| | | var rollershade = new Rollershade() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | rollershade.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (rollershade.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | UpdateDeviceStatus(rollershade); |
| | | UpdateDeviceInfo(rollershade, "RemoveDeviceRespon"); |
| | | if (rollershade.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var infoRoller = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == rollershade.DeviceID && obj.DeviceAddr == rollershade.DeviceAddr && obj.DeviceEpoint == rollershade.DeviceEpoint); |
| | | if (infoRoller != null) |
| | | { |
| | | gwa.DeviceList.Remove(infoRoller); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.IASZone: |
| | | var ias = new IASZone() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | ias.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (ias.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | UpdateDeviceStatus(ias); |
| | | UpdateDeviceInfo(ias, "RemoveDeviceRespon"); |
| | | if (ias.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var info = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == ias.DeviceID && obj.DeviceAddr == ias.DeviceAddr && obj.DeviceEpoint == ias.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | gwa.DeviceList.Remove(info); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.DimmableLight: |
| | | var dimmableLight = new DimmableLight() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | dimmableLight.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (dimmableLight.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | UpdateDeviceStatus(dimmableLight); |
| | | UpdateDeviceInfo(dimmableLight, "RemoveDeviceRespon"); |
| | | if (dimmableLight.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var info = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == dimmableLight.DeviceID && obj.DeviceAddr == dimmableLight.DeviceAddr && obj.DeviceEpoint == dimmableLight.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | gwa.DeviceList.Remove(info); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.Repeater: |
| | | var repeater = new Repeater() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | repeater.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (repeater.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | UpdateDeviceStatus(repeater); |
| | | UpdateDeviceInfo(repeater, "RemoveDeviceRespon"); |
| | | if (repeater.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var info = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == repeater.DeviceID && obj.DeviceAddr == repeater.DeviceAddr && obj.DeviceEpoint == repeater.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | gwa.DeviceList.Remove(info); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.Thermostat: |
| | | var ac = new AC() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | ac.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<AC.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (ac.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | UpdateDeviceStatus(ac); |
| | | UpdateDeviceInfo(ac, "RemoveDeviceRespon"); |
| | | if (ac.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var info = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == ac.DeviceID && obj.DeviceAddr == ac.DeviceAddr && obj.DeviceEpoint == ac.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | gwa.DeviceList.Remove(info); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.Transverter: |
| | | var transverter = new Transverter() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | transverter.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<Transverter.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (transverter.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | UpdateDeviceStatus(transverter); |
| | | UpdateDeviceInfo(transverter, "RemoveDeviceRespon"); |
| | | if (transverter.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var info = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == transverter.DeviceID && obj.DeviceAddr == transverter.DeviceAddr && obj.DeviceEpoint == transverter.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | gwa.DeviceList.Remove(info); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | var tempDevice = new CommonDevice() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
|
| | | tempDevice.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.RemoveDeviceResponseData>(jobject["Data"].ToString());
|
| | | if (tempDevice.removeDeviceResponseData == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | else
|
| | | {
|
| | | UpdateDeviceStatus(tempDevice);
|
| | | UpdateDeviceInfo(tempDevice, "RemoveDeviceRespon");
|
| | | if (tempDevice.removeDeviceResponseData.Result == 0)
|
| | | {
|
| | | var infoTempDevice = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == tempDevice.DeviceID && obj.DeviceAddr == tempDevice.DeviceAddr && obj.DeviceEpoint == tempDevice.DeviceEpoint);
|
| | | if (infoTempDevice != null)
|
| | | {
|
| | | gwa.DeviceList.Remove(infoTempDevice);
|
| | | }
|
| | | }
|
| | | } |
| | | } |
| | | } |
| | |
| | | var tempEpoint = jobject.Value<int>("Epoint"); |
| | | var dataId = jobject.Value<int>("Data_ID"); |
| | | |
| | | var tempDevice = new CommonDevice { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
|
| | | tempDevice.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceStatusReportData>(jobject["Data"].ToString());
|
| | | UpdateDeviceStatus(tempDevice);
|
| | | UpdateDeviceInfo(tempDevice, "DeviceStatusReport"); |
| | | } |
| | | #endregion |
| | | #region 门锁操作事件通知 |
| | | else if (topic == gatewayID + "/" + "DoorLock/DoorLockOperatingEventNotificationCommand") |
| | | { |
| | | var deviceID = jobject.Value<int>("Device_ID"); |
| | | switch ((DeviceType)(deviceID)) |
| | | { |
| | | case DeviceType.DimmableLight: |
| | | var light = new DimmableLight { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId }; |
| | | light.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | UpdateDeviceStatus(light); |
| | | UpdateDeviceInfo(light, "DeviceStatusReport"); |
| | | case DeviceType.DoorLock: |
| | | var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | var OperatingEventNotificationDatad = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.DoorLock.DoorLockOperatingEventNotificationCommand>(jobject["Data"].ToString()); |
| | | if (OperatingEventNotificationDatad != null) |
| | | { |
| | | doorLock.doorLockOperatingEventNotificationCommand = OperatingEventNotificationDatad; |
| | | } |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("DoorLockProgrammingEventNotificationCommand已经通知"); |
| | | gwa.ReportAction("DoorLockProgrammingEventNotificationCommand", doorLock); |
| | | } |
| | | UpdateDeviceStatus(doorLock); |
| | | UpdateDeviceInfo(doorLock, "DoorLockProgrammingEventNotificationCommand"); |
| | | break; |
| | | case DeviceType.OnOffSwitch: |
| | | var lightSwitch = new Panel { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId }; |
| | | lightSwitch.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | UpdateDeviceStatus(lightSwitch); |
| | | UpdateDeviceInfo(lightSwitch, "DeviceStatusReport"); |
| | | break; |
| | | case DeviceType.OnOffOutput: |
| | | var lighttoggle = new ToggleLight { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId }; |
| | | lighttoggle.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | UpdateDeviceStatus(lighttoggle); |
| | | UpdateDeviceInfo(lighttoggle, "DeviceStatusReport"); |
| | | break; |
| | | case DeviceType.AirSwitch: |
| | | var airSwitch = new AirSwitch { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId }; |
| | | airSwitch.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | UpdateDeviceStatus(airSwitch); |
| | | UpdateDeviceInfo(airSwitch, "DeviceStatusReport"); |
| | | break; |
| | | case DeviceType.WindowCoveringDevice: |
| | | var curtain = new Rollershade { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId }; |
| | | curtain.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | UpdateDeviceStatus(curtain); |
| | | UpdateDeviceInfo(curtain, "DeviceStatusReport"); |
| | | break; |
| | | case DeviceType.OtaDevice: |
| | | case DeviceType.OtaPanelDevice: |
| | | var ota = new OTADevice { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId }; |
| | | ota.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<OTADevice.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | UpdateDeviceStatus(ota); |
| | | UpdateDeviceInfo(ota, "DeviceStatusReport"); |
| | | break; |
| | | case DeviceType.IASZone: |
| | | var ias = new IASZone { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId }; |
| | | ias.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | UpdateDeviceStatus(ias); |
| | | UpdateDeviceInfo(ias, "DeviceStatusReport"); |
| | | break; |
| | | case DeviceType.Repeater: |
| | | var repeater = new Repeater { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId }; |
| | | repeater.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<Repeater.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | UpdateDeviceStatus(repeater); |
| | | UpdateDeviceInfo(repeater, "DeviceStatusReport"); |
| | | break; |
| | | case DeviceType.Thermostat: |
| | | var ac = new AC { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId }; |
| | | ac.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<AC.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | UpdateDeviceStatus(ac); |
| | | UpdateDeviceInfo(ac, "DeviceStatusReport"); |
| | | break; |
| | | case DeviceType.Transverter : |
| | | var transverter = new Transverter { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId }; |
| | | transverter.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<AC.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | UpdateDeviceStatus(transverter); |
| | | UpdateDeviceInfo(transverter, "DeviceStatusReport"); |
| | | } |
| | | } |
| | | #endregion |
| | | #region 门锁编程事件通知 |
| | | else if (topic == gatewayID + "/" + "DoorLock/DoorLockProgrammingEventNotificationCommand") |
| | | { |
| | | var deviceID = jobject.Value<int>("Device_ID"); |
| | | switch ((DeviceType)(deviceID)) |
| | | { |
| | | case DeviceType.DoorLock: |
| | | var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | var ProgrammingEventNotificationData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.DoorLock.DoorLockProgrammingEventNotificationCommand>(jobject["Data"].ToString()); |
| | | if (ProgrammingEventNotificationData != null) |
| | | { |
| | | doorLock.doorLockProgrammingEventNotificationCommand = ProgrammingEventNotificationData; |
| | | } |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("DoorLockProgrammingEventNotificationCommand已经通知"); |
| | | gwa.ReportAction("DoorLockProgrammingEventNotificationCommand", doorLock); |
| | | } |
| | | UpdateDeviceStatus(doorLock); |
| | | UpdateDeviceInfo(doorLock, "DoorLockProgrammingEventNotificationCommand"); |
| | | break; |
| | | } |
| | | } |
| | |
| | | #region 设备请求APP获取升级数据 |
| | | else if (topic == gatewayID + "/" + "ZbDataPassthrough") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); |
| | | if (gatewayTemp.clientDataPassthroughResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | //上报类型通知 |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("DeviceRequestAcUpdateData"); |
| | | gwa.ReportAction("DeviceRequestAcUpdateData", gatewayTemp.clientDataPassthroughResponseData); |
| | | {
|
| | | var clientDataPassthrough = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
|
| | | if (clientDataPassthrough != null)
|
| | | {
|
| | | DebugPrintLog("DeviceRequestAcUpdateData");
|
| | | gwa.ReportAction("DeviceRequestAcUpdateData", clientDataPassthrough);
|
| | | } |
| | | } |
| | | } |
| | | #endregion |
| | | DebugPrintLog("网关返回数据通知"); |
| | | } |
| | | catch (Exception ex) |
| | | { |