| | |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 82 } }; |
| | | 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 { } |
| | | |
| | |
| | | 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 });
|
| | | } |
| | | }
|
| | |
| | | return; |
| | | } |
| | | 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 |