WiFiFlutter icon indicating copy to clipboard operation
WiFiFlutter copied to clipboard

[wifi_iot] WiFi Connection not working on Pixel 6 Android 12

Open kyleb-app opened this issue 3 years ago • 37 comments

So far this plugin has worked on my iPad, and Lenovo Android 11 Tablet. But today I got a Pixel 6 Android 12 for further testing - it is behaving normally, it asks to join the correct network, and Android even shows a notification saying the connection is successful, but it does not actually connect to the network my app is telling it to.

bool result = await WiFiForIoTPlugin.connect(ssid, password: password, joinOnce: true, security: NetworkSecurity.WPA,); if (result) { WiFiForIoTPlugin.forceWifiUsage(true); Navigator.push( context, MaterialPageRoute( builder: (context) => Login() ) ); }

kyleb-app avatar Apr 19 '22 20:04 kyleb-app

If I manually connect to the WiFi network, then run my app, it works normally. I tried running the app with the WiFi network saved, but disconnected, did not work.

kyleb-app avatar Apr 19 '22 20:04 kyleb-app

Can you share logs, could be that the phone does not find the network "good" and would revert to older one - can you retry after forgetting old network?

daadu avatar Apr 20 '22 06:04 daadu

Launching lib/main.dart on Pixel 6 in debug mode...
Running Gradle task 'assembleDebug'...
✓  Built build/app/outputs/flutter-apk/app-debug.apk.
Debug service listening on ws://127.0.0.1:59935/MnTO7ilAoHQ=/ws
Syncing files to device Pixel 6...

======== Exception caught by rendering library =====================================================
The following assertion was thrown during layout:
A RenderFlex overflowed by 152 pixels on the right.

The relevant error-causing widget was: 
  Row Row:file:///Users/kylebessemer/development/github.com/kbessemer/flutter_analyzer/lib/components/connect.dart:198:37
The overflowing RenderFlex has an orientation of Axis.horizontal.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern. This is usually caused by the contents being too big for the RenderFlex.

Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be seen. If the content is legitimately bigger than the available space, consider clipping it with a ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView.

The specific RenderFlex in question is: RenderFlex#29b51 relayoutBoundary=up8 OVERFLOWING
...  parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
...  constraints: BoxConstraints(0.0<=w<=331.4, 0.0<=h<=Infinity)
...  size: Size(331.4, 24.0)
...  direction: horizontal
...  mainAxisAlignment: center
...  mainAxisSize: max
...  crossAxisAlignment: center
...  textDirection: ltr
...  verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
====================================================================================================

======== Exception caught by rendering library =====================================================
The following assertion was thrown during layout:
A RenderFlex overflowed by 149 pixels on the right.

The relevant error-causing widget was: 
  Row Row:file:///Users/kylebessemer/development/github.com/kbessemer/flutter_analyzer/lib/components/connect.dart:211:37
The overflowing RenderFlex has an orientation of Axis.horizontal.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern. This is usually caused by the contents being too big for the RenderFlex.

Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be seen. If the content is legitimately bigger than the available space, consider clipping it with a ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView.

The specific RenderFlex in question is: RenderFlex#8b35b relayoutBoundary=up8 OVERFLOWING
...  parentData: offset=Offset(0.0, 39.0); flex=null; fit=null (can use size)
...  constraints: BoxConstraints(0.0<=w<=331.4, 0.0<=h<=Infinity)
...  size: Size(331.4, 24.0)
...  direction: horizontal
...  mainAxisAlignment: center
...  mainAxisSize: max
...  crossAxisAlignment: center
...  textDirection: ltr
...  verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
====================================================================================================
I/OpenGLRenderer( 6841): Davey! duration=4476ms; Flags=1, FrameTimelineVsyncId=2998, IntendedVsync=48418156335, Vsync=48418156335, InputEventId=0, HandleInputStart=48418609438, AnimationStart=48418610618, PerformTraversalsStart=48418610984, DrawStart=48418997703, FrameDeadline=48434756335, FrameInterval=48418602195, FrameStartTime=16666667, SyncQueued=48419804628, SyncStart=48419834861, IssueDrawCommandsStart=48420246238, SwapBuffers=48426723858, FrameCompleted=52894633813, DequeueBufferDuration=1901042, QueueBufferDuration=713745, GpuCompleted=52894633813, SwapBuffersCompleted=48427476056, DisplayPresentTime=0, 
I/flutter ( 6841): MS_FeverWarn_b827eb3d791f
I/flutter ( 6841): fvrwrn_b827eb3d791f_ms
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F....ID 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)
D/InputMethodManager( 6841): showSoftInput() view=io.flutter.embedding.android.FlutterView{e292e0e VFE...... .F...... 0,0-1080,2358 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 6841): show(ime(), fromIme=true)

