JLChen
2020-01-15 454ac814944cf956ff02b84b70ba2ec68e5e5ea1
2020-01-15 1.优化MQTT连接。 2.增加本地通信加密。
2个文件已添加
14个文件已修改
448 ■■■■■ 已修改文件
Crabtree/.vs/SmartHome/xs/UserPrefs.xml 57 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/.vs/SmartHome/xs/sqlite3/storage.ide 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/.vs/SmartHome/xs/sqlite3/storage.ide-shm 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/.vs/SmartHome/xs/sqlite3/storage.ide-wal 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/ON/Properties/AndroidManifest.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/SmartHome/HDL/Operation/Packet.cs 27 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/SmartHome/HDL/Operation/ResponseEntity/ErrorCode.cs 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/SmartHome/HDL/Operation/UserConfig.cs 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/SmartHome/UI/SimpleControl/CommonPage.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/SmartHome/UI/SimpleControl/EquipmentPublicClass.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/SmartHome/UI/SimpleControl/MainPage.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs 176 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs 128 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/SmartHome/UI/SimpleControl/Phone/Register/AccountLogin.cs 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/SmartHome/UI/SimpleControl/Phone/Schedule/HelpView.cs 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/SmartHome/UI/SimpleControl/Phone/User/UserSettingView.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/.vs/SmartHome/xs/UserPrefs.xml
@@ -1,40 +1,52 @@
<Properties StartupConfiguration="{1D83BF28-BA88-4152-BA41-D7EFE90A5437}|Default">
  <MonoDevelop.Ide.ItemProperties.ON.Droid PreferredExecutionTarget="Android.Android_Accelerated_Oreo" />
  <MonoDevelop.Ide.Workbench ActiveDocument="SmartHome/HDL/Operation/UserInfo.cs">
