fix:蓝牙WIFI配网时增加peerID字段

This commit is contained in:
liyi 2024-12-23 15:19:57 +08:00
parent 5e862a2919
commit e6b14a50eb
2 changed files with 79 additions and 37 deletions

View File

@ -17,6 +17,7 @@ class SenderConfiguringWifiCommand extends SenderProtocol {
this.userID, this.userID,
this.ssid, this.ssid,
this.password, this.password,
this.peerId,
this.numberOfServers, this.numberOfServers,
this.listOfServers, this.listOfServers,
this.numberOfPhone, this.numberOfPhone,
@ -31,6 +32,7 @@ class SenderConfiguringWifiCommand extends SenderProtocol {
String? userID; String? userID;
String? ssid; String? ssid;
String? password; String? password;
String? peerId;
int? numberOfServers; int? numberOfServers;
List<int>? listOfServers; List<int>? listOfServers;
int? numberOfPhone; int? numberOfPhone;
@ -44,7 +46,7 @@ class SenderConfiguringWifiCommand extends SenderProtocol {
@override @override
String toString() { String toString() {
return 'SenderConfiguringWifiCommand{keyID: $keyID, userID: $userID, ' return 'SenderConfiguringWifiCommand{keyID: $keyID, userID: $userID, '
'ssid: $ssid, password: $password, numberOfServers: $numberOfServers, ' 'ssid: $ssid, password: $password,peerId: $peerId, numberOfServers: $numberOfServers, '
'listOfServers: $listOfServers, numberOfPhone: $numberOfPhone, ' 'listOfServers: $listOfServers, numberOfPhone: $numberOfPhone, '
'listOfPhone: $listOfPhone, token: $token, needAuthor: $needAuthor, ' 'listOfPhone: $listOfPhone, token: $token, needAuthor: $needAuthor, '
'publicKey: $publicKey, privateKey: $privateKey}'; 'publicKey: $publicKey, privateKey: $privateKey}';
@ -87,6 +89,11 @@ class SenderConfiguringWifiCommand extends SenderProtocol {
subData.addAll(utf8.encode(password!)); subData.addAll(utf8.encode(password!));
subData = getFixedLengthList(subData, 20 - passwordLength); 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 // NumberOfServers
subData.add(numberOfServers!); subData.add(numberOfServers!);

View File

@ -1,4 +1,3 @@
import 'dart:async'; import 'dart:async';
import 'dart:io'; 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:permission_handler/permission_handler.dart';
import 'package:star_lock/login/login/entity/LoginEntity.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/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 'package:star_lock/tools/baseGetXController.dart';
import '../../../../../blue/blue_manage.dart'; import '../../../../../blue/blue_manage.dart';
@ -21,24 +21,26 @@ import '../../../../../tools/eventBusEventManage.dart';
import '../../../../../tools/storage.dart'; import '../../../../../tools/storage.dart';
import 'configuringWifi_state.dart'; import 'configuringWifi_state.dart';
class ConfiguringWifiLogic extends BaseGetXController{ class ConfiguringWifiLogic extends BaseGetXController {
final ConfiguringWifiState state = ConfiguringWifiState(); final ConfiguringWifiState state = ConfiguringWifiState();
Future<void> getWifiLockServiceIpAndPort() async { Future<void> getWifiLockServiceIpAndPort() async {
final ConfiguringWifiEntity entity = await ApiRepository.to.getWifiLockServiceIpAndPort(); final ConfiguringWifiEntity entity =
if(entity.errorCode! == 0){ await ApiRepository.to.getWifiLockServiceIpAndPort();
if (entity.errorCode! == 0) {
state.configuringWifiEntity.value = entity; state.configuringWifiEntity.value = entity;
} }
} }
Future<void> updateNetworkInfo() async{ Future<void> updateNetworkInfo() async {
final LoginEntity entity = await ApiRepository.to.updateNetworkInfo( final LoginEntity entity = await ApiRepository.to.updateNetworkInfo(
lockId: state.lockSetInfoData.value.lockId!, lockId: state.lockSetInfoData.value.lockId!,
network:state.wifiNameController.text, network: state.wifiNameController.text,
); );
if(entity.errorCode!.codeIsSuccessful){ if (entity.errorCode!.codeIsSuccessful) {
showToast('配网成功'.tr, something:(){ showToast('配网成功'.tr, something: () {
eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); eventBus
.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
Get.close(2); Get.close(2);
}); });
} }
@ -46,10 +48,12 @@ class ConfiguringWifiLogic extends BaseGetXController{
// //
late StreamSubscription<Reply> _replySubscription; late StreamSubscription<Reply> _replySubscription;
void _initReplySubscription() { void _initReplySubscription() {
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async { _replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
// WIFI配网结果 // WIFI配网结果
if(reply is SenderConfiguringWifiReply) { if (reply is SenderConfiguringWifiReply) {
_replySenderConfiguringWifi(reply); _replySenderConfiguringWifi(reply);
} }
}); });
@ -59,7 +63,7 @@ class ConfiguringWifiLogic extends BaseGetXController{
Future<void> _replySenderConfiguringWifi(Reply reply) async { Future<void> _replySenderConfiguringWifi(Reply reply) async {
final int status = reply.data[5]; final int status = reply.data[5];
switch(status){ switch (status) {
case 0x00: case 0x00:
// //
state.sureBtnState.value = 0; state.sureBtnState.value = 0;
@ -69,19 +73,26 @@ class ConfiguringWifiLogic extends BaseGetXController{
break; break;
case 0x06: case 0x06:
// //
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey); final List<String>? privateKey =
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList =
changeStringListToIntList(privateKey!);
final List<String>? publicKey = await Storage.getStringList(saveBluePublicKey); final List<String>? publicKey =
final List<int> publicKeyDataList = changeStringListToIntList(publicKey!); await Storage.getStringList(saveBluePublicKey);
final List<int> publicKeyDataList =
changeStringListToIntList(publicKey!);
final List<int> tokenData = reply.data.sublist(7, 10); final List<int> tokenData = reply.data.sublist(7, 10);
final List<String> saveStrList = changeIntListToStringList(tokenData); final List<String> saveStrList = changeIntListToStringList(tokenData);
Storage.setStringList(saveBlueToken, saveStrList); Storage.setStringList(saveBlueToken, saveStrList);
final List<int> serversList = <int>[]; final List<int> serversList = <int>[];
for(int i = 0; i<state.configuringWifiEntity.value.data!.serviceList!.length; i++){ for (int i = 0;
final ServiceList item = state.configuringWifiEntity.value.data!.serviceList![i]; i < state.configuringWifiEntity.value.data!.serviceList!.length;
i++) {
final ServiceList item =
state.configuringWifiEntity.value.data!.serviceList![i];
final List<String> itemList = item.serviceIp!.split('.'); final List<String> itemList = item.serviceIp!.split('.');
for (String element in itemList) { for (String element in itemList) {
serversList.add(int.parse(element)); serversList.add(int.parse(element));
@ -94,6 +105,11 @@ class ConfiguringWifiLogic extends BaseGetXController{
serversList.add(type2); serversList.add(type2);
} }
final StarChartRegisterNodeEntity? registerNodeEntity =
await Storage.getStarChartRegisterNodeInfo();
// app用户的peerId
String appPeerId = registerNodeEntity?.peer?.id ?? '';
final List<String> uidList = <String>[Storage.getUid().toString()]; final List<String> uidList = <String>[Storage.getUid().toString()];
IoSenderManage.senderConfiguringWifiCommand( IoSenderManage.senderConfiguringWifiCommand(
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
@ -108,6 +124,7 @@ class ConfiguringWifiLogic extends BaseGetXController{
needAuthor: 1, needAuthor: 1,
publicKey: publicKeyDataList, publicKey: publicKeyDataList,
privateKey: getPrivateKeyList, privateKey: getPrivateKeyList,
peerId: appPeerId,
); );
break; break;
@ -123,42 +140,51 @@ class ConfiguringWifiLogic extends BaseGetXController{
// wifi // wifi
Future<void> senderConfiguringWifiAction() async { Future<void> senderConfiguringWifiAction() async {
if(state.wifiNameController.text.isEmpty){ if (state.wifiNameController.text.isEmpty) {
showToast('请输入wifi名称'.tr); showToast('请输入wifi名称'.tr);
return; return;
} }
if(state.sureBtnState.value == 1){ if (state.sureBtnState.value == 1) {
return; return;
} }
state.sureBtnState.value = 1; state.sureBtnState.value = 1;
showEasyLoading(); showEasyLoading();
showBlueConnetctToastTimer(action: (){ showBlueConnetctToastTimer(action: () {
dismissEasyLoading(); dismissEasyLoading();
state.sureBtnState.value = 0; state.sureBtnState.value = 0;
}); });
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { BlueManage().blueSendData(BlueManage().connectDeviceName,
if (connectionState == BluetoothConnectionState.connected){ (BluetoothConnectionState connectionState) async {
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey); if (connectionState == BluetoothConnectionState.connected) {
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); final List<String>? privateKey =
await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList =
changeStringListToIntList(privateKey!);
final List<String>? publicKey = await Storage.getStringList(saveBluePublicKey); final List<String>? publicKey =
final List<int> publicKeyDataList = changeStringListToIntList(publicKey!); await Storage.getStringList(saveBluePublicKey);
final List<int> publicKeyDataList =
changeStringListToIntList(publicKey!);
final List<String>? token = await Storage.getStringList(saveBlueToken); final List<String>? token = await Storage.getStringList(saveBlueToken);
final List<int> getTokenList = changeStringListToIntList(token!); final List<int> getTokenList = changeStringListToIntList(token!);
final List<int> serversList = <int>[]; final List<int> serversList = <int>[];
for(int i = 0; i<state.configuringWifiEntity.value.data!.serviceList!.length; i++){ for (int i = 0;
final ServiceList item = state.configuringWifiEntity.value.data!.serviceList![i]; i < state.configuringWifiEntity.value.data!.serviceList!.length;
if(item.serviceIp!.contains('192')){ i++) {
final ServiceList item =
state.configuringWifiEntity.value.data!.serviceList![i];
if (item.serviceIp!.contains('192')) {
final List<String> itemList = item.serviceIp!.split('.'); final List<String> itemList = item.serviceIp!.split('.');
for (String element in itemList) { for (String element in itemList) {
serversList.add(int.parse(element)); serversList.add(int.parse(element));
} }
}else{ } else {
final List<InternetAddress> addresses = await InternetAddress.lookup(item.serviceIp!); final List<InternetAddress> addresses =
await InternetAddress.lookup(item.serviceIp!);
final List<String> itemList = addresses.first.address.split('.'); final List<String> itemList = addresses.first.address.split('.');
for (String element in itemList) { for (String element in itemList) {
serversList.add(int.parse(element)); serversList.add(int.parse(element));
@ -174,11 +200,17 @@ class ConfiguringWifiLogic extends BaseGetXController{
final String? uidStr = await Storage.getUid(); final String? uidStr = await Storage.getUid();
final List<String> uidList = <String>[uidStr.toString()]; final List<String> uidList = <String>[uidStr.toString()];
final StarChartRegisterNodeEntity? registerNodeEntity =
await Storage.getStarChartRegisterNodeInfo();
// app用户的peerId
String appPeerId = registerNodeEntity?.peer?.id ?? '';
IoSenderManage.senderConfiguringWifiCommand( IoSenderManage.senderConfiguringWifiCommand(
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
userID: await Storage.getUid(), userID: await Storage.getUid(),
ssid: state.wifiNameController.text, ssid: state.wifiNameController.text,
password: state.wifiPWDController.text, password: state.wifiPWDController.text,
peerId: appPeerId,
numberOfServers: state.configuringWifiEntity.value.data!.serviceNum, numberOfServers: state.configuringWifiEntity.value.data!.serviceNum,
listOfServers: serversList, listOfServers: serversList,
numberOfPhone: uidList.length, numberOfPhone: uidList.length,
@ -192,7 +224,7 @@ class ConfiguringWifiLogic extends BaseGetXController{
dismissEasyLoading(); dismissEasyLoading();
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
state.sureBtnState.value = 0; state.sureBtnState.value = 0;
if(state.ifCurrentScreen.value == true){ if (state.ifCurrentScreen.value == true) {
showBlueConnetctToast(); showBlueConnetctToast();
} }
} }
@ -200,6 +232,7 @@ class ConfiguringWifiLogic extends BaseGetXController{
} }
final NetworkInfo _networkInfo = NetworkInfo(); final NetworkInfo _networkInfo = NetworkInfo();
Future<String> getWifiName() async { Future<String> getWifiName() async {
String ssid = ''; String ssid = '';
ssid = (await _networkInfo.getWifiName())!; ssid = (await _networkInfo.getWifiName())!;
@ -211,17 +244,19 @@ class ConfiguringWifiLogic extends BaseGetXController{
/// ///
Future<bool> checkLocationPermission() async { Future<bool> checkLocationPermission() async {
final PermissionStatus value = await locationPermission(); 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; return allow;
} }
Future<PermissionStatus> locationPermission() async => Permission.location.request(); Future<PermissionStatus> locationPermission() async =>
Permission.location.request();
@override @override
void onReady() { void onReady() {
super.onReady(); super.onReady();
if(state.wifiName.value.isEmpty){ if (state.wifiName.value.isEmpty) {
getWifiName().then((String value) { getWifiName().then((String value) {
state.wifiNameController.text = value; state.wifiNameController.text = value;
}); });