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.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<int>? 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!);

View File

@ -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<void> 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<void> updateNetworkInfo() async{
Future<void> 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<Reply> _replySubscription;
void _initReplySubscription() {
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
_replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
// WIFI配网结果
if(reply is SenderConfiguringWifiReply) {
if (reply is SenderConfiguringWifiReply) {
_replySenderConfiguringWifi(reply);
}
});
@ -59,7 +63,7 @@ class ConfiguringWifiLogic extends BaseGetXController{
Future<void> _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<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
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<int> publicKeyDataList = changeStringListToIntList(publicKey!);
final List<String>? publicKey =
await Storage.getStringList(saveBluePublicKey);
final List<int> publicKeyDataList =
changeStringListToIntList(publicKey!);
final List<int> tokenData = reply.data.sublist(7, 10);
final List<String> saveStrList = changeIntListToStringList(tokenData);
Storage.setStringList(saveBlueToken, saveStrList);
final List<int> serversList = <int>[];
for(int i = 0; i<state.configuringWifiEntity.value.data!.serviceList!.length; i++){
final ServiceList item = state.configuringWifiEntity.value.data!.serviceList![i];
for (int i = 0;
i < state.configuringWifiEntity.value.data!.serviceList!.length;
i++) {
final ServiceList item =
state.configuringWifiEntity.value.data!.serviceList![i];
final List<String> 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<String> uidList = <String>[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<void> 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<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState connectionState) async {
if (connectionState == BluetoothConnectionState.connected) {
final List<String>? privateKey =
await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList =
changeStringListToIntList(privateKey!);
final List<String>? publicKey = await Storage.getStringList(saveBluePublicKey);
final List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
final List<String>? publicKey =
await Storage.getStringList(saveBluePublicKey);
final List<int> publicKeyDataList =
changeStringListToIntList(publicKey!);
final List<String>? token = await Storage.getStringList(saveBlueToken);
final List<int> getTokenList = changeStringListToIntList(token!);
final List<int> serversList = <int>[];
for(int i = 0; i<state.configuringWifiEntity.value.data!.serviceList!.length; i++){
final ServiceList item = state.configuringWifiEntity.value.data!.serviceList![i];
if(item.serviceIp!.contains('192')){
for (int i = 0;
i < state.configuringWifiEntity.value.data!.serviceList!.length;
i++) {
final ServiceList item =
state.configuringWifiEntity.value.data!.serviceList![i];
if (item.serviceIp!.contains('192')) {
final List<String> itemList = item.serviceIp!.split('.');
for (String element in itemList) {
serversList.add(int.parse(element));
}
}else{
final List<InternetAddress> addresses = await InternetAddress.lookup(item.serviceIp!);
} else {
final List<InternetAddress> addresses =
await InternetAddress.lookup(item.serviceIp!);
final List<String> 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<String> uidList = <String>[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<String> getWifiName() async {
String ssid = '';
ssid = (await _networkInfo.getWifiName())!;
@ -211,17 +244,19 @@ class ConfiguringWifiLogic extends BaseGetXController{
///
Future<bool> 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<PermissionStatus> locationPermission() async => Permission.location.request();
Future<PermissionStatus> 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;
});