<Properties StartupConfiguration="{9D9EF20B-6E65-4A65-92BF-567EBF1E1443}|Default">
  <MonoDevelop.Ide.ItemProperties.ON.Droid PreferredExecutionTarget="Android.4b65c46595" />
  <MonoDevelop.Ide.Workbench ActiveDocument="SmartHome/UI/SimpleControl/Phone/User/UserMiddle.cs">
    <Files>
      <File FileName="SmartHome/UI/SimpleControl/MainPage.cs" Line="362" Column="16" />
      <File FileName="SmartHome/HDL/Operation/ResponseEntity/SendJson.cs" />
      <File FileName="SmartHome/UI/SimpleControl/MqttCommon.cs" />
      <File FileName="SmartHome/HDL/Operation/Control.cs" Line="388" Column="38" />
      <File FileName="SmartHome/HDL/Operation/Target.cs" />
      <File FileName="SmartHome/HDL/Operation/UserConfig.cs" Line="299" Column="22" />
      <File FileName="SmartHome/HDL/Operation/BusSocket.cs" Line="167" Column="1" />
      <File FileName="SmartHome/HDL/Operation/Packet.cs" Line="145" Column="45" />
      <File FileName="SmartHome/HDL/Operation/MyEnum.cs" />
      <File FileName="SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs" />
      <File FileName="SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs" Line="281" Column="42" />
      <File FileName="SmartHome/UI/SimpleControl/CommonPage.cs" Line="55" Column="57" />
      <File FileName="SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs" Line="372" Column="19" />
      <File FileName="SmartHome/UI/SimpleControl/Phone/User/UserMiddle.cs" Line="406" Column="43" />
      <File FileName="SmartHome/HDL/Operation/UserInfo.cs" Line="1" Column="1" />
      <File FileName="SmartHome/HDL/Operation/ResponseEntity/SendJson.cs" Line="464" Column="8" />
      <File FileName="SmartHome/UI/SimpleControl/MainPage.cs" Line="43" Column="25" />
      <File FileName="SmartHome/UI/SimpleControl/MqttCommon.cs" Line="105" Column="16" />
      <File FileName="SmartHome/UI/SimpleControl/Phone/Room/UserRoom.cs" Line="2270" Column="76" />
      <File FileName="SmartHome/HDL/Operation/MyEnum.cs" Line="1214" Column="27" />
      <File FileName="SmartHome/UI/SimpleControl/CommonPage.cs" Line="453" Column="22" />
      <File FileName="SmartHome/UI/SimpleControl/Phone/Light/UserDeviceToLight.cs" Line="45" Column="56" />
      <File FileName="SmartHome/UI/SimpleControl/EquipmentPublicClass.cs" Line="120" Column="1" />
      <File FileName="SmartHome/UI/SimpleControl/Phone/Light/UserDeviceToSocket.cs" Line="44" Column="23" />
      <File FileName="SmartHome/HDL/Operation/Packet.cs" Line="69" Column="1" />
      <File FileName="SmartHome/HDL/Operation/Device/ButtonPanel.cs" Line="27" Column="9" />
      <File FileName="SmartHome/UI/SimpleControl/Phone/User/UserSettingView.cs" Line="482" Column="42" />
      <File FileName="SmartHome/UI/SimpleControl/Phone/Register/AccountLogin.cs" Line="12" Column="28" />
      <File FileName="SmartHome/UI/SimpleControl/Phone/Schedule/HelpView.cs" Line="35" Column="40" />
      <File FileName="SmartHome/HDL/Operation/ResponseEntity/ErrorCode.cs" Line="26" Column="47" />
      <File FileName="SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs" Line="1" Column="1" />
      <File FileName="SmartHome/UI/SimpleControl/Phone/Register/AccountView.cs" Line="80" Column="29" />
      <File FileName="SmartHome/UI/SimpleControl/Phone/User/UserMiddle.cs" Line="207" Column="21" />
    </Files>
    <Pads>
      <Pad Id="ProjectPad">
        <State name="__root__">
          <Node name="SmartHome" expanded="True">
            <Node name="ON.Droid" expanded="True" />
            <Node name="ON.Droid" expanded="True">
              <Node name="Properties" expanded="True" />
            </Node>
            <Node name="Shared" expanded="True">
              <Node name="HDL" expanded="True">
                <Node name="Operation" expanded="True">
                  <Node name="UserInfo.cs" selected="True" />
                  <Node name="Device" expanded="True" />
                  <Node name="ResponseEntity" expanded="True" />
                </Node>
              </Node>
              <Node name="UI" expanded="True">
                <Node name="SimpleControl" expanded="True">
                  <Node name="Phone" expanded="True">
                    <Node name="Guide" expanded="True" />
                    <Node name="Light" expanded="True" />
                    <Node name="Music" expanded="True" />
                    <Node name="Register" expanded="True" />
                    <Node name="User" expanded="True" />
                    <Node name="Room" expanded="True" />
                    <Node name="Schedule" expanded="True" />
                    <Node name="User" expanded="True">
                      <Node name="UserMiddle.cs" selected="True" />
                    </Node>
                  </Node>
                </Node>
              </Node>
@@ -55,7 +67,8 @@
  <MonoDevelop.Ide.ItemProperties.ON.Ios automaticSigning="False" PreferredExecutionTarget="MonoDevelop.IPhone.IPhoneDeviceTarget.254b82433419c7ca1850b1dfb524c79b7aeb0640" />
  <MonoDevelop.Ide.DebuggingService.Breakpoints>
    <BreakpointStore>
      <Breakpoint file="/Users/jlchen/JLChen/ProjectsCode/HDLGit/CrabtreeOn/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs" relfile="SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs" line="546" column="1" />
      <Breakpoint file="/Users/jlchen/JLChen/ProjectsCode/HDLGit/CrabtreeOn/Crabtree/SmartHome/UI/SimpleControl/Phone/Light/UserDeviceToLight.cs" relfile="SmartHome/UI/SimpleControl/Phone/Light/UserDeviceToLight.cs" line="69" column="1" />
      <Breakpoint file="/Users/jlchen/JLChen/ProjectsCode/HDLGit/CrabtreeOn/Crabtree/SmartHome/UI/SimpleControl/Phone/Light/UserDeviceToSocket.cs" relfile="SmartHome/UI/SimpleControl/Phone/Light/UserDeviceToSocket.cs" line="72" column="1" />
    </BreakpointStore>
  </MonoDevelop.Ide.DebuggingService.Breakpoints>
  <MultiItemStartupConfigurations />