kyleb-app avatar Apr 20 '22 17:04 kyleb-app

Ok, so when I forget all wifi networks that are saved, the app with wifi_iot does connect me to the requested network successfully. Do you know of a better fix for this?

kyleb-app avatar Apr 20 '22 17:04 kyleb-app

I found the disconnect function in wifi_iot but it is not working for me.

Error: E/WifiIotPlugin(21026): Can't disconnect from WiFi, networkCallback and networkSuggestions is null.

Code: var disc = await WiFiForIoTPlugin.disconnect();

kyleb-app avatar Apr 20 '22 19:04 kyleb-app

@kbessemer disconnect() only works for network that are connected via connect()

daadu avatar Apr 21 '22 08:04 daadu

Ok, I understand. Is there any way to get this working on Android 12? Only work around I have found is to manually disconnect from my current wifi network before running my app that has wifi_iot

kyleb-app avatar Apr 21 '22 18:04 kyleb-app

Need to know the reason why Android is disconnecting, log you shared has no info about it. Can you check WiFi setting, do you see any setting that could disconnect "network that seems bad/poor" to Android?

daadu avatar Apr 22 '22 10:04 daadu

I do not see any settings that match this criteria in the phone. There are not many settings under WiFi, there is "Adaptive connectivity" I have tried disabling this with no success

kyleb-app avatar May 03 '22 17:05 kyleb-app

There are also no errors in the console when trying to connect to the WiFi network on the android 12 device

kyleb-app avatar May 03 '22 17:05 kyleb-app

Sorry for 3rd reply, wanted to show you how this is operating on android 12/pixel 6: http://kylebessemer.com/wifi.mp4

You can see that the WiFi connection shows as successful everytime I try to connect by android popup notification, but it is not actually joining the network. After the 2nd attempt I manually disconnect from my current WiFi network and then attempt to connect using the wifi_iot plugin again and it works that time.

I should add that the hotspot I am trying to connect to does not have internet access, it is an IoT device.

Below is the console log, the line with "address = 192.168.187.241" is from a failed API call to the backend on the IoT device, this is used to confirm connectivity with the device.

