黄学彪
2019-12-05 b3e96fce4cc01113128ddf8e0a18fc19594a9e56
ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
@@ -603,7 +603,8 @@
                    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 { }
@@ -3631,6 +3632,7 @@
                            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 });
                            }
                        }
@@ -3657,8 +3659,58 @@
                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