Crabtree/.vs/SmartHome/xs/sqlite3/storage.ide
Binary files differ
Crabtree/.vs/SmartHome/xs/sqlite3/storage.ide-shm
Binary files differ
Crabtree/.vs/SmartHome/xs/sqlite3/storage.ide-wal
Binary files differ
Crabtree/ON/Properties/AndroidManifest.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hdl.crabtree" android:versionName="2.50114" android:versionCode="20200114">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hdl.crabtree" android:versionName="2.50115" android:versionCode="20200115">
    <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="26" />
    <!-- Required  一些系统要求的权限,此处是极光推送需求的权限,如访问网络等-->
    <permission android:name="com.hdl.on.permission.JPUSH_MESSAGE" android:protectionLevel="signature" />
Crabtree/SmartHome/HDL/Operation/Packet.cs
@@ -59,9 +59,6 @@
        {
            //加密检测
            EncryptionDetection ();
            //对于操作数据库的时间比较长的,可以创建另一个线程处理
            if (!"HDLMIRACLE".Equals (System.Text.Encoding.ASCII.GetString (Bytes, 4, 10))) {
                return;
@@ -69,7 +66,6 @@
            byte subnetID = this.Bytes [17]; //源子网号
            byte deviceID = this.Bytes [18]; //源设备号
            //源设备类型
            int deviceType = this.Bytes [19] * 256 + this.Bytes [20];
@@ -130,21 +126,26 @@
            if (IsLocal) {//本地通讯
               
                if (UserConfig.Instance.IsLocalEncrypt) {
                    if ("Passord error" == (System.Text.Encoding.ASCII.GetString (Bytes, 14, 13))) {
                        //网关返回,加密密码key不对
                        return;
                    if (Bytes.Length == 28) {
                        var mes = System.Text.Encoding.ASCII.GetString (Bytes, 14, 14);
                        if ("Password error" == mes) {
                            //网关返回,加密密码key不对
                            UserConfig.Instance.EncryptedPasswordCorrect = false;
                            return;
                        }
                    }
                    var messageGet = Shared.Securitys.EncryptionService.AesEncryptPayload (Bytes, UserConfig.Instance.LocalEncryptKey);
                    var messageGet = Shared.Securitys.EncryptionService.AesDecryptPayload (Bytes, UserConfig.Instance.LocalEncryptKey);
                    Bytes = messageGet;
                   
                } else {
                    if ("Locked" == (System.Text.Encoding.ASCII.GetString (Bytes, 14, 6))) {
                        //网关已加密,自动切换为加密
                        UserConfig.Instance.IsLocalEncrypt = true;
                    if (Bytes.Length == 20) {
                        var mes = System.Text.Encoding.ASCII.GetString (Bytes, 14, 6);
                        if ("Locked" == mes) {
                            //网关已加密,自动切换为加密
                            UserConfig.Instance.IsLocalEncrypt = true;
                        }
                    }
                }
            }
Crabtree/SmartHome/HDL/Operation/ResponseEntity/ErrorCode.cs
@@ -58,9 +58,9 @@
        public readonly static string NoAddMainAccount = "Can't bind master account!";
        //获取住宅的网关列表失败!
        public readonly static string FailedGetGatewaysForHome = "Failed to get list of gateways for home!";
        //此网关已绑定到一个住所,请在绑定到另一个住所之前将其重置。或者长按网关按键3S,变成红灯常亮进入强制绑定模式!
        public readonly static string UnableToBindGateway = "This gateway is already bound to one residence, please reset it before binding to another residence.Or long press the gateway button 3S, the red light is always on to enter the forced binding mode!";
        //此网关已绑定到一个住所,请在绑定到另一个住所之前将其重置。或者长按网关按键3S,变成红灯常亮,然后重试!
        public readonly static string UnableToBindGateway = "This gateway is already bound to one residence, please reset it before binding to another residence.Or long press the gateway button 3S, the red light is always on, and then try again!";
        //网关固件版本过低,请先升级!
        public readonly static string GatewayVersionLow = "The gateway firmware version is too low, please upgrade first!";
        //请先绑定无线网关  2020-01-11
@@ -69,6 +69,7 @@
        public readonly static string LoginInAnotherDevice = "Your account is signed in with a remote connection on another device!";
        //您并不具有此分享者此住宅的完全控制权限!
        public readonly static string InsufficientAuthority = "You don't have full control over this sharer's home!";
        //密码错误或者网关被其它住宅绑定,与网关通讯失败! 请长按网关按钮3S,进入红灯常亮,然后重新搜索!
        public readonly static string GatewayPasswordError = "The password is wrong or the gateway is bound by another home, communication with the gateway failed! Please long press the gateway button 3S, the red light is always on, and then search again!";
    }
}
Crabtree/SmartHome/HDL/Operation/UserConfig.cs
@@ -266,6 +266,12 @@
        /// </summary>
        public string LocalEncryptKey = string.Empty;
        /// <summary>
        /// 是否加密密码验证通过
        /// </summary>
        public bool EncryptedPasswordCorrect = true;
        /// <summary>
        /// 是否加密
        /// </summary>
Crabtree/SmartHome/UI/SimpleControl/CommonPage.cs
@@ -326,7 +326,7 @@
                        }
                    }
                    break;
                case Command. ReadAnalogValueACK:
                case Command.ReadAnalogValueACK:
                    foreach (var room in Room.Lists) {
                        foreach (var common in room.DeviceList) {
                            if (common.SubnetID != subnetID || common.DeviceID != deviceID || common.LoopID != usefullBytes [1]) {
@@ -350,7 +350,7 @@
                                int dddd = usefullBytes [0] & 0x3F;
                            int dddd = usefullBytes [0] & 0x3F;
                            // 0xXX:公司内部协议对应的序号
                            // common.Type:对应的是编辑软件的序号(没有一一对应,是为了将相近的调整在一起,方便客户使用)
Crabtree/SmartHome/UI/SimpleControl/EquipmentPublicClass.cs
@@ -62,7 +62,7 @@
                        });
                        bool canRemote = false;
                        if (CommonPage.IsRemote) {
                            await SmartHome.MqttCommon.StartCloudMqtt ();
                            //await SmartHome.MqttCommon.StartCloudMqtt ();
                            SmartHome.MqttCommon.MqttRemoteSend (new byte [] { }, 3);
                        }
                        foreach (var gatewayFileName in gateWayList) {
@@ -131,7 +131,7 @@
                            if (UserConfig.Instance.CheckHomeGateways ()) {
                                if (!string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.HomeGateways[0].GatewayUniqueId)) {
                                    Shared.SimpleControl.CommonPage.IsRemote = true;
                                    await SmartHome.MqttCommon.StartCloudMqtt ();
                                    //await SmartHome.MqttCommon.StartCloudMqtt ();
                                }
                            }
                        }
