| | |
| | | //} |
| | | |
| | | EventHandler<MouseEventArgs> eHandler = (sender, e) => { |
| | | Dialog dialog = new Dialog (); |
| | | Dialog dialog = new Dialog ();//修改设备备注 |
| | | FrameLayout dialogBodyView = new FrameLayout () { |
| | | BackgroundColor = SkinStyle.Current.DialogColor, |
| | | Width = Application.GetRealWidth (494), |
| | |
| | | //CommonPage.UpdateRemark (common.SubnetID, common.DeviceID, btnChangeName.Text.Trim ()); |
| | | |
| | | byte [] updateBytes = new byte [20]; |
| | | byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (btnChangeName.Text.Trim ()); |
| | | string changeName = btnChangeName.Text.Trim (); |
| | | byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (changeName); |
| | | Array.Copy (remakeBytes, 0, updateBytes, 0, remakeBytes.Length < 20 ? remakeBytes.Length : 20); |
| | | Control.ControlBytesSend (Command.Write_DeviceRamarkCMD, common.SubnetID, common.DeviceID, updateBytes); |
| | | |
| | | //修改云端备注 |
| | | new Thread (() => { |
| | | var http = new HttpServerRequest (); |
| | | http.EditDeviceName (common.DeviceID.ToString(), UserConfig.Instance.CurrentRegion.Id,changeName); |
| | | }) { IsBackground = true }.Start (); |
| | | |
| | | |
| | | btnDeviceName.Text = btnChangeName.Text; |
| | |
| | | if (SetGateWayMqttUrlAddress ()) { |
| | | //4.写配置成功后下一步操作 |
| | | GatewaySettingSucceeded (); |
| | | //追加判断网关上网秘钥是否写入成功 2022年12月28日14:16:14 |
| | | ApplyServerKey (); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | GotoHomePage (); |
| | | //GotoHomePage (); |
| | | UploadOidAndSidList (); |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读取网关上网秘钥,如果秘钥有问题则重新写入 |
| | | /// </summary> |
| | | void ApplyServerKey () |
| | | { |
| | | if (gatewayDeicve.Type == DeviceType.OnePortMqttFR) { |
| | | var result = Control.ControlBytesSendHasReturn (Command.ApplyServerKey, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { 0}); |
| | | if (result != null && result.Length > 1) { |
| | | if (result [1] == 0xF5) { |
| | | var secretKeyPack = HttpServerRequest.Current.ApplyDeviceSecret (gatewayDeicve.MAC.Replace(".","")); |
| | | if (secretKeyPack != null) { |
| | | if (secretKeyPack.Code == StateCode.SUCCESS) { |
| | | var pack = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceSecret> (secretKeyPack.Data.ToString ()); |
| | | if (pack != null) { |
| | | byte [] usefullBytes = new byte [17]; |
| | | usefullBytes [0] = 1; |
| | | byte [] ddd = System.Text.Encoding.ASCII.GetBytes (pack.deviceSecret); |
| | | Array.Copy (ddd, 0, usefullBytes, 1, 16 < ddd.Length ? 16 : ddd.Length); |
| | | var result2 = Control.ControlBytesSendHasReturn (Command.ApplyServerKey, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, usefullBytes); |
| | | |
| | | //byte [] restartArray = new byte [12]; |
| | | //string [] macArray = gatewayDeicve.MAC.Split ("."); |
| | | //for(int i = 0; i < macArray.Length; i++) { |
| | | // restartArray [i + 2] = Convert.ToByte (macArray [i], 16); |
| | | //} |
| | | //restartArray [10] = gatewayDeicve.SubnetID; |
| | | //restartArray [11] = gatewayDeicve.DeviceID; |
| | | //var result3 = Control.ControlBytesSendHasReturn (Command.RestartTheGateway, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, restartArray); |
| | | //Application.RunOnMainThread (() => { |
| | | // new Alert ("", "The Internet access key was successfully written, and the gateway is being restarted!", Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | //}); |
| | | } |
| | | } |
| | | } else { |
| | | Application.RunOnMainThread (() => { |
| | | new Alert ("", "Failed to generate Internet access key!", Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | }); |
| | | } |
| | | } |
| | | } else { |
| | | //Application.RunOnMainThread (() => { |
| | | // new Alert ("", "Failed to read the Internet access key!", Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | //}); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | ///// <summary> |
| | | ///// Gateway setting succeeded,data up.Please wait... |
| | | ///// 绑定Mac(印度版) |
| | | ///// </summary> |
| | | //void BindGatewaysNew () |
| | | //{ |
| | | // //Application.RunOnMainThread (() => { |
| | | // // MainPage.Loading.Start ("Gateway setting succeeded,data up. Please wait..."); |
| | | // //}); |
| | | // //IO.FileUtils.SaveEquipmentMessage (gatewayDeicve); |
| | | // //var gatewayMAC = gatewayDeicve.MAC.Replace (".", ""); |
| | | /// <summary> |
| | | /// 上传oid和sid列表 |
| | | /// </summary> |
| | | void UploadOidAndSidList () |
| | | { |
| | | |
| | | // ////走新更新绑定接口 |
| | | // //var mBindMacObj = new BindMacObj () { |
| | | // // LoginAccessToken = MainPage.LoginUser.LoginTokenString, |
| | | // // HomeId = UserConfig.Instance.CurrentRegion.Id, |
| | | // // MAC = gatewayMAC |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.Loading.Start ("Uploading device list..."); |
| | | }); |
| | | var RES = HDLLinkUtlis.Current.UploadOidAndSidList (); |
| | | Application.RunOnMainThread (() => { |
| | | if (RES) { |
| | | //Utlis.ShowTip ("Device list upload successfully!"); |
| | | } else { |
| | | Utlis.ShowTip ("Device list upload failed!"); |
| | | } |
| | | GotoHomePage (); |
| | | }); |
| | | |
| | | // //}; |
| | | |
| | | // //string urlHead = MainPage.RequestHttpsHost; |
| | | // //if (mBindMacObj.IsOtherAccountCtrl) { |
| | | // // urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl; |
| | | // // mBindMacObj.LoginAccessToken = UserConfig.Instance.MasterAccountToken; |
| | | // //} |
| | | |
| | | |
| | | // //var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (mBindMacObj); |
| | | |
| | | // ////var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (new EditMACByHomeId { RegionID = UserConfig.Instance.CurrentRegion.Id, MAC = gatewayMAC, IsReBind = true }); |
| | | // //var respone = MainPage.RequestHttps (API.BindMac, requestJson, urlHead); |
| | | // //if (respone.StateCode.ToUpper () != StateCode.SUCCESS) { |
| | | // // GetNowHomeGatewayAfterBindMacFailed ();//2020-01-11 |
| | | // // Application.RunOnMainThread (() => { |
| | | // // new Alert ("", $"Failed to bind Mac address! {ErrorCode.Reason }{respone.StateCode}", Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | // // if (MainPage.LoginUser.AccountString == "464027401@qq.com") { |
| | | // // new Alert (respone.StateCode, respone.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | // // } |
| | | // // }); |
| | | // // return; |
| | | // //} |
| | | // //GetNowHomeGateway (); |
| | | |
| | | // var gatewayMAC = gatewayDeicve.MAC.Replace (".", ""); |
| | | // AddMacToUserConfig (gatewayMAC); |
| | | |
| | | //} |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 跳转主页面 |
| | |
| | | //} |
| | | |
| | | } |
| | | |
| | | |
| | | public class DeviceSecret |
| | | { |
| | | public string deviceSecret; |
| | | } |
| | | } |