old mode 100644
new mode 100755
| | |
| | | |
| | | /// <summary> |
| | | /// 同步到远程的当前时间戳 |
| | | /// </summary> |
| | | /// </summary>Re |
| | | public static ulong CurrentTimeStamp |
| | | { |
| | | get |
| | |
| | | } |
| | | } |
| | | catch { } |
| | | finally{ |
| | | finally |
| | | { |
| | | Actions -= action; |
| | | } |
| | | DebugPrintLog("Security/ChangeAdminPassword_Actions 退出" + System.DateTime.Now.ToString()); |
| | |
| | | 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); |
| | | 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.Phone.UserCenter.HdlGatewayLogic.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.WIFI);
|
| | | System.Console.WriteLine($"当前是网关Wi-Fi在通讯_{System.DateTime.Now.ToString()}"); |
| | | |
| | | }; |
| | |
| | | { |
| | | try |
| | | { |
| | | if (remoteMqttIsConnecting) |
| | | if (remoteMqttIsConnecting || Shared.Common.Config.Instance.HomeId == "") |
| | | { |
| | | return; |
| | | } |
| | |
| | | var url = Shared.Common.Config.Instance.ZigbeeMqttBrokerLoadSubDomain;//.Replace("6688","6689"); |
| | | if (string.IsNullOrEmpty(url) || !url.StartsWith("tcp://") || url.Split(':').Length != 3) |
| | | { |
| | | remoteMqttIsConnecting = false; |
| | | return; |
| | | } |
| | | if (RemoteMqttClient == null) |
| | |
| | | #if DEBUG |
| | | DebugPrintLog($"远程连接成功_{System.DateTime.Now.ToString()}");
|
| | | #endif |
| | | Shared.Common.LocalGateway.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.Remote); |
| | | 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) |
| | |
| | | KeepAlivePeriod = new TimeSpan(0, 5, 0),//设置心跳时间(最大值,2^16-1 = 65535秒 = 18小时。最小值可以为0,表示客户端不断开。一般设为几分钟,比如微信心跳周期为300秒。) |
| | | DefaultCommunicationTimeout = new TimeSpan(0, 0, 100),//设置超时时间 |
| | | }; |
| | | //远程通讯连接,连接云端服务器 |
| | | await RemoteMqttClient.ConnectAsync(connectCloudMqttClientOptions); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | { |
| | | 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); |
| | | #if DEBUG |
| | | DebugPrintLog($"远程 ——发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_当前网关{CurrentGateWayId}_{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") |
| | | #endif |
| | | } |
| | | else |
| | | { |
| | |
| | | /// <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) |
| | | { |
| | | if(string.IsNullOrEmpty(message)){
|
| | | if (string.IsNullOrEmpty(message)) |
| | | {
|
| | | return; |
| | | } |
| | | await Send(topic, System.Text.Encoding.UTF8.GetBytes(message), qosLevel, retain); |
| | |
| | | { |
| | | message = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload); |
| | | } |
| | | else if (topic == "BeingSqueezedOffline") |
| | | { |
| | | //云端中的当前连接被挤下线,需要通知app |
| | | //全局接收网关推送的的逻辑(为了执行速度,尽可能的别加耗时的操作) |
| | | message = "BeingSqueezedOffline"; |
| | | Shared.Phone.UserCenter.HdlGatewayReceiveLogic.GatewayOverallMsgReceive("", topic, null);
|
| | | DebugPrintLog($"被挤下线通知:{ topic}_远程返回的数据_{message}_{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") |
| | | return; |
| | | } |
| | | //重新登录:帐号或者共享连接中的[子帐号分布式Id$Share$分布式住宅Id=XXX尚未登录,请重新登录后再连接后再进行发布操作,如果您当前是别人共享给你的连接,则请重新请求获取连接信息一下,再初始化连接再次发布远程控制即可!! |
| | | else if (topic == "AppNoLogin") |
| | | { |
| | |
| | | } |
| | | } |
| | | #if DEBUG |
| | | DebugPrintLog($"远程返回的主题:{ topic}_远程返回的数据_{message}_{System.DateTime.Now.ToString()}"); |
| | | DebugPrintLog($"远程返回的主题:{ topic}_远程返回的数据_{message}_{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") |
| | | #endif |
| | | var cloudMqttResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Common.CloudMqttResponsePack>(message); |
| | | if (cloudMqttResult != null) |
| | |
| | | RemoteTimeStamp = ulong.Parse(cloudMqttResult.CloudTimestamp); |
| | | LoginRemoteDateTime = System.DateTime.Now; |
| | | #if DEBUG |
| | | DebugPrintLog($"远程返回主题:{topic}_当前时间戳:_+{CurrentTimeStamp} + _+ {System.DateTime.Now.ToString()}"); |
| | | DebugPrintLog($"远程返回主题:{topic}_当前时间戳:_+{CurrentTimeStamp} + _+{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff" // {System.DateTime.Now.ToString()}"); |
| | | #endif |
| | | return; |
| | | } |
| | |
| | | { |
| | | var topic = e.ApplicationMessage.Topic; |
| | | var message = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload); |
| | | // DebugPrintLog($"网关返回的主题(秘文):{topic}_网关返回的负载(秘文):{message}_{System.DateTime.Now.ToString()}"); |
| | | |
| | | if (IsEncry) |
| | | { |
| | |
| | | { |
| | | 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 |
| | |
| | | if (gwa.GwResDataAction != null) |
| | | { |
| | | gwa.GwResDataAction(topic, message); |
| | | if (topic == $"{gatewayID}/DoorLock/DoorLockOperatingEventNotificationCommand") |
| | | { |
| | | Console.WriteLine($"111_DoorLockOperatingEventNotificationCommand:{message}"); |
| | | } |
| | | if (topic == $"{gatewayID}/DoorLock/DoorLockProgrammingEventNotificationCommand") |
| | | { |
| | | Console.WriteLine($"111_DoorLockProgrammingEventNotificationCommand:{message}"); |
| | | } |
| | | } |
| | | gwa.CurrentGateWayId = gatewayID; |
| | | |
| | |
| | | jobject = Newtonsoft.Json.Linq.JObject.Parse(message); |
| | | }
|
| | |
|
| | | //全局接收网关推送的的逻辑(为了执行速度,尽可能的别加耗时的操作)
|
| | | Shared.Phone.UserCenter.HdlGatewayReceiveLogic.GatewayOverallMsgReceive(gatewayID, topic, jobject);
|
| | |
|
| | | #region 云端通知 |
| | | var cloudMqttResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Common.CloudMqttResponsePack>(message); |
| | | if (cloudMqttResult != null) |
| | |
| | | DebugPrintLog("AppNoLogin已经通知"); |
| | | gwa.CloudErrorAction("AppNoLogin", "登录过期,请重新登录"); |
| | | } |
| | | //全局接收网关推送的的逻辑(为了执行速度,尽可能的别加耗时的操作)
|
| | | Shared.Phone.UserCenter.HdlGatewayReceiveLogic.GatewayOverallMsgReceive(gatewayID, "AppNoLogin", jobject); |
| | | break; |
| | | case "AppTimeOut": |
| | | if (gwa.CloudErrorAction != null) |
| | |
| | | gwa.ReportAction("DeviceInComingRespon", transverter.getNewDeviceInfo); |
| | | } |
| | | UpdateDeviceInfo(transverter, "DeviceInComingRespon"); |
| | | UpdateDeviceStatus(gwa); |
| | | break; |
| | | 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 }; |
| | | doorLock.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock.NewDeviceInfoData>(jobject["Data"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("DeviceInComingRespon已经通知"); |
| | | gwa.ReportAction("DeviceInComingRespon", doorLock.getNewDeviceInfo); |
| | | } |
| | | UpdateDeviceInfo(doorLock, "DeviceInComingRespon"); |
| | | UpdateDeviceStatus(gwa); |
| | | break; |
| | | } |
| | |
| | | UpdateDeviceStatus(transverterInfo); |
| | | } |
| | | break; |
| | | 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 }; |
| | | doorLock.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString()); |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("OnlineStatusChange已经通知"); |
| | | gwa.ReportAction("OnlineStatusChange", doorLock); |
| | | } |
| | | var doorLockInfo = gwa.DeviceList.Find(obj => obj.DeviceID == doorLock.DeviceID && obj.DeviceAddr == doorLock.DeviceAddr); |
| | | if (doorLockInfo == null) |
| | | { |
| | | gwa.DeviceList.Add(doorLockInfo); |
| | | UpdateDeviceInfo(doorLockInfo, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(gwa); |
| | | } |
| | | else |
| | | { |
| | | if (doorLockInfo.DeviceInfo != null) |
| | | { |
| | | doorLockInfo.DeviceInfo.IsOnline = doorLockInfo.IsOnline; |
| | | } |
| | | UpdateDeviceInfo(doorLockInfo, "OnlineStatusChange"); |
| | | UpdateDeviceStatus(doorLockInfo); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | #endregion |
| | |
| | | } |
| | | } |
| | | break; |
| | | case DeviceType.DoorLock: |
| | | var doorLock = new DoorLock() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | doorLock.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | if (doorLock.removeDeviceResponseData == null) |
| | | { |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | UpdateDeviceStatus(doorLock); |
| | | UpdateDeviceInfo(doorLock, "RemoveDeviceRespon"); |
| | | if (doorLock.removeDeviceResponseData.Result == 0) |
| | | { |
| | | var info = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == doorLock.DeviceID && obj.DeviceAddr == doorLock.DeviceAddr && obj.DeviceEpoint == doorLock.DeviceEpoint); |
| | | if (info != null) |
| | | { |
| | | gwa.DeviceList.Remove(info); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | |
| | | 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()); |
| | | transverter.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<Transverter.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | UpdateDeviceStatus(transverter); |
| | | UpdateDeviceInfo(transverter, "DeviceStatusReport"); |
| | | break; |
| | | case DeviceType.DoorLock: |
| | | var doorLock = new DoorLock { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId }; |
| | | doorLock.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock.DeviceStatusReportData>(jobject["Data"].ToString()); |
| | | UpdateDeviceStatus(doorLock); |
| | | UpdateDeviceInfo(doorLock, "DeviceStatusReport"); |
| | | break; |
| | | } |
| | | } |
| | | #endregion |