Crabtree/SmartHome/UI/SimpleControl/MainPage.cs
@@ -39,7 +39,7 @@
        //public static Button LogoButton = new Button ();
        public static string RequestVersion = "20200114";
        public static string RequestVersion = "20200115";
        public static UserInfo LoginUser;
        /// <summary>
        /// 是否是管理员权限(变更了,成员的时候,这个也为ture。为什么会声明这样变量,因为有些接口必须使用原来的Token)
Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs
@@ -41,6 +41,73 @@
        //static bool thisShowTip = true;
        static string mqttRequestParToken = "";
        static MqttCommon ()
        {
            InitMqtt ();
        }
        public static async System.Threading.Tasks.Task InitMqtt ()
        {
            new System.Threading.Thread (async () => {
                while (true) {
                    System.Threading.Thread.Sleep (100);
                    if (!CommonPage.IsRemote) continue;
                    await StartCloudMqtt ();
                    await CheckingSubscribeTopics ();
                }
            }) { IsBackground = true }.Start ();
        }
        /// <summary>
        /// 是否订阅成功
        /// </summary>
        static bool isSubscribeTopicSuccess = false;
        /// <summary>
        /// 检查主题是否订阅失败
        /// </summary>
        /// <returns></returns>
        static async Task CheckingSubscribeTopics ()
        {
            if (!remoteIsConnected) {
                return;
            }
            try {
                if (!isSubscribeTopicSuccess) {
                    var topicFilterCommon = new TopicFilter () {
                        Topic = $"/BusGateWayToClient/{CurRemoteMACInfo.macMark}/Common/#",
                        QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce
                    };
                    //网关重新登录主题
                    var topicFilterGateWayInfoChange = new TopicFilter () {
                        Topic = $"/BusGateWayToClient/{CurRemoteMACInfo.macMark}/NotifyBusGateWayInfoChange",
                        QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce
                    };
                    //挤下线主题
                    var topicFilterNotifySqueeze = new TopicFilter () {
                        Topic = $"/BusGateWayToClient/{mMqttInfo.connEmqClientId}/Push/NotifySqueeze",
                        QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce
                    };
                    var topicFilters = new TopicFilter [] { topicFilterCommon, topicFilterGateWayInfoChange, topicFilterNotifySqueeze };
                    var result = await RemoteMqttClient.SubscribeAsync (topicFilters);
                    if (result.Items [0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS2) {
                        isSubscribeTopicSuccess = true;
                    }
                }
            } catch (Exception e) {
            }
        }
        /// <summary>
        /// 断开远程Mqtt的链接
        /// </summary>
@@ -92,16 +159,16 @@
            //追加:没有远程连接的权限
            if (remoteMqttIsConnecting
               || remoteIsConnected) {
                System.Console.WriteLine ($"============>MqttremoteMqttIsConnecting:{remoteMqttIsConnecting}  remoteIsConnected:{remoteIsConnected} ");
                //System.Console.WriteLine ($"============>MqttremoteMqttIsConnecting:{remoteMqttIsConnecting}  remoteIsConnected:{remoteIsConnected} ");
                return;
            }
            remoteMqttIsConnecting = true;
            await System.Threading.Tasks.Task.Factory.StartNew (async () => {
                try {
                    lock (RemoteMqttClient) {
                    //lock (RemoteMqttClient) {
                        //表示后面将进行连接
                        remoteMqttIsConnecting = true;
                        #region 初始化远程Mqtt
                        //(3)当[连接云端的Mqtt成功后]或者[以及后面App通过云端Mqtt转发数据给网关成功后],处理接收到云端数据包响应时在mqttServerClient_ApplicationMessageReceived这个方法处理
@@ -175,6 +242,7 @@
                        if (RemoteMqttClient.DisconnectedHandler == null) {
                            RemoteMqttClient.UseDisconnectedHandler (async (e) => {
                                System.Console.WriteLine ($"============>Mqtt远程连接断开");
                                isSubscribeTopicSuccess = false;
                                await DisConnectRemoteMqttClient ("StartRemoteMqtt.DisconnectedHandler");
                                //await StartRemoteMqtt();
                                //if (thisShowTip) {
@@ -211,8 +279,7 @@
                            });
                        }
                        #endregion
                    }
                    try {
                    //}
                        mqttRequestParToken = MainPage.LoginUser.LoginTokenString;
                        //--第一步:获取mqtt链接参数
@@ -271,11 +338,6 @@
                            }
                        }
                    } catch (Exception ex) {
                        Console.WriteLine (ex.Message);
                    }
                } catch (Exception ex) {
                    System.Console.WriteLine ($"============>Mqtt 远程连接通讯连接出异常:{ex.Message}");
                } finally {
@@ -310,22 +372,14 @@
                await DisConnectRemoteMqttClient ("StartRemoteMqtt");
                await RemoteMqttClient.ConnectAsync (options1);
                remoteIsConnected = true;
                await MqttRemoteSend (new byte [] { 0 }, 1);
                await MqttRemoteSend (new byte [] { 0 }, 2);
                await MqttRemoteSend (new byte [] { 0 }, 4);
                //await MqttRemoteSend (new byte [] { 0 }, 1);
                //await MqttRemoteSend (new byte [] { 0 }, 2);
                //await MqttRemoteSend (new byte [] { 0 }, 4);
            }
        }
        //public static async System.Threading.Tasks.Task InitMqtt () {
        //    while (true) {
        //        await StartCloudMqtt ();
        //        System.Threading.Thread.Sleep (100);
        //    }
        //}
        /// <summary>
        /// 
        /// </summary>
