‘基本信息’页获取‘网络信号强度’
This commit is contained in:
parent
2f1135193b
commit
3c90758a5f
@ -39,6 +39,7 @@ class DeviceNetworkInfo {
|
|||||||
this.networkMac,
|
this.networkMac,
|
||||||
this.secretKey,
|
this.secretKey,
|
||||||
this.peerId,
|
this.peerId,
|
||||||
|
this.rssi,
|
||||||
});
|
});
|
||||||
|
|
||||||
DeviceNetworkInfo.fromJson(dynamic json) {
|
DeviceNetworkInfo.fromJson(dynamic json) {
|
||||||
@ -46,12 +47,14 @@ class DeviceNetworkInfo {
|
|||||||
networkMac = json['networkMac'];
|
networkMac = json['networkMac'];
|
||||||
secretKey = json['secretKey'];
|
secretKey = json['secretKey'];
|
||||||
peerId = json['peerId'];
|
peerId = json['peerId'];
|
||||||
|
rssi = json['rssi'];
|
||||||
}
|
}
|
||||||
|
|
||||||
String? wifiName;
|
String? wifiName;
|
||||||
String? networkMac;
|
String? networkMac;
|
||||||
String? secretKey;
|
String? secretKey;
|
||||||
String? peerId;
|
String? peerId;
|
||||||
|
String? rssi;
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
final map = <String, dynamic>{};
|
final map = <String, dynamic>{};
|
||||||
@ -59,6 +62,7 @@ class DeviceNetworkInfo {
|
|||||||
map['networkMac'] = networkMac;
|
map['networkMac'] = networkMac;
|
||||||
map['secretKey'] = secretKey;
|
map['secretKey'] = secretKey;
|
||||||
map['peerId'] = peerId;
|
map['peerId'] = peerId;
|
||||||
|
map['rssi'] = rssi;
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -142,7 +142,10 @@ class _BasicInformationPageState extends State<BasicInformationPage> {
|
|||||||
visible: state.lockSetInfoData.value.lockFeature?.wifi == 1,
|
visible: state.lockSetInfoData.value.lockFeature?.wifi == 1,
|
||||||
child: CommonItem(
|
child: CommonItem(
|
||||||
leftTitel: '网络信号强度'.tr,
|
leftTitel: '网络信号强度'.tr,
|
||||||
rightTitle: '-',
|
rightTitle: state.lockSetInfoData.value.lockBasicInfo?.networkInfo?.rssi != null
|
||||||
|
? '${rssiToPercentage(state.lockSetInfoData.value.lockBasicInfo?.networkInfo?.rssi)}'
|
||||||
|
'%(${state.lockSetInfoData.value.lockBasicInfo?.networkInfo?.rssi}dBm)'
|
||||||
|
: '-',
|
||||||
allHeight: 70.h,
|
allHeight: 70.h,
|
||||||
isHaveLine: true,
|
isHaveLine: true,
|
||||||
),
|
),
|
||||||
@ -226,4 +229,12 @@ class _BasicInformationPageState extends State<BasicInformationPage> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int rssiToPercentage(int? rssi) {
|
||||||
|
if (rssi == null) return 0;
|
||||||
|
// 限制RSSI值在合理范围内
|
||||||
|
int clampedRssi = rssi.clamp(-100, -30);
|
||||||
|
// 线性映射: percentage = (rssi + 100) * 100 / 70
|
||||||
|
return ((clampedRssi + 100) * 100 ~/ 70).clamp(0, 100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,6 +61,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
required String secretKey,
|
required String secretKey,
|
||||||
required String deviceMac,
|
required String deviceMac,
|
||||||
required String networkMac,
|
required String networkMac,
|
||||||
|
int? rssi,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
final LoginEntity entity = await ApiRepository.to.settingDeviceNetwork(
|
final LoginEntity entity = await ApiRepository.to.settingDeviceNetwork(
|
||||||
@ -70,6 +71,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
networkMac: networkMac,
|
networkMac: networkMac,
|
||||||
secretKey: secretKey,
|
secretKey: secretKey,
|
||||||
peerId: peerId,
|
peerId: peerId,
|
||||||
|
rssi: rssi,
|
||||||
);
|
);
|
||||||
return entity;
|
return entity;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -140,6 +142,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
String result = utf8String(secretKeyList);
|
String result = utf8String(secretKeyList);
|
||||||
|
|
||||||
AppLog.log('解析配网信息: $result');
|
AppLog.log('解析配网信息: $result');
|
||||||
|
AppLog.log('使用传入的RSSI值: ${state.rssi.value}');
|
||||||
|
|
||||||
// 解析 JSON 字符串为 Map
|
// 解析 JSON 字符串为 Map
|
||||||
Map<String, dynamic> jsonMap = json.decode(result);
|
Map<String, dynamic> jsonMap = json.decode(result);
|
||||||
@ -150,6 +153,12 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
String? secretKey = jsonMap['secretKey'];
|
String? secretKey = jsonMap['secretKey'];
|
||||||
String? deviceMac = jsonMap['deviceMac'];
|
String? deviceMac = jsonMap['deviceMac'];
|
||||||
String? networkMac = jsonMap['networkMac'];
|
String? networkMac = jsonMap['networkMac'];
|
||||||
|
int? rssi = jsonMap['rssi'];
|
||||||
|
|
||||||
|
// 如果解析出的RSSI为空,则使用当前获取的RSSI
|
||||||
|
if (rssi == null && state.rssi.value.isNotEmpty) {
|
||||||
|
rssi = int.tryParse(state.rssi.value);
|
||||||
|
}
|
||||||
|
|
||||||
// 验证关键字段
|
// 验证关键字段
|
||||||
if (peerId == null ||
|
if (peerId == null ||
|
||||||
@ -166,6 +175,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
secretKey: secretKey,
|
secretKey: secretKey,
|
||||||
deviceMac: deviceMac ?? '',
|
deviceMac: deviceMac ?? '',
|
||||||
networkMac: networkMac ?? '',
|
networkMac: networkMac ?? '',
|
||||||
|
rssi: rssi,
|
||||||
);
|
);
|
||||||
if (info.errorCode!.codeIsSuccessful) {
|
if (info.errorCode!.codeIsSuccessful) {
|
||||||
// 设置锁的peerID
|
// 设置锁的peerID
|
||||||
@ -174,12 +184,15 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
networkMac: networkMac,
|
networkMac: networkMac,
|
||||||
secretKey: secretKey,
|
secretKey: secretKey,
|
||||||
peerId: peerId,
|
peerId: peerId,
|
||||||
|
rssi: rssi.toString(),
|
||||||
);
|
);
|
||||||
|
|
||||||
state.lockSetInfoData.value?.lockBasicInfo?.networkInfo?.peerId =
|
state.lockSetInfoData.value?.lockBasicInfo?.networkInfo?.peerId =
|
||||||
peerId;
|
peerId;
|
||||||
state.lockSetInfoData.value?.lockBasicInfo?.networkInfo?.wifiName =
|
state.lockSetInfoData.value?.lockBasicInfo?.networkInfo?.wifiName =
|
||||||
wifiName;
|
wifiName;
|
||||||
|
state.lockSetInfoData.value?.lockBasicInfo?.networkInfo?.rssi =
|
||||||
|
rssi as int?;
|
||||||
|
|
||||||
/// 配网成功后,赋值锁的peerId
|
/// 配网成功后,赋值锁的peerId
|
||||||
StartChartManage().lockPeerId = peerId;
|
StartChartManage().lockPeerId = peerId;
|
||||||
@ -271,6 +284,13 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取当前WiFi信号强度
|
||||||
|
int? currentRssi = await getCurrentWifiRssi();
|
||||||
|
if (currentRssi != null) {
|
||||||
|
state.rssi.value = currentRssi.toString();
|
||||||
|
AppLog.log('当前WiFi信号强度: $currentRssi dBm');
|
||||||
|
}
|
||||||
|
|
||||||
// 获取网关配置信息
|
// 获取网关配置信息
|
||||||
try {
|
try {
|
||||||
final GetGatewayConfigurationEntity entity = await ApiRepository.to
|
final GetGatewayConfigurationEntity entity = await ApiRepository.to
|
||||||
@ -417,6 +437,19 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 获取当前WiFi信号强度
|
||||||
|
Future<int?> getCurrentWifiRssi() async {
|
||||||
|
try {
|
||||||
|
if (state.rssi.value.isNotEmpty) {
|
||||||
|
return int.tryParse(state.rssi.value);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} catch (e) {
|
||||||
|
AppLog.log('获取WiFi信号强度失败: $e');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///定位权限
|
///定位权限
|
||||||
Future<bool> checkLocationPermission() async {
|
Future<bool> checkLocationPermission() async {
|
||||||
final PermissionStatus value = await locationPermission();
|
final PermissionStatus value = await locationPermission();
|
||||||
@ -432,6 +465,14 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
void onReady() {
|
void onReady() {
|
||||||
super.onReady();
|
super.onReady();
|
||||||
|
|
||||||
|
// 获取网络信号
|
||||||
|
final arguments = Get.arguments;
|
||||||
|
if (arguments != null) {
|
||||||
|
if (arguments['rssi'] != null) {
|
||||||
|
state.rssi.value = arguments['rssi'].toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|||||||
@ -6,6 +6,9 @@ import '../../lockSet/lockSetInfo_entity.dart';
|
|||||||
import 'configuringWifiEntity.dart';
|
import 'configuringWifiEntity.dart';
|
||||||
|
|
||||||
class ConfiguringWifiState {
|
class ConfiguringWifiState {
|
||||||
|
// 网络信号
|
||||||
|
final RxString rssi = ''.obs;
|
||||||
|
|
||||||
ConfiguringWifiState() {
|
ConfiguringWifiState() {
|
||||||
var map = Get.arguments;
|
var map = Get.arguments;
|
||||||
lockSetInfoData.value = map['lockSetInfoData'];
|
lockSetInfoData.value = map['lockSetInfoData'];
|
||||||
|
|||||||
@ -100,6 +100,8 @@ class _WifiListPageState extends State<WifiListPage> {
|
|||||||
state.lockSetInfoData.value,
|
state.lockSetInfoData.value,
|
||||||
'wifiName': wifiNameStr['wifiName'],
|
'wifiName': wifiNameStr['wifiName'],
|
||||||
'pageName': state.pageName.value,
|
'pageName': state.pageName.value,
|
||||||
|
// 传递信号强度
|
||||||
|
'rssi': wifiNameStr['rssi'],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|||||||
@ -309,29 +309,33 @@ class NetworkInfo {
|
|||||||
this.peerId,
|
this.peerId,
|
||||||
this.isOnline,
|
this.isOnline,
|
||||||
this.wifiName,
|
this.wifiName,
|
||||||
|
this.rssi,
|
||||||
});
|
});
|
||||||
|
|
||||||
NetworkInfo.fromJson(Map<String, dynamic> json) {
|
NetworkInfo.fromJson(Map<String, dynamic> json) {
|
||||||
peerId = json['peerId'];
|
peerId = json['peerId'];
|
||||||
isOnline = json['isOnline'];
|
isOnline = json['isOnline'];
|
||||||
wifiName = json['wifiName'];
|
wifiName = json['wifiName'];
|
||||||
|
rssi = json['rssi'];
|
||||||
}
|
}
|
||||||
|
|
||||||
String? peerId;
|
String? peerId;
|
||||||
String? wifiName;
|
String? wifiName;
|
||||||
int? isOnline;
|
int? isOnline;
|
||||||
|
int? rssi;
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
final Map<String, dynamic> data = <String, dynamic>{};
|
final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
data['peerId'] = peerId;
|
data['peerId'] = peerId;
|
||||||
data['wifiName'] = wifiName;
|
data['wifiName'] = wifiName;
|
||||||
data['isOnline'] = isOnline;
|
data['isOnline'] = isOnline;
|
||||||
|
data['rssi'] = rssi;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'NetworkInfo{peerId: $peerId, wifiName: $wifiName, isOnline: $isOnline}';
|
return 'NetworkInfo{peerId: $peerId, wifiName: $wifiName, isOnline: $isOnline, rssi: $rssi}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2382,6 +2382,7 @@ class ApiProvider extends BaseProvider {
|
|||||||
String networkMac,
|
String networkMac,
|
||||||
String secretKey,
|
String secretKey,
|
||||||
String peerId,
|
String peerId,
|
||||||
|
int rssi,
|
||||||
) =>
|
) =>
|
||||||
post(
|
post(
|
||||||
deviceNetworkConfiguration.toUrl,
|
deviceNetworkConfiguration.toUrl,
|
||||||
@ -2392,6 +2393,7 @@ class ApiProvider extends BaseProvider {
|
|||||||
'networkMac': networkMac,
|
'networkMac': networkMac,
|
||||||
'secretKey': secretKey,
|
'secretKey': secretKey,
|
||||||
'peerId': peerId,
|
'peerId': peerId,
|
||||||
|
'rssi': rssi,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
/// 获取设备配网信息
|
/// 获取设备配网信息
|
||||||
|
|||||||
@ -2362,8 +2362,9 @@ class ApiRepository {
|
|||||||
required String networkMac,
|
required String networkMac,
|
||||||
required String secretKey,
|
required String secretKey,
|
||||||
required String peerId,
|
required String peerId,
|
||||||
|
int? rssi,
|
||||||
}) async {
|
}) async {
|
||||||
final res = await apiProvider.settingDeviceNetwork(deviceType, deviceMac, wifiName, networkMac, secretKey, peerId);
|
final res = await apiProvider.settingDeviceNetwork(deviceType, deviceMac, wifiName, networkMac, secretKey, peerId, rssi!);
|
||||||
return LoginEntity.fromJson(res.body);
|
return LoginEntity.fromJson(res.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user