flutternetwork / WiFiFlutter

Flutter plugin suite for various WiFi services.
https://wifi.flutternetwork.dev
283 stars 176 forks source link

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

Closed kbessemer closed 1 year ago

kbessemer commented 2 years ago

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() ) ); }

kbessemer commented 2 years ago

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.

daadu commented 2 years ago

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?

kbessemer commented 2 years ago
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)
kbessemer commented 2 years ago

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?

kbessemer commented 2 years ago

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();

daadu commented 2 years ago

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

kbessemer commented 2 years ago

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

daadu commented 2 years ago

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?

kbessemer commented 2 years ago

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

kbessemer commented 2 years ago

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

kbessemer commented 2 years ago

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, 
seikosantana commented 2 years ago

Having the same issue

kbessemer commented 2 years ago

Having the same issue

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

seikosantana commented 2 years ago

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.

kbessemer commented 2 years ago

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

hanlectin commented 2 years ago

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

daadu commented 2 years ago

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

daadu commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@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?

hanlectin commented 2 years ago

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

hanlectin commented 2 years ago

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

daadu commented 2 years ago

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.

seikosantana commented 2 years ago

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

hanlectin commented 2 years ago

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:

daadu commented 2 years ago

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 commented 2 years ago

@hanlectin I meant disabling network calls from your app.

daadu commented 2 years ago

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.

hanlectin commented 2 years ago

@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)

daadu commented 2 years ago

@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 commented 2 years ago

@hanlectin Sure, will let you know when there is clarity in what is wrong and patch is ready to test against Android 12 device. As of now I am unable to consistently reproduce the issue with Android 12 phone I have - as of now I think this is a non-issue on Android 12 (could be Pixel6 specific thing) - as I obsereved this issue only when my access point where app connected not sufficiently powered.

alexs-sentrytechnology commented 2 years ago

Hi - I get this issue on my pixel 6 pro running Android 12 also. Seems to be a pixel 6 think - my code runs successfully on other phones.

daadu commented 2 years ago

Sorry, I don't have Pixel 6 to test. Would encourage once who have it to debug the issue.

johnmaguire commented 1 year ago

I stumbled across this issue as I was thinking about an issue I experienced last year, which sounds exactly like this one, including running a Pixel 6 with Android 12. It was disappointing since it sort of rendered my app's value moot for me.

There is also this longstanding issue in the GoPro community... I believe the Pixel 6 has some issue inherent to it. Note the month from five months ago at https://community.gopro.com/s/question/0D53b00008Btpg7CAB/pixel6pro-on-android-12-wont-pair-with-hero4-or-session?language=en_US:

For those using Pixel 6, please know that there is still an observed connectivity issue. Our team is looking into it. We will post back fro updates. Thanks!

Martichou commented 1 year ago

Hey ! I'm not sure if anyone dig a bit deeper in this, but I tried.

(tested on a Pixel 6 with Android 13) What I discovered is that when you call connect (or findAndConnect, it doesn't matter), the Network object you get have an ID. Let's say that ID is 190. The issue come when you try to forceWifiUsage, the Network object that function use is 183 (number are just pure indication and may varies).

That issue only appears when you are already connected to another Wifi network before calling the connect method. It seems to be due to the fact that since Android 12, a device can be connected to multiple access points.

I've not yet found a correct way to fix this. For the moment my current workaround is to bindProcessToNetwork in the connect function (precisely in the connectTo function).

Someone have a better idea for a fix ?

daadu commented 1 year ago

@Martichou Thanks for the efforts.

Currently, we are not doing forceWifiUsage with connect by default, is because want to give this control to user when to enable or disable this network for communication.

What I suggest is to cache and use (within forceWifiUsage) Network object (if available) we get in onAvailable directly (will have to make sure that the objects is cleaned up properly if disconnected) inside connectTo. Can you try this and see if that issue is resolved. Unfortunately, I dont have any Android 13 or Pixel phone to test this.

Martichou commented 1 year ago

@daadu I know about the reasoning behind why you don't enforce the forceWifiUsage :).

I've just done as you recommended and it seems to work just fine. I was able to connect and to forceWifiUsage while staying connected to the previous AP. So the Pixel I had was connected to both AP at the same time and the APP was speaking to the one used in connect.

I will try to clean things up and ensure I clean the object correctly and then send a patch for you to review. Maybe we'll get a fix finally! 😉

darhaywa commented 1 year ago

@Martichou thanks for your solution I've put a PR in place with a tidied-up version.

@daadu could you take a look and let us know if there are any issues?

daadu commented 1 year ago

@darhaywa Thanks for the PR.

@Martichou Thanks for working on it.

daadu commented 1 year ago

This fix has landed on pub.dev with v0.3.18

@kbessemer Thank for reporting this. Check yourself here!

Closing this issue. Feel free to ask for re-opening if not resolved.