@@ -351,59 +405,14 @@
                    try {
                         RemoteMqttClient.PublishAsync (m);
                    } catch (Exception e) {
                        await DisConnectRemoteMqttClient (e.Message);
                        await StartCloudMqtt ();
                        if (remoteIsConnected) {
                            RemoteMqttClient.PublishAsync (m);
                        }
                        //await DisConnectRemoteMqttClient (e.Message);
                        //await StartCloudMqtt ();
                        //if (remoteIsConnected) {
                        //    RemoteMqttClient.PublishAsync (m);
                        //}
                    }
                    //}
                    break;
                case 1:
                    topicName = $"/BusGateWayToClient/{CurRemoteMACInfo.macMark}/Common/#";
                    //if (remoteIsConnected) {
                    try {
                        await RemoteMqttClient.SubscribeAsync (topicName);
                    } catch (Exception e) {
                        await DisConnectRemoteMqttClient (e.Message);
                        await StartCloudMqtt ();
                        if (remoteIsConnected) {
                            await RemoteMqttClient.SubscribeAsync (topicName);
                        }
                    }
                    // }
                    break;
                case 2:
                    var macStr = CurRemoteMACInfo.mac.ToUpper ();
                    char [] cArrs = macStr.ToCharArray ();
                    Array.Reverse (cArrs);
                    var sss = string.Join (string.Empty, cArrs);
                    using (var provider = new MD5CryptoServiceProvider ()) {
                        byte [] buffer = provider.ComputeHash (Encoding.Default.GetBytes (sss));
                        StringBuilder builder = new StringBuilder ();
                        for (int i = 0; i < buffer.Length; i++) {
                            builder.Append (buffer [i].ToString ("x2"));
                        }
                        CurRemoteMACInfo.md5_mac_string = builder.ToString ().ToUpper ();
                    }
                    //topicName = $"/NotifyBusGateWayInfoChagne/{CurRemoteMACInfo.md5_mac_string}";
                    //2020-01-11 修改订阅主题地址
                    topicName = $"/BusGateWayToClient/{CurRemoteMACInfo.macMark}/NotifyBusGateWayInfoChange";
                    //if (remoteIsConnected) {
                    try {
                        await RemoteMqttClient.SubscribeAsync (topicName);
                    } catch (Exception e) {
                        await DisConnectRemoteMqttClient (e.Message);
                        await StartCloudMqtt ();
                        if (remoteIsConnected) {
                            await RemoteMqttClient.SubscribeAsync (topicName);
                        }
                    }
                    //}
                    break;
                case 3:
                    topicName = $"/ClientToBusGateWay/{CurRemoteMACInfo.macMark}/Common/CheckGateway";