Launching lib/main.dart on Pixel 6 in debug mode...
Running Gradle task 'assembleDebug'...
✓  Built build/app/outputs/flutter-apk/app-debug.apk.
Installing build/app/outputs/flutter-apk/app.apk...
Debug service listening on ws://127.0.0.1:57055/3GU1Yl0Z-UA=/ws
Syncing files to device Pixel 6...
I/flutter (12680): MS_FeverWarn_b827eb3d791f
I/flutter (12680): MS_FeverWarn_b827eb3d791f
E/flutter (12680): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: SocketException: Software caused connection abort (OS Error: Software caused connection abort, errno = 103), address = 192.168.187.241, port = 35138
E/flutter (12680): #0      _NativeSocket.startConnect (dart:io-patch/socket_patch.dart:682:35)
E/flutter (12680): #1      _RawSocket.startConnect (dart:io-patch/socket_patch.dart:1817:26)
E/flutter (12680): #2      RawSocket.startConnect (dart:io-patch/socket_patch.dart:27:23)
E/flutter (12680): #3      Socket._startConnect (dart:io-patch/socket_patch.dart:2038:22)
E/flutter (12680): #4      Socket.startConnect (dart:io/socket.dart:792:21)
E/flutter (12680): #5      _ConnectionTarget.connect (dart:_http/http_impl.dart:2440:18)
E/flutter (12680): #6      _HttpClient._getConnection.connect (dart:_http/http_impl.dart:2834:12)
E/flutter (12680): #7      _HttpClient._getConnection (dart:_http/http_impl.dart:2839:12)
E/flutter (12680): #8      _HttpClient._openUrl (dart:_http/http_impl.dart:2698:12)
E/flutter (12680): #9      _HttpClient.openUrl (dart:_http/http_impl.dart:2570:7)
E/flutter (12680): #10     IOClient.send (package:http/src/io_client.dart:35:38)
E/flutter (12680): #11     BaseClient._sendUnstreamed (package:http/src/base_client.dart:93:38)
E/flutter (12680): #12     BaseClient.get (package:http/src/base_client.dart:27:7)
E/flutter (12680): #13     get.<anonymous closure> (package:http/http.dart:46:36)
E/flutter (12680): #14     _withClient (package:http/http.dart:164:20)
E/flutter (12680): #15     get (package:http/http.dart:46:5)
E/flutter (12680): #16     _ConnectState.PingGet (package:flutter_analyzer/components/connect.dart:82:17)
E/flutter (12680): #17     _ConnectState.PingHandler (package:flutter_analyzer/components/connect.dart:92:21)
E/flutter (12680): <asynchronous suspension>
E/flutter (12680): 
E/flutter (12680): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: SocketException: Software caused connection abort (OS Error: Software caused connection abort, errno = 103), address = 192.168.187.241, port = 35140
E/flutter (12680): #0      _NativeSocket.startConnect (dart:io-patch/socket_patch.dart:682:35)
E/flutter (12680): #1      _RawSocket.startConnect (dart:io-patch/socket_patch.dart:1817:26)
E/flutter (12680): #2      RawSocket.startConnect (dart:io-patch/socket_patch.dart:27:23)
E/flutter (12680): #3      Socket._startConnect (dart:io-patch/socket_patch.dart:2038:22)
E/flutter (12680): #4      Socket.startConnect (dart:io/socket.dart:792:21)
E/flutter (12680): #5      _ConnectionTarget.connect (dart:_http/http_impl.dart:2440:18)
E/flutter (12680): #6      _HttpClient._getConnection.connect (dart:_http/http_impl.dart:2834:12)
E/flutter (12680): #7      _HttpClient._getConnection (dart:_http/http_impl.dart:2839:12)
E/flutter (12680): #8      _HttpClient._openUrl (dart:_http/http_impl.dart:2698:12)
E/flutter (12680): #9      _HttpClient.openUrl (dart:_http/http_impl.dart:2570:7)
E/flutter (12680): #10     IOClient.send (package:http/src/io_client.dart:35:38)
E/flutter (12680): #11     BaseClient._sendUnstreamed (package:http/src/base_client.dart:93:38)
E/flutter (12680): #12     BaseClient.get (package:http/src/base_client.dart:27:7)
E/flutter (12680): #13     get.<anonymous closure> (package:http/http.dart:46:36)
E/flutter (12680): #14     _withClient (package:http/http.dart:164:20)
E/flutter (12680): #15     get (package:http/http.dart:46:5)
E/flutter (12680): #16     _ConnectState.PingGet (package:flutter_analyzer/components/connect.dart:82:17)
E/flutter (12680): #17     _ConnectState.PingHandler (package:flutter_analyzer/components/connect.dart:92:21)
E/flutter (12680): <asynchronous suspension>
E/flutter (12680): 
I/OpenGLRenderer(12680): Davey! duration=79454ms; Flags=1, FrameTimelineVsyncId=23004, IntendedVsync=332622070017, Vsync=332622070017, InputEventId=0, HandleInputStart=332622291950, AnimationStart=332622293130, PerformTraversalsStart=332622293618, DrawStart=332622656859, FrameDeadline=332655336684, FrameInterval=332622285358, FrameStartTime=16666667, SyncQueued=332623080117, SyncStart=332623099893, IssueDrawCommandsStart=332623365070, SwapBuffers=332630632363, FrameCompleted=412076406491, DequeueBufferDuration=813720, QueueBufferDuration=618245, GpuCompleted=412076406491, SwapBuffersCompleted=332631287677, DisplayPresentTime=0, 
I/flutter (12680): MS_FeverWarn_b827eb3d791f
I/OpenGLRenderer(12680): Davey! duration=50742ms; Flags=0, FrameTimelineVsyncId=29223, IntendedVsync=366240170005, Vsync=366240170005, InputEventId=1049296413, HandleInputStart=366240751968, AnimationStart=366240753392, PerformTraversalsStart=366240838272, DrawStart=366248494969, FrameDeadline=366267881116, FrameInterval=366240747492, FrameStartTime=11111111, SyncQueued=366248696751, SyncStart=366248736139, IssueDrawCommandsStart=366248801854, SwapBuffers=366253935195, FrameCompleted=416982897663, DequeueBufferDuration=2401001, QueueBufferDuration=355551, GpuCompleted=416982897663, SwapBuffersCompleted=366254963841, DisplayPresentTime=0, 

