From e6b14a50eb55783efdf5b976785606f99e62bb25 Mon Sep 17 00:00:00 2001 From: liyi Date: Mon, 23 Dec 2024 15:19:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=93=9D=E7=89=99WIFI=E9=85=8D=E7=BD=91?= =?UTF-8?q?=E6=97=B6=E5=A2=9E=E5=8A=A0peerID=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/blue/io_protocol/io_configuringWifi.dart | 9 +- .../configuringWifi_logic.dart | 107 ++++++++++++------ 2 files changed, 79 insertions(+), 37 deletions(-) diff --git a/lib/blue/io_protocol/io_configuringWifi.dart b/lib/blue/io_protocol/io_configuringWifi.dart index 99ac0e29..8cc0142d 100755 --- a/lib/blue/io_protocol/io_configuringWifi.dart +++ b/lib/blue/io_protocol/io_configuringWifi.dart @@ -17,6 +17,7 @@ class SenderConfiguringWifiCommand extends SenderProtocol { this.userID, this.ssid, this.password, + this.peerId, this.numberOfServers, this.listOfServers, this.numberOfPhone, @@ -31,6 +32,7 @@ class SenderConfiguringWifiCommand extends SenderProtocol { String? userID; String? ssid; String? password; + String? peerId; int? numberOfServers; List? listOfServers; int? numberOfPhone; @@ -44,7 +46,7 @@ class SenderConfiguringWifiCommand extends SenderProtocol { @override String toString() { return 'SenderConfiguringWifiCommand{keyID: $keyID, userID: $userID, ' - 'ssid: $ssid, password: $password, numberOfServers: $numberOfServers, ' + 'ssid: $ssid, password: $password,peerId: $peerId, numberOfServers: $numberOfServers, ' 'listOfServers: $listOfServers, numberOfPhone: $numberOfPhone, ' 'listOfPhone: $listOfPhone, token: $token, needAuthor: $needAuthor, ' 'publicKey: $publicKey, privateKey: $privateKey}'; @@ -87,6 +89,11 @@ class SenderConfiguringWifiCommand extends SenderProtocol { subData.addAll(utf8.encode(password!)); subData = getFixedLengthList(subData, 20 - passwordLength); + //peerId 44 + final int peerIdLength = utf8.encode(peerId!).length; + subData.addAll(utf8.encode(peerId!)); + subData = getFixedLengthList(subData, 44 - peerIdLength); + // NumberOfServers subData.add(numberOfServers!); diff --git a/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart b/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart index 3049a26c..eb6f1ccc 100755 --- a/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart +++ b/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart @@ -1,4 +1,3 @@ - import 'dart:async'; import 'dart:io'; @@ -8,6 +7,7 @@ import 'package:network_info_plus/network_info_plus.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:star_lock/login/login/entity/LoginEntity.dart'; import 'package:star_lock/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifiEntity.dart'; +import 'package:star_lock/talk/startChart/entity/star_chart_register_node_entity.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import '../../../../../blue/blue_manage.dart'; @@ -21,24 +21,26 @@ import '../../../../../tools/eventBusEventManage.dart'; import '../../../../../tools/storage.dart'; import 'configuringWifi_state.dart'; -class ConfiguringWifiLogic extends BaseGetXController{ +class ConfiguringWifiLogic extends BaseGetXController { final ConfiguringWifiState state = ConfiguringWifiState(); Future getWifiLockServiceIpAndPort() async { - final ConfiguringWifiEntity entity = await ApiRepository.to.getWifiLockServiceIpAndPort(); - if(entity.errorCode! == 0){ + final ConfiguringWifiEntity entity = + await ApiRepository.to.getWifiLockServiceIpAndPort(); + if (entity.errorCode! == 0) { state.configuringWifiEntity.value = entity; } } - Future updateNetworkInfo() async{ + Future updateNetworkInfo() async { final LoginEntity entity = await ApiRepository.to.updateNetworkInfo( lockId: state.lockSetInfoData.value.lockId!, - network:state.wifiNameController.text, + network: state.wifiNameController.text, ); - if(entity.errorCode!.codeIsSuccessful){ - showToast('配网成功'.tr, something:(){ - eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); + if (entity.errorCode!.codeIsSuccessful) { + showToast('配网成功'.tr, something: () { + eventBus + .fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); Get.close(2); }); } @@ -46,10 +48,12 @@ class ConfiguringWifiLogic extends BaseGetXController{ // 监听设备返回的数据 late StreamSubscription _replySubscription; + void _initReplySubscription() { - _replySubscription = EventBusManager().eventBus!.on().listen((Reply reply) async { + _replySubscription = + EventBusManager().eventBus!.on().listen((Reply reply) async { // WIFI配网结果 - if(reply is SenderConfiguringWifiReply) { + if (reply is SenderConfiguringWifiReply) { _replySenderConfiguringWifi(reply); } }); @@ -59,7 +63,7 @@ class ConfiguringWifiLogic extends BaseGetXController{ Future _replySenderConfiguringWifi(Reply reply) async { final int status = reply.data[5]; - switch(status){ + switch (status) { case 0x00: //成功 state.sureBtnState.value = 0; @@ -69,19 +73,26 @@ class ConfiguringWifiLogic extends BaseGetXController{ break; case 0x06: //无权限 - final List? privateKey = await Storage.getStringList(saveBluePrivateKey); - final List getPrivateKeyList = changeStringListToIntList(privateKey!); + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = + changeStringListToIntList(privateKey!); - final List? publicKey = await Storage.getStringList(saveBluePublicKey); - final List publicKeyDataList = changeStringListToIntList(publicKey!); + final List? publicKey = + await Storage.getStringList(saveBluePublicKey); + final List publicKeyDataList = + changeStringListToIntList(publicKey!); final List tokenData = reply.data.sublist(7, 10); final List saveStrList = changeIntListToStringList(tokenData); Storage.setStringList(saveBlueToken, saveStrList); final List serversList = []; - for(int i = 0; i itemList = item.serviceIp!.split('.'); for (String element in itemList) { serversList.add(int.parse(element)); @@ -94,6 +105,11 @@ class ConfiguringWifiLogic extends BaseGetXController{ serversList.add(type2); } + final StarChartRegisterNodeEntity? registerNodeEntity = + await Storage.getStarChartRegisterNodeInfo(); + // 获取app用户的peerId + String appPeerId = registerNodeEntity?.peer?.id ?? ''; + final List uidList = [Storage.getUid().toString()]; IoSenderManage.senderConfiguringWifiCommand( keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), @@ -108,6 +124,7 @@ class ConfiguringWifiLogic extends BaseGetXController{ needAuthor: 1, publicKey: publicKeyDataList, privateKey: getPrivateKeyList, + peerId: appPeerId, ); break; @@ -123,42 +140,51 @@ class ConfiguringWifiLogic extends BaseGetXController{ // 点击配置wifi Future senderConfiguringWifiAction() async { - if(state.wifiNameController.text.isEmpty){ + if (state.wifiNameController.text.isEmpty) { showToast('请输入wifi名称'.tr); return; } - if(state.sureBtnState.value == 1){ + if (state.sureBtnState.value == 1) { return; } state.sureBtnState.value = 1; showEasyLoading(); - showBlueConnetctToastTimer(action: (){ + showBlueConnetctToastTimer(action: () { dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { - if (connectionState == BluetoothConnectionState.connected){ - final List? privateKey = await Storage.getStringList(saveBluePrivateKey); - final List getPrivateKeyList = changeStringListToIntList(privateKey!); + BlueManage().blueSendData(BlueManage().connectDeviceName, + (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected) { + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = + changeStringListToIntList(privateKey!); - final List? publicKey = await Storage.getStringList(saveBluePublicKey); - final List publicKeyDataList = changeStringListToIntList(publicKey!); + final List? publicKey = + await Storage.getStringList(saveBluePublicKey); + final List publicKeyDataList = + changeStringListToIntList(publicKey!); final List? token = await Storage.getStringList(saveBlueToken); final List getTokenList = changeStringListToIntList(token!); final List serversList = []; - for(int i = 0; i itemList = item.serviceIp!.split('.'); for (String element in itemList) { serversList.add(int.parse(element)); } - }else{ - final List addresses = await InternetAddress.lookup(item.serviceIp!); + } else { + final List addresses = + await InternetAddress.lookup(item.serviceIp!); final List itemList = addresses.first.address.split('.'); for (String element in itemList) { serversList.add(int.parse(element)); @@ -174,11 +200,17 @@ class ConfiguringWifiLogic extends BaseGetXController{ final String? uidStr = await Storage.getUid(); final List uidList = [uidStr.toString()]; + + final StarChartRegisterNodeEntity? registerNodeEntity = + await Storage.getStarChartRegisterNodeInfo(); + // 获取app用户的peerId + String appPeerId = registerNodeEntity?.peer?.id ?? ''; IoSenderManage.senderConfiguringWifiCommand( keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), userID: await Storage.getUid(), ssid: state.wifiNameController.text, password: state.wifiPWDController.text, + peerId: appPeerId, numberOfServers: state.configuringWifiEntity.value.data!.serviceNum, listOfServers: serversList, numberOfPhone: uidList.length, @@ -192,7 +224,7 @@ class ConfiguringWifiLogic extends BaseGetXController{ dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; - if(state.ifCurrentScreen.value == true){ + if (state.ifCurrentScreen.value == true) { showBlueConnetctToast(); } } @@ -200,6 +232,7 @@ class ConfiguringWifiLogic extends BaseGetXController{ } final NetworkInfo _networkInfo = NetworkInfo(); + Future getWifiName() async { String ssid = ''; ssid = (await _networkInfo.getWifiName())!; @@ -211,17 +244,19 @@ class ConfiguringWifiLogic extends BaseGetXController{ ///定位权限 Future checkLocationPermission() async { final PermissionStatus value = await locationPermission(); - final bool allow = value != PermissionStatus.permanentlyDenied && value != PermissionStatus.denied; + final bool allow = value != PermissionStatus.permanentlyDenied && + value != PermissionStatus.denied; return allow; } - Future locationPermission() async => Permission.location.request(); + Future locationPermission() async => + Permission.location.request(); @override void onReady() { super.onReady(); - if(state.wifiName.value.isEmpty){ + if (state.wifiName.value.isEmpty) { getWifiName().then((String value) { state.wifiNameController.text = value; });