@@ -411,29 +420,12 @@
                    try {
                        Console.WriteLine ("CheckGateway");
                        await RemoteMqttClient.PublishAsync (m1);
                         RemoteMqttClient.PublishAsync (m1);
                    } catch (Exception e) {
                        Console.WriteLine ($"CheckGateway Fail:{e.Message}");
                        await DisConnectRemoteMqttClient (e.Message);
                        await StartCloudMqtt ();
                        //await DisConnectRemoteMqttClient (e.Message);
                        //await StartCloudMqtt ();
                    }
                    break;
                case 4:
                    //2020-01-13 修改挤下线主题
                    topicName = $"/BusGateWayToClient/{mMqttInfo.connEmqClientId}/Push/NotifySqueeze";
                    //if (remoteIsConnected) {
                    try {
                        await RemoteMqttClient.SubscribeAsync (topicName);
                    } catch (Exception e) {
                        await DisConnectRemoteMqttClient (e.Message);
                        await StartCloudMqtt ();
                        if (remoteIsConnected) {
                            await RemoteMqttClient.SubscribeAsync (topicName);
                        }
                    }
                    //}
                    break;
                }
Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs
@@ -348,6 +348,8 @@
        Alert checkInternetAlert = new Alert ("", "Your phone in not connected to WIFI network, please connet", "Close", "Search again");
        Alert confirmAlert = new Alert ("", "Please make sure gateway is powered up and comect to WiFi router.", "Close", "Search again");
        Alert confirmAlert1 = new Alert ("", "If not all the gateways are in the list,you can search again.", "Close", "Search again");
        Alert wrongPasswordAlert = new Alert ("", ErrorCode.GatewayPasswordError, "Close", "Search again");
        void SearchGatewayList ()
        {
            if (UserConfig.Instance.internetStatus == 0 || UserConfig.Instance.internetStatus == 1) {
@@ -370,6 +372,7 @@
                    #region 搜索设备
                    ////2020-01-14 默认明文开始搜索
                    UserConfig.Instance.IsLocalEncrypt = false;
                    UserConfig.Instance.EncryptedPasswordCorrect = true;
                    CommonPage.LocalPhoneFindDevice = true;
                    CommonPage.RandomHigh = (byte)new Random ().Next (255);
@@ -433,13 +436,9 @@
                        if (CommonPage.GateWayList.Count == 0) {
                            MainPage.Loading.Hide ();
                            if (this != null && this.Parent != null) {
                                confirmAlert.Show ();
                                confirmAlert.ResultEventHandler += (ddf, ddd) => {
                                    MainPage.Loading.Hide ();
                                    if (ddd) {
                                        SearchGatewayList ();
                                    }
                                };
                                ShowConfirmAlert ();
                            }
                        } else {
                            if (this != null && this.Parent != null) {
@@ -459,7 +458,49 @@
            }) { IsBackground = true }.Start ();
        }
        /// <summary>
        /// 提示
        /// Please make sure gateway is powered up and comect to WiFi router.
        /// 或者
        ///
        /// </summary>
        static void ShowConfirmAlert () {
            if (UserConfig.Instance.IsLocalEncrypt) {
                //密码检验正确
                if (UserConfig.Instance.EncryptedPasswordCorrect) {
                    inView.confirmAlert.Show ();
                    inView.confirmAlert.ResultEventHandler += (ddf, ddd) => {
                        MainPage.Loading.Hide ();
                        if (ddd) {
                            inView.SearchGatewayList ();
                        }
                    };
                } else {
                    inView.wrongPasswordAlert.Show ();
                    inView.wrongPasswordAlert.ResultEventHandler += (ddf, ddd) => {
                        MainPage.Loading.Hide ();
                        if (ddd) {
                            inView.SearchGatewayList ();
                        }
                    };
                }
            } else {
                inView.confirmAlert.Show ();
                inView.confirmAlert.ResultEventHandler += (ddf, ddd) => {
                    MainPage.Loading.Hide ();
                    if (ddd) {
                        inView.SearchGatewayList ();
                    }
                };
            }
        }
        //static byte [] AseKeyBytes;
@@ -532,19 +573,19 @@
            });
            bool goNext = false;
            if (!UserConfig.Instance.IsLocalEncrypt) {
                //如果没加密,走修改加密方法
                var result = SetGateWayLocalEncryption (common);
                if (!result) {
                    MainPage.LoadingHide ();
                    return result;//修改失败 返回goNext false
                }
                //修改成功,设置本地为加密方式
                UserConfig.Instance.IsLocalEncrypt = true;
                //string aseKeyStr = CommonPage.MyEncodingUTF8.GetString (AseKeyBytes);
                //UserConfig.Instance.LocalEncryptKey = aseKeyStr;
                System.Console.WriteLine ($"============>LocalEncryptKey 加密成功Key为:{UserConfig.Instance.LocalEncryptKey}");
            }
            //if (!UserConfig.Instance.IsLocalEncrypt) {
            //    //如果没加密,走修改加密方法
            //    var result = SetGateWayLocalEncryption (common);
            //    if (!result) {
            //        MainPage.LoadingHide ();
            //        return result;//修改失败 返回goNext false
            //    }
            //    //修改成功,设置本地为加密方式
            //    UserConfig.Instance.IsLocalEncrypt = true;
            //    //string aseKeyStr = CommonPage.MyEncodingUTF8.GetString (AseKeyBytes);
            //    //UserConfig.Instance.LocalEncryptKey = aseKeyStr;
            //    System.Console.WriteLine ($"============>LocalEncryptKey 加密成功Key为:{UserConfig.Instance.LocalEncryptKey}");
            //}
            var backBytes = Control.ControlBytesSendHasReturn (Command.Read_APP_Data_STORE_1D5C_CMD, common.SubnetID, common.DeviceID, new byte [] { });
          