kyleb-app avatar May 03 '22 20:05 kyleb-app

Having the same issue

seikosantana avatar May 05 '22 15:05 seikosantana

Having the same issue

Are you using a Pixel 6 phone? Or is it a different phone model also running Android 12?

kyleb-app avatar May 05 '22 21:05 kyleb-app

it's a different phone, and it's android 10, but i managed to solve it with what's mentioned in https://github.com/flutternetwork/WiFiFlutter/issues/247

From my inspection, yes it successfully made connection, but wasn't able to reach LAN, which is needed in my case, to communicate with the IoT device. so I do put

await forceWifiUsage(true);

after a successful connection and network traffic to the LAN will then be routed.

seikosantana avatar May 06 '22 13:05 seikosantana

Ok, that is not the issue I am facing. I am already using forceWifiUsage. Works perfectly on Android 11 but not 12

kyleb-app avatar May 06 '22 14:05 kyleb-app

I can confirm the very same behavior: works on all configurations I tried, except Pixel 6 and Android 12

hanlectin avatar May 16 '22 07:05 hanlectin

@kbessemer I will test on Android 12, and get back.

daadu avatar May 16 '22 08:05 daadu

Looks like some APIs are deprecated in SDK 31 (Android 12) - https://developer.android.com/about/versions/12/behavior-changes-12#concurrent-connections

I am working on it, will open a PR when ready with patch - urge all to test against that PR with as many devices as possible (different versions, vendors, etc).

daadu avatar May 16 '22 08:05 daadu

I am failing to reproduce the issue with Android 12 phone(iQOO 9 SE) with the latest version of wifi_iot on pub.dev.

daadu avatar May 16 '22 11:05 daadu

@kbessemer @hanlectin have done some implementation changes at #283, can you verify that this fixes the problem (highly unlikely though).

I don't have a Pixel 6 phone to test this against.

Also can you verify the issue is not with WiFi deivce end, like "rebooting" after the device connects to it or something?

Have you added android:usesCleartextTraffic="true" to AndroidManifest.xml file for HTTP (unsecure) traffic to be allowed?

daadu avatar May 16 '22 11:05 daadu

sorry, I can't test at the moment. but I can confirm what I tried yesterday:

  • used wifi_scan 0.2.1 (not 0.3.0 yet)
  • SSID was WPA secure
  • using: await WiFiForIoTPlugin.connect(ssid, password: '12345678', joinOnce: true, security: NetworkSecurity.WPA, withInternet: false);
  • returns with "Connected OK" toast (similar text)
  • ...but there is no connection to target (192.168.4.1) ==> I need to connect to the above SSID in Internet/WiFi -> then it works! (last step is NOT necessary on < Android 12). it works right after calling WiFiForIoTPlugin.connect()

hanlectin avatar May 16 '22 12:05 hanlectin

I'll test with wifi_scan v0.3.0 and/or android:usesCleartextTraffic="true" later today...

hanlectin avatar May 16 '22 12:05 hanlectin

I found some way to reproduce it with a production app I built that uses this lib. Following are my notes about it.

