|
|
|
@ -2,6 +2,7 @@ import 'dart:async'; |
|
|
|
|
|
|
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:wifi_iot/wifi_iot.dart'; |
|
|
|
|
|
|
|
class MeetingConnectController extends GetxController { |
|
|
|
RxString stateStr = '搜索中...'.obs; |
|
|
|
@ -25,8 +26,6 @@ class MeetingConnectController extends GetxController { |
|
|
|
String _ftpAccount = ''; |
|
|
|
String _ftpPassword = ''; |
|
|
|
|
|
|
|
bool _isConnectWifi = false; |
|
|
|
|
|
|
|
@override |
|
|
|
void onInit() { |
|
|
|
super.onInit(); |
|
|
|
@ -87,6 +86,7 @@ class MeetingConnectController extends GetxController { |
|
|
|
} |
|
|
|
|
|
|
|
Future<void> _disconnect() async { |
|
|
|
await WiFiForIoTPlugin.disconnect(); |
|
|
|
await _device?.disconnect(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -158,15 +158,15 @@ class MeetingConnectController extends GetxController { |
|
|
|
break; |
|
|
|
case 0x03: // FTP 地址 |
|
|
|
_ftpAddress = String.fromCharCodes(value.sublist(3, value.length - 2)); |
|
|
|
_connectFtp(); |
|
|
|
sendData([0x5a, 0x01, 0x04]); |
|
|
|
break; |
|
|
|
case 0x04: // FTP 端口 |
|
|
|
_ftpPort = String.fromCharCodes(value.sublist(3, value.length - 2)); |
|
|
|
_connectFtp(); |
|
|
|
sendData([0x5a, 0x01, 0x05]); |
|
|
|
break; |
|
|
|
case 0x05: // FTP 账号 |
|
|
|
_ftpAccount = String.fromCharCodes(value.sublist(3, value.length - 2)); |
|
|
|
_connectFtp(); |
|
|
|
sendData([0x5a, 0x01, 0x06]); |
|
|
|
break; |
|
|
|
case 0x06: // FTP 密码 |
|
|
|
_ftpPassword = _decodePassword(value); |
|
|
|
@ -181,23 +181,21 @@ class MeetingConnectController extends GetxController { |
|
|
|
await sendData([0x5a, 0x01, 0x0c]); |
|
|
|
} |
|
|
|
|
|
|
|
void _getFtp() async { |
|
|
|
await sendData([0x5a, 0x01, 0x03]); |
|
|
|
await sendData([0x5a, 0x01, 0x04]); |
|
|
|
await sendData([0x5a, 0x01, 0x05]); |
|
|
|
await sendData([0x5a, 0x01, 0x06]); |
|
|
|
} |
|
|
|
|
|
|
|
void _connectWifi() { |
|
|
|
void _connectWifi() async { |
|
|
|
if (_wifiSSID.isNotEmpty && _wifiPassword.isNotEmpty) { |
|
|
|
_getFtp(); |
|
|
|
stateStr.value = '正在连接 Wi-Fi...'; |
|
|
|
await WiFiForIoTPlugin.connect( |
|
|
|
_wifiSSID, |
|
|
|
password: _wifiPassword, |
|
|
|
security: NetworkSecurity.WPA, |
|
|
|
); |
|
|
|
stateStr.value = 'Wi-Fi 连接成功'; |
|
|
|
sendData([0x5a, 0x01, 0x03]); |
|
|
|
} |
|
|
|
_connectFtp(); |
|
|
|
} |
|
|
|
|
|
|
|
void _connectFtp() { |
|
|
|
if (_isConnectWifi && |
|
|
|
_ftpAddress.isNotEmpty && |
|
|
|
if (_ftpAddress.isNotEmpty && |
|
|
|
_ftpPort.isNotEmpty && |
|
|
|
_ftpAccount.isNotEmpty && |
|
|
|
_ftpPassword.isNotEmpty) {} |
|
|
|
|