@@ -552,9 +593,8 @@
                Application.RunOnMainThread (() => {
                    new Alert ("", "No response from gateway. Please make sure the gateway is online and its firmware is up to date.", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                });
            }
            MainPage.LoadingHide ();
            if (backBytes.Length >= 37) {
                //******************住宅ID string类型*************
@@ -565,19 +605,57 @@
                //2020-01-12
                backIDStr = backIDStr.Replace ("\0", "");
                if (enable || backIDStr == UserConfig.Instance.CurrentRegion.Id || string.IsNullOrEmpty (backIDStr)) {
                    if (!UserConfig.Instance.IsLocalEncrypt) {
                        //如果没加密,走修改加密方法
                        var result = SetGateWayLocalEncryption (common);
                        if (!result) {
                            MainPage.LoadingHide ();
                            return result;//修改失败 返回goNext false
                        }
                        //修改成功,设置本地为加密方式
                        UserConfig.Instance.IsLocalEncrypt = true;
                        System.Console.WriteLine ($"============>LocalEncryptKey 加密成功Key为:{UserConfig.Instance.LocalEncryptKey}");
                    }
                    goNext = true;
                } else {
                    Application.RunOnMainThread (() => {
                        new Alert ("", ErrorCode.UnableToBindGateway, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                    });
                    UnableToBindGatewayAlertShow ();
                }
            } else {
                Application.RunOnMainThread (() => {
                    new Alert ("", ErrorCode.GatewayVersionLow, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                });
            }
            MainPage.LoadingHide ();
            return goNext;
        }
        static void UnableToBindGatewayAlertShow ()
        {
            if (inView == null)
                return;
            Application.RunOnMainThread (() => {
                //if (this != null && this.Parent != null) {
                var alter = new Alert ("", ErrorCode.UnableToBindGateway, Language.StringByID (R.MyInternationalizationString.Close));
                alter.ResultEventHandler += (sender1, e1) => {
                    if (e1) {
                        if (inView == null)
                            return;
                        //重置为加密模式
                        UserConfig.Instance.IsLocalEncrypt = true;
                        (inView.Parent as PageLayout).PageIndex -= 1;
                    }
                };
                alter.Show ();
                //}
            });
        }
    }
}
Crabtree/SmartHome/UI/SimpleControl/Phone/Register/AccountLogin.cs
@@ -74,12 +74,14 @@
                TextAlignment = TextAlignment.CenterLeft,
                Radius = (uint)Application.GetRealHeight (0),
                TextColor = SkinStyle.Current.TextColor1,
                //Text = account,