Firstly, The issue does not come up with the current version of the app on the PlayStore - on the Android 12 device I mentioned above - my hunch is - because it was compiled with SDK version 30 (set by flutter.sdkComplieVersion in Flutter v2.10.5) - wifi_iot version was `0.3.15+2 (I am sure that the issue is not in the current version as well - as the change has nothing to do with it)

When complied with Flutter v3.0.0 with compile SDK 31 - the issue starts coming (I tried with debug, release and release-with-obfuscation builds). I noticed, when the app is connected to the IoT device, if there is any other traffic (In my case I call "sync API" to our the server when device "resumes", therefore each time the dialogue of "should connect?" comes up - this network calls are made), I saw what @kbessemer posted above in video link - "connection is successful" but the subsequent "HTTP call" fails - I was able to solve the issue by disabling all other traffic when "connecting and communication" with my IoT device.

I observed that the WiFi service in Android phone kept "restarting", when there was such "mix traffic" (internet calls or device calls), not sure what the reason could be and what could be the "real fix" for it.

@kbessemer @seikosantana @hanlectin Can you guys confirm this behaviour - do you have such "mix traffic" at the same time - can disabling "internet requests" when making "requests to device" fix it? and/or does reverting to flutter v2.10.5 (and compile SDK to 30) also fix the problem? Please let me know.

daadu avatar May 16 '22 13:05 daadu

I don't have Android 12 device but i'll try compiling to SDK Level 31

seikosantana avatar May 16 '22 13:05 seikosantana

I don't know how to disable "internet requests"?! Lot's of apps installed. Surely many of these try to connect whenever there's a chance ;( My "wifi_scan" app was until yesterday using flutter 2.10.x. since yesterday 3.0.0: no difference there!

facts/summarize:

  • WiFi connected to IoT device (via system settings), cellular data disabled: --> connection OK, (wifi_scan not used/not necessary)
  • WiFi connected to IoT device (via system settings), cellular data enabled: --> need wifi_scan WiFiForIoTPlugin.forceWifiUsage(true) - otherwise app tries to connect via cellular data
  • WiFi connected to internet-connected AP --> need wifi_scan WiFiForIoTPlugin.connect() & WiFiForIoTPlugin.forceWifiUsage(true)
    ==> this works with many/all(?) combinations, but NOT with Android12/Pixel6 (while WiFiForIoTPlugin is in use and connected to the IoT device, the previous internet-WiFi is not working; however, I think I recently read that with Android 13 it might be possible to keep two (or more) WiFi connections in parallel. on supported hardware. unfortunately I can't find that article at the moment...)

hanlectin avatar May 17 '22 07:05 hanlectin

I have wrapped forceWifiUsage around an HTTP client

class _WifiForcedClient extends http.BaseClient {
  _WifiForcedClient(this._inner);

  final http.Client _inner;

  Future<void> _forceWifiUsage(bool force, {String logTag = ""}) async {
    logTag += ": _forceWifiUsage($force)";

    try {
      print("$logTag: started");
      await WiFiForIoTPlugin.forceWifiUsage(force);
      print("$logTag: done");
    } catch (e, s) {
      print("$logTag: failed $e, $s");
    }
  }

  @override
  Future<http.StreamedResponse> send(http.BaseRequest request) async {
    try {
      //  enable - force wifi usage
      await _forceWifiUsage(true, logTag: "_WifiForcedClient");

      // call send on inner client
      return await _inner.send(request);
    } finally {
      //  disable - force wifi usage
      await _forceWifiUsage(false, logTag: "_WifiForcedClient");
    }
  }
}

I use this client to make all HTTP calls via AP connected by my app, rest I use normal client.

I think in your case, you will have to disable forceWifiUsage back when you try to make "calls to the internet" - usin g the above client will help you organise traffic properly.

daadu avatar May 17 '22 07:05 daadu

@hanlectin I meant disabling network calls from your app.

daadu avatar May 17 '22 07:05 daadu

I think I recently read that with Android 13 it might be possible to keep two (or more) WiFi connections in parallel. on supported hardware. unfortunately I can't find that article at the moment...)

@hanlectin Android 13 will support such multiple connections, but will be left to device vendor to support it at Wifi driver/firmware level.

daadu avatar May 17 '22 07:05 daadu

@hanlectin I meant disabling network calls from your app.

thanks. sure. understood... FYI: my application is different: my app connects to a measurement-device that sends data (and can be controlled) via WiFi (it provides a WiFi hotspot). most of the time, this device will come with a dedicated/bundled android phone/tablet as a controller. in that case the phone will never need to access the internet at all... (here I can easily configure only one WiFi connection in system-settings and keep it that way) also sometimes, one phone should operate multiple measurement-devices. so fast switching devices from wihtin the app (using wifi_scan) is a real benefit. and works fine. possible even with Android 12 as there will not be any mobile data enabled on the phone running the app. during development (and for testing) I sometimes use my own phone (Pixel 6). here I found the problems... --> however, at the end, the currenly observed Android 12 issues are not a deal-breaker for my purpose, as we won't be using Pixel6/Android12 devices bundled with the mwasurement devices. It's currently more or less personal interest to also have it running on Pixel6, too - as I don't really see why it shouldn't work here too... maybe there will be a future need to really have it working on a Pixel6/Android12... but for now: not (very) important!

nevertheless: thanks a lot for your efforts!!! (and please let me know if I can test anything if there's an update available)

hanlectin avatar May 17 '22 08:05 hanlectin

@kbessemer Some observation,

I got Software caused connection abort error, when the IoT device reboots (because of brownout - low power) after connection is made and device tries to make network request.

I can fix these when device is connected to proper power source (5V 2A adapter).

daadu avatar May 17 '22 08:05 daadu