This is my code:
Future<void> connectToWifi() async {
try {
if (Platform.isAndroid) {
isConnected = await WiFiForIoTPlugin.connect(
_vesselData['ssid'],
password: _vesselData['passphrase'],
security: NetworkSecurity.WPA,
// Enable Internet access
withInternet: false,
isHidden: true,
timeoutInSeconds: 10,
joinOnce: true,
);
// Force Android to treat Wi-Fi as the primary network using
await WiFiForIoTPlugin.forceWifiUsage(true);
} else if (Platform.isIOS){
isConnected = await WiFiForIoTPlugin.connect(
_vesselData['ssid'],
password: _vesselData['passphrase'],
security: NetworkSecurity.WPA,
isHidden: true,
timeoutInSeconds: 10,
// Ensures the connection remains persistent, preventing the system from disconnecting the device.
joinOnce: false,
);
}
if (isConnected) {
log("Connected to ${_vesselData['ssid']}");
streamData();
} else {
log("Failed to connect to ${_vesselData['ssid']}");
}
} catch (e) {
log("Error: $e");
}
}
Topic:
Community
SubTopic:
Apple Developers
Tags: