|
|
|
@ -4,6 +4,8 @@ import 'package:flutter_blue_plus/flutter_blue_plus.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:wifi_iot/wifi_iot.dart'; |
|
|
|
|
|
|
|
import '../../../core/utils/ftpconnect/ftpconnect.dart'; |
|
|
|
|
|
|
|
class MeetingConnectController extends GetxController { |
|
|
|
RxString stateStr = '搜索中...'.obs; |
|
|
|
RxBool isRescan = false.obs; |
|
|
|
@ -16,8 +18,8 @@ class MeetingConnectController extends GetxController { |
|
|
|
|
|
|
|
bool isScanFailed = false; |
|
|
|
|
|
|
|
late BluetoothCharacteristic? _writeCharacteristic; |
|
|
|
late StreamSubscription<List<int>>? _valueReceivedSubscription; |
|
|
|
BluetoothCharacteristic? _writeCharacteristic; |
|
|
|
StreamSubscription<List<int>>? _valueReceivedSubscription; |
|
|
|
|
|
|
|
String _wifiSSID = ''; |
|
|
|
String _wifiPassword = ''; |
|
|
|
@ -26,6 +28,8 @@ class MeetingConnectController extends GetxController { |
|
|
|
String _ftpAccount = ''; |
|
|
|
String _ftpPassword = ''; |
|
|
|
|
|
|
|
FTPConnect? _ftpConnect; |
|
|
|
|
|
|
|
@override |
|
|
|
void onInit() { |
|
|
|
super.onInit(); |
|
|
|
@ -56,6 +60,7 @@ class MeetingConnectController extends GetxController { |
|
|
|
_scanResultsSubscription.cancel(); |
|
|
|
_isScanningSubscription.cancel(); |
|
|
|
_valueReceivedSubscription?.cancel(); |
|
|
|
_ftpConnect?.disconnect(); |
|
|
|
_stopScan(); |
|
|
|
_disconnect(); |
|
|
|
super.onClose(); |
|
|
|
@ -86,6 +91,7 @@ class MeetingConnectController extends GetxController { |
|
|
|
} |
|
|
|
|
|
|
|
Future<void> _disconnect() async { |
|
|
|
await WiFiForIoTPlugin.forceWifiUsage(false); |
|
|
|
await WiFiForIoTPlugin.disconnect(); |
|
|
|
await _device?.disconnect(); |
|
|
|
} |
|
|
|
@ -131,7 +137,6 @@ class MeetingConnectController extends GetxController { |
|
|
|
} |
|
|
|
|
|
|
|
void _listenData(List<int> value) { |
|
|
|
print('----$value--------'); |
|
|
|
int command = value[2]; |
|
|
|
switch (command) { |
|
|
|
case 0x0d: // 是否有导入文件 |
|
|
|
@ -145,12 +150,12 @@ class MeetingConnectController extends GetxController { |
|
|
|
break; |
|
|
|
case 0x87: // Wi-Fi 开启/关闭 |
|
|
|
if (value[3] == 0x01 && value[4] == 0x01) { |
|
|
|
_getWifi(); |
|
|
|
sendData([0x5a, 0x01, 0x0b]); |
|
|
|
} |
|
|
|
break; |
|
|
|
case 0x0b: // WiFi 热点 SSID |
|
|
|
_wifiSSID = String.fromCharCodes(value.sublist(3, value.length - 2)); |
|
|
|
_connectWifi(); |
|
|
|
sendData([0x5a, 0x01, 0x0c]); |
|
|
|
break; |
|
|
|
case 0x0c: // WiFi 热点密码 |
|
|
|
_wifiPassword = _decodePassword(value); |
|
|
|
@ -176,11 +181,6 @@ class MeetingConnectController extends GetxController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void _getWifi() async { |
|
|
|
await sendData([0x5a, 0x01, 0x0b]); |
|
|
|
await sendData([0x5a, 0x01, 0x0c]); |
|
|
|
} |
|
|
|
|
|
|
|
void _connectWifi() async { |
|
|
|
if (_wifiSSID.isNotEmpty && _wifiPassword.isNotEmpty) { |
|
|
|
stateStr.value = '正在连接 Wi-Fi...'; |
|
|
|
@ -189,16 +189,29 @@ class MeetingConnectController extends GetxController { |
|
|
|
password: _wifiPassword, |
|
|
|
security: NetworkSecurity.WPA, |
|
|
|
); |
|
|
|
await WiFiForIoTPlugin.forceWifiUsage(true); |
|
|
|
stateStr.value = 'Wi-Fi 连接成功'; |
|
|
|
sendData([0x5a, 0x01, 0x03]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void _connectFtp() { |
|
|
|
void _connectFtp() async { |
|
|
|
if (_ftpAddress.isNotEmpty && |
|
|
|
_ftpPort.isNotEmpty && |
|
|
|
_ftpAccount.isNotEmpty && |
|
|
|
_ftpPassword.isNotEmpty) {} |
|
|
|
_ftpPassword.isNotEmpty) { |
|
|
|
_ftpConnect = FTPConnect( |
|
|
|
_ftpAddress, |
|
|
|
port: int.tryParse(_ftpPort) ?? 21, |
|
|
|
user: _ftpAccount, |
|
|
|
pass: _ftpPassword, |
|
|
|
); |
|
|
|
await _ftpConnect?.connect(); |
|
|
|
_ftpConnect?.listCommand = ListCommand.LIST; |
|
|
|
List<FTPEntry>? _listDirectory = |
|
|
|
await _ftpConnect?.listDirectoryContent(); |
|
|
|
print(_listDirectory); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
String _decodePassword(List<int> data) { |
|
|
|
|