Crabtree/.vs/SmartHome/xs/UserPrefs.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Crabtree/ON.Ios/Info.plist | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Crabtree/ON/Properties/AndroidManifest.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Crabtree/SmartHome/UI/SimpleControl/MainPage.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
Crabtree/.vs/SmartHome/xs/UserPrefs.xml
@@ -1,40 +1,36 @@ <Properties StartupConfiguration="{1D83BF28-BA88-4152-BA41-D7EFE90A5437}|Default"> <MonoDevelop.Ide.ItemProperties.ON.Droid PreferredExecutionTarget="Android.Android_Accelerated_Oreo" /> <MonoDevelop.Ide.Workbench ActiveDocument="ON.Ios/Resources/Language.ini"> <MonoDevelop.Ide.Workbench ActiveDocument="SmartHome/UI/SimpleControl/MqttCommon.cs"> <Files> <File FileName="SmartHome/UI/SimpleControl/Phone/Alexa/SmartSpeakertListPage.cs" Line="153" Column="48" /> <File FileName="SmartHome/HDL/Common/HttpUtil/HttpUtil.cs" Line="236" Column="1" /> <File FileName="SmartHome/HDL/Common/CommonUtlis.cs" Line="264" Column="27" /> <File FileName="ON/Assets/Language.ini" Line="1114" Column="1" /> <File FileName="SmartHome/UI/SimpleControl/R.cs" Line="1222" Column="44" /> <File FileName="ON.Ios/Resources/Language.ini" Line="2230" Column="1" /> <File FileName="SmartHome/HDL/Common/HttpUtil/HttpServerRequest.cs" Line="815" Column="1" /> <File FileName="SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs" /> <File FileName="SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs" /> <File FileName="ON/Properties/AndroidManifest.xml" /> <File FileName="ON.Ios/Info.plist" /> <File FileName="SmartHome/UI/SimpleControl/MqttCommon.cs" Line="349" Column="1" /> <File FileName="SmartHome/HDL/Common/HDLLinkUtlis.cs" Line="132" Column="1" /> <File FileName="SmartHome/UI/SimpleControl/MainPage.cs" Line="1" Column="1" /> </Files> <Pads> <Pad Id="ProjectPad"> <State name="__root__"> <Node name="SmartHome" expanded="True"> <Node name="ON.Droid" expanded="True"> <Node name="Assets" expanded="True" /> </Node> <Node name="ON.Ios" expanded="True"> <Node name="References" expanded="True" /> <Node name="Resources" expanded="True"> <Node name="Language.ini" selected="True" /> </Node> </Node> <Node name="Shared" expanded="True"> <Node name="DLL" expanded="True" /> <Node name="HDL" expanded="True"> <Node name="Common" expanded="True"> <Node name="HttpUtil" expanded="True" /> </Node> <Node name="Operation" expanded="True"> <Node name="Device" expanded="True" /> </Node> </Node> <Node name="IO" expanded="True" /> <Node name="Net" expanded="True" /> <Node name="UI" expanded="True"> <Node name="SimpleControl" expanded="True"> <Node name="Phone" expanded="True"> <Node name="Alexa" expanded="True" /> <Node name="Schedule" expanded="True" /> <Node name="User" expanded="True" /> </Node> <Node name="Phone" expanded="True" /> <Node name="MqttCommon.cs" selected="True" /> </Node> </Node> </Node> @@ -56,6 +52,7 @@ <MonoDevelop.Ide.DebuggingService.Breakpoints> <BreakpointStore> <Breakpoint file="/Users/jlchen/JLChen/ProjectsCode/HDLGit/CrabtreeOnNew/Crabtree/SmartHome/HDL/Common/HttpUtil/HttpServerRequest.cs" relfile="SmartHome/HDL/Common/HttpUtil/HttpServerRequest.cs" line="153" column="1" /> <Breakpoint file="/Users/jlchen/JLChen/ProjectsCode/HDLGit/CrabtreeOnNew/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs" relfile="SmartHome/HDL/Common/HDLLinkUtlis.cs" line="661" column="1" /> </BreakpointStore> </MonoDevelop.Ide.DebuggingService.Breakpoints> <MultiItemStartupConfigurations /> Crabtree/ON.Ios/Info.plist
@@ -17,9 +17,9 @@ <key>CFBundleIdentifier</key> <string>com.hdl.on</string> <key>CFBundleShortVersionString</key> <string>2.603291</string> <string>2.606221</string> <key>CFBundleVersion</key> <string>2.603291</string> <string>2.606221</string> <key>LSRequiresIPhoneOS</key> <true/> <key>MinimumOSVersion</key> Crabtree/ON/Properties/AndroidManifest.xml
@@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hdl.crabtreenew" android:versionName="2.604151" android:versionCode="202104151"> <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="28" /> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hdl.crabtreenew" android:versionName="2.606221" android:versionCode="202106221"> <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="29" /> <!-- 在安卓P版本之后,必须要授予FOREGROUND_SERVICE权限,才能够使用前台服务 --> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <!-- 定位权限,用于APP通过获取定位坐标查询当前地区天气--> Crabtree/SmartHome/UI/SimpleControl/MainPage.cs
@@ -38,7 +38,7 @@ //public static Button LogoButton = new Button (); public static string RequestVersion = "2.604151"; public static string RequestVersion = "2.606221"; public static UserInfo LoginUser; /// <summary> /// 是否是管理员权限(变更了,成员的时候,这个也为ture。为什么会声明这样变量,因为有些接口必须使用原来的Token) Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs
@@ -9,6 +9,7 @@ using MQTTnet; using System.Text; using System.Security.Cryptography; using System.Collections.Generic; namespace SmartHome { @@ -35,6 +36,10 @@ ///// </summary> //static readonly string TopicToApp = "/Push/NotifySqueeze"; /// <summary> /// 是否获取过密钥 /// </summary> static bool isGetGatewaySecretKey = false; /// <summary> /// 随机Key @@ -66,7 +71,7 @@ /// <summary> /// 断开远程Mqtt的链接 /// </summary> public static async System.Threading.Tasks.Task DisConnectRemoteMqttClient (string s = "") public static async System.Threading.Tasks.Task DisConnectRemoteMqttClient (string s = "") { try { if (remoteIsConnected) { @@ -120,6 +125,7 @@ bNeedStartTip = true; bNeedConnectTip = true; CommonConfig.Current.IfGetMqttInfoSuccess = false; isGetGatewaySecretKey = false;//获取密钥标记为false } await DisConnectRemoteMqttClient (s); } @@ -246,8 +252,16 @@ //QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce }; //当设备MQTT报文加密密钥发生变更时,云端通过该主题通知其他客户端刷新密钥,其它和该网关交互的客户端自行订阅该主题,该主题包不加密 var topicFilterPush3 = new MqttTopicFilter { Topic = $"/user/{CommonConfig.Current.HomeGatewayInfo.gatewayId}/custom/mqtt/secret/change", QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce, }; Utlis.WriteLine ("开始订阅!"); var result = await RemoteMqttClient.SubscribeAsync (new MqttTopicFilter [] { topicFilterBusGateWayToClient, topicFilterPush2 }); var result = await RemoteMqttClient.SubscribeAsync (new MqttTopicFilter [] { topicFilterBusGateWayToClient, topicFilterPush2, topicFilterPush3 }); if (result.Items [0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0) { isSubscribeSuccess = true; Utlis.WriteLine ("订阅成功!"); @@ -321,6 +335,11 @@ } else if (topic == $"/BusGateWayToClient/{CommonConfig.Current.HomeGatewayInfo.gatewayId}/NotifyBusGateWayInfoChange") {//网关上线,需要更新aeskey //收到网关上线消息主题 ReceiveNotifyBusGateWayInfoChange (); } else if (topic == $"/user/{CommonConfig.Current.HomeGatewayInfo.gatewayId}/custom/mqtt/secret/change") {//设备密钥更新通知,需要更新aeskey //设备密钥更新通知 HDLUtils.WriteLine ("设备密钥更新通知"); isGetGatewaySecretKey = false;//获取密钥标记为false GetGatewaySecretKey (); } else if (topic == $"/BusGateWayToClient/{CommonConfig.Current.HomeGatewayInfo.gatewayId}/NotifyGateWayOffline") {//网关掉线 //----第二步:读取账号下面的网关列表 ReceiveNotifyGateWayOffline (); } else if (topic == $"/BusGateWayToClient/{CommonConfig.Current.HomeGatewayInfo.gatewayId}/Common/CheckGateway") { @@ -372,13 +391,16 @@ //} //(4)===========开始连接过程========== //之前已经获取参数成功过 if (CommonConfig.Current.IfGetMqttInfoSuccess) { //判断是否需要重新获取 await CheckMQTTConnectAsync (); } else { //开始获取远程连接参数 await StartMQTTGetInfo (); //4.1 如果没获取过密钥则重新获取一次, 获取一次最新的密钥 if (isGetGatewaySecretKey || GetGatewaySecretKey ()) { //之前已经获取参数成功过 if (CommonConfig.Current.IfGetMqttInfoSuccess) { //判断是否需要重新获取 await CheckMQTTConnectAsync (); } else { //开始获取远程连接参数 await StartMQTTGetInfo (); } } } catch (Exception ex) { @@ -665,9 +687,6 @@ //#endif CheckIfNeedReadAllDeviceStatus (); } GetSingleHomeGatewayPaggerAndMQTTConnectAsync (false); } catch { } } @@ -831,7 +850,7 @@ var mqttInfoRequestResult_Obj = HttpServerRequest.Current.GetMqttRemoteInfo (GetRandomKey ()); if (mqttInfoRequestResult_Obj != null) { CommonConfig.Current.mMqttInfo = mqttInfoRequestResult_Obj; if (UserConfig.Instance.CheckHomeGatewaysNotEmpty()) { if (UserConfig.Instance.CheckHomeGatewaysNotEmpty ()) { //----第二步找出是否存在匹配当前住宅的mac,存在再进行远程。 CommonConfig.Current.HomeGatewayInfo = UserConfig.Instance.HomeGateway; if (CommonConfig.Current.HomeGatewayInfo != null) { @@ -848,13 +867,51 @@ } /// <summary> /// 分享住宅 获取当前住宅网关信息并且连接MQTT 或者刷新 /// 2020-03-17 /// 设备密钥更新通知,重新拿密钥 /// </summary> static async Task GetSingleHomeGatewayPaggerAndMQTTConnectAsync (bool bNeedConnect = true) /// <returns></returns> static bool GetGatewaySecretKey () { bool isSuccess = false; try { if (string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.Id)) return false; var nowhomeId = UserConfig.Instance.CurrentRegion.Id; var requestJson = HttpUtil.GetSignRequestJson (new HomeIdObj () { homeId = nowhomeId }); var revertObj = HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_GetGatewayList, requestJson); if (revertObj.Code == StateCode.SUCCESS) { var mHomeGatewayRes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<HomeGatewayInfo>> (revertObj.Data.ToString ()); if (nowhomeId == UserConfig.Instance.CurrentRegion.Id) { if (mHomeGatewayRes != null) { if (mHomeGatewayRes.Count > 0) { //只取第一个住宅 var info = mHomeGatewayRes [0]; UserConfig.Instance.HomeGateway = info; UserConfig.Instance.SaveUserConfig (); CommonConfig.Current.HomeGatewayInfo = info; //更新网关信息和加密Key mqttEncryptKey = info.aesKey; CommonConfig.Current.Save (); isSuccess = true; isGetGatewaySecretKey = true;//获取密钥标记为true } else { //打印错误 HDLUtils.WriteLine ("gateway is not bound"); } } } } else { //打印错误 HDLUtils.WriteLine ("Failed to get gateway info"); } return isSuccess; } catch { //return ""; return isSuccess; } }