‘基本信息’页获取‘网络信号强度’
This commit is contained in:
parent
2f1135193b
commit
3c90758a5f
@ -39,6 +39,7 @@ class DeviceNetworkInfo {
|
||||
this.networkMac,
|
||||
this.secretKey,
|
||||
this.peerId,
|
||||
this.rssi,
|
||||
});
|
||||
|
||||
DeviceNetworkInfo.fromJson(dynamic json) {
|
||||
@ -46,12 +47,14 @@ class DeviceNetworkInfo {
|
||||
networkMac = json['networkMac'];
|
||||
secretKey = json['secretKey'];
|
||||
peerId = json['peerId'];
|
||||
rssi = json['rssi'];
|
||||
}
|
||||
|
||||
String? wifiName;
|
||||
String? networkMac;
|
||||
String? secretKey;
|
||||
String? peerId;
|
||||
String? rssi;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
@ -59,6 +62,7 @@ class DeviceNetworkInfo {
|
||||
map['networkMac'] = networkMac;
|
||||
map['secretKey'] = secretKey;
|
||||
map['peerId'] = peerId;
|
||||
map['rssi'] = rssi;
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,7 +142,10 @@ class _BasicInformationPageState extends State<BasicInformationPage> {
|
||||
visible: state.lockSetInfoData.value.lockFeature?.wifi == 1,
|
||||
child: CommonItem(
|
||||
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,
|
||||
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 deviceMac,
|
||||
required String networkMac,
|
||||
int? rssi,
|
||||
}) async {
|
||||
try {
|
||||
final LoginEntity entity = await ApiRepository.to.settingDeviceNetwork(
|
||||
@ -70,6 +71,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
||||
networkMac: networkMac,
|
||||
secretKey: secretKey,
|
||||
peerId: peerId,
|
||||
rssi: rssi,
|
||||
);
|
||||
return entity;
|
||||
} catch (e) {
|
||||
@ -140,6 +142,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
||||
String result = utf8String(secretKeyList);
|
||||
|
||||
AppLog.log('解析配网信息: $result');
|
||||
AppLog.log('使用传入的RSSI值: ${state.rssi.value}');
|
||||
|
||||
// 解析 JSON 字符串为 Map
|
||||
Map<String, dynamic> jsonMap = json.decode(result);
|
||||
@ -150,6 +153,12 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
||||
String? secretKey = jsonMap['secretKey'];
|
||||
String? deviceMac = jsonMap['deviceMac'];
|
||||
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 ||
|
||||
@ -166,6 +175,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
||||
secretKey: secretKey,
|
||||
deviceMac: deviceMac ?? '',
|
||||
networkMac: networkMac ?? '',
|
||||
rssi: rssi,
|
||||
);
|
||||
if (info.errorCode!.codeIsSuccessful) {
|
||||
// 设置锁的peerID
|
||||
@ -174,12 +184,15 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
||||
networkMac: networkMac,
|
||||
secretKey: secretKey,
|
||||
peerId: peerId,
|
||||
rssi: rssi.toString(),
|
||||
);
|
||||
|
||||
state.lockSetInfoData.value?.lockBasicInfo?.networkInfo?.peerId =
|
||||
peerId;
|
||||
state.lockSetInfoData.value?.lockBasicInfo?.networkInfo?.wifiName =
|
||||
wifiName;
|
||||
state.lockSetInfoData.value?.lockBasicInfo?.networkInfo?.rssi =
|
||||
rssi as int?;
|
||||
|
||||
/// 配网成功后,赋值锁的peerId
|
||||
StartChartManage().lockPeerId = peerId;
|
||||
@ -271,6 +284,13 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取当前WiFi信号强度
|
||||
int? currentRssi = await getCurrentWifiRssi();
|
||||
if (currentRssi != null) {
|
||||
state.rssi.value = currentRssi.toString();
|
||||
AppLog.log('当前WiFi信号强度: $currentRssi dBm');
|
||||
}
|
||||
|
||||
// 获取网关配置信息
|
||||
try {
|
||||
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 {
|
||||
final PermissionStatus value = await locationPermission();
|
||||
@ -432,6 +465,14 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
||||
void 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) {
|
||||
getWifiName().then((String value) {
|
||||
state.wifiNameController.text = value;
|
||||
|
||||
@ -6,6 +6,9 @@ import '../../lockSet/lockSetInfo_entity.dart';
|
||||
import 'configuringWifiEntity.dart';
|
||||
|
||||
class ConfiguringWifiState {
|
||||
// 网络信号
|
||||
final RxString rssi = ''.obs;
|
||||
|
||||
ConfiguringWifiState() {
|
||||
var map = Get.arguments;
|
||||
lockSetInfoData.value = map['lockSetInfoData'];
|
||||
|
||||
@ -100,6 +100,8 @@ class _WifiListPageState extends State<WifiListPage> {
|
||||
state.lockSetInfoData.value,
|
||||
'wifiName': wifiNameStr['wifiName'],
|
||||
'pageName': state.pageName.value,
|
||||
// 传递信号强度
|
||||
'rssi': wifiNameStr['rssi'],
|
||||
});
|
||||
});
|
||||
}),
|
||||
|
||||
@ -309,29 +309,33 @@ class NetworkInfo {
|
||||
this.peerId,
|
||||
this.isOnline,
|
||||
this.wifiName,
|
||||
this.rssi,
|
||||
});
|
||||
|
||||
NetworkInfo.fromJson(Map<String, dynamic> json) {
|
||||
peerId = json['peerId'];
|
||||
isOnline = json['isOnline'];
|
||||
wifiName = json['wifiName'];
|
||||
rssi = json['rssi'];
|
||||
}
|
||||
|
||||
String? peerId;
|
||||
String? wifiName;
|
||||
int? isOnline;
|
||||
int? rssi;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data['peerId'] = peerId;
|
||||
data['wifiName'] = wifiName;
|
||||
data['isOnline'] = isOnline;
|
||||
data['rssi'] = rssi;
|
||||
return data;
|
||||
}
|
||||
|
||||
@override
|
||||
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 secretKey,
|
||||
String peerId,
|
||||
int rssi,
|
||||
) =>
|
||||
post(
|
||||
deviceNetworkConfiguration.toUrl,
|
||||
@ -2392,6 +2393,7 @@ class ApiProvider extends BaseProvider {
|
||||
'networkMac': networkMac,
|
||||
'secretKey': secretKey,
|
||||
'peerId': peerId,
|
||||
'rssi': rssi,
|
||||
}));
|
||||
|
||||
/// 获取设备配网信息
|
||||
|
||||
@ -2362,8 +2362,9 @@ class ApiRepository {
|
||||
required String networkMac,
|
||||
required String secretKey,
|
||||
required String peerId,
|
||||
int? rssi,
|
||||
}) 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);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user