WiFiFlutter icon indicating copy to clipboard operation
WiFiFlutter copied to clipboard

[wifi_iot] On android 12 `findAndConnect` does not connect with provided ssid

Open mys10gan opened this issue 2 years ago • 3 comments

On android 12

bool connect = await WiFiForIoTPlugin.findAndConnect(ssid, joinOnce: true);

Always return false and never works. But works absolutely fine on Android 11. On Android 11 a pop up shows up searching for device... and eventually it gets connected. But on Android 12 nothing happens and suddenly wifi settings opens up.

Env

Oneplus 7t (oxygen os 12) Flutter version 3.7.7 compileSdkVersion 33 minSdkVersion 19

This code works on:

Oneplus 6t (LineageOS 20.0 - Android 13) Oneplus 6t (OxygenOS 11 - Android 11)

Perms

 <uses-permission android:name="android.permission.INTERNET"/>
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
 <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

mys10gan avatar Mar 09 '23 20:03 mys10gan

Can you confirm that the connect method works? issue might be with findAndConnect only - in this case use wifi_scan package to get list of SSIDs and use the connect method to connect (if this works in Android 12).

Methods like findAndConnect are in maintenance mode (check #229 ), connect method should be working - if that fails then please share some logs for debugging.

daadu avatar Mar 10 '23 03:03 daadu

Thank you for the reply. And yes connect method works. My application does connects automatically to the desired SSID but still the WiFi settings page opens up, this is a lil weird.

mys10gan avatar Mar 10 '23 15:03 mys10gan

This seems to be working, the problem was asynchronous nature of the code I have made and because http post was called async, the WiFiForIoTPlugin got .disconnected() just before the http post was done. This is always little harder to debug, but this time debugger worked easily. Dart is superb, most stuff can big jumped in and really works.

The problem was one missin await and thats all. In spite of long 40 years of experience in 10+ languages I am quite new in dart and random errors occur.

Android 12 1feb 2023

In my case connect works, I get into isConnected().then but I get always network unreachable error from flutter dio plugin, it works smoothly when wifi is setup from the Android setup menu. So it is not device network issue, it is 100% android or plugin issues. I connect as follows, android dialog does everything fine, connects and wifi icons shows the network connected

await WiFiForIoTPlugin.connect("ssid",password:"x2..", security:NetworkSecurity.WPA); await WiFiForIoTPlugin.forceWifiUsage(true);

TCP activities end up with the following: I/flutter (13128): =================== CAUGHT DART ERROR I/flutter (13128): catched Error : DioError [unknown]: null I/flutter (13128): Error: SocketException: Connection failed (OS Error: Network is unreachable, errno = 101), address = 192.168.4.1, port = 80

Tried another phone I/flutter (21652): catched Error : DioError [unknown]: null I/flutter (21652): Error: SocketException: Software caused connection abort (OS Error: Software caused connection abort, errno = 103), address = 192.168.4.1, port = 58890

actually we have seen the errors in both phones. IT IS NOT CONNECTIVITY ISSUES - everything work smoothly if we setup wifi manually from Android dialog before and disable wifiiotplugin,.connect from dart code

IF I ALLOW CONNECT TO THE SSID, android always answers with connected message, this dialog comes from Android OS not from the AP and after that the flutter app enters correctly into isConnexcted srtea

WiFiForIoTPlugin.isConnected().then((val) {

here I use dio. and the erros above occur

kadarpik avatar Mar 12 '23 22:03 kadarpik