#if DEBUG
                //Text = "18926269190@189.cn"
                Text = "721343314@qq.com"
#endif
                Text = account,
            };
#if DEBUG
            //Text = "18926269190@189.cn"
            etAccount.Text = "721343314@qq.com";
#endif
            accountView.AddChidren (etAccount);
            var userConfigBytes = IO.FileUtils.ReadFile ("AccountListDB");
@@ -121,11 +123,12 @@
                TextAlignment = TextAlignment.CenterLeft,
                SecureTextEntry = true,
                TextColor = SkinStyle.Current.TextColor1,
#if DEBUG
                Text = "123456"
#endif
                //Text = password,
                Text = password,
            };
#if DEBUG
            etPasswrod.Text = "123456";
#endif
            passwrodView.AddChidren (etPasswrod);
            Button btnShowPassword = new Button () {
Crabtree/SmartHome/UI/SimpleControl/Phone/Schedule/HelpView.cs
@@ -29,6 +29,17 @@
            };
            topView.AddChidren (title);
            title.MouseLongEventHandler += (sd, ds) => {
//#if DEBUG
                try {
                    //2020-01-15 长按显示当前住宅ID
                    new Alert ("", UserConfig.Instance.CurrentRegion.Id, "close").Show ();
                } catch { }
//#endif
            };
            var back = new Button () {
                Height = Application.GetRealHeight (100),
                Width = Application.GetRealWidth (85),
Crabtree/SmartHome/UI/SimpleControl/Phone/User/UserSettingView.cs
@@ -475,6 +475,7 @@
            btnhelpTitle.MouseLongEventHandler += (sd, ds) => {
                //var uc = UserConfig.Instance.RometoUserInfoKeys.Find ((obj) => obj.Contains ("HiddenJson"));
                //new Alert ("", uc, "close").Show ();
            };
            EventHandler<MouseEventArgs> helpEventHandler = (sender, e) => {