| | |
| | | if (SetGateWayMqttUrlAddress ()) { |
| | | //4.写配置成功后下一步操作 |
| | | GatewaySettingSucceeded (); |
| | | //追加判断网关上网秘钥是否写入成功 2022年12月28日14:16:14 |
| | | ApplyServerKey (); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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> |
| | | /// 上传oid和sid列表 |
| | |
| | | //} |
| | | |
| | | } |
| | | |
| | | |
| | | public class DeviceSecret |
| | | { |
| | | public string deviceSecret; |
| | | } |
| | | } |