Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to communicate on network when connected with no internet for android 11 and higher #352

Open
aminebagga opened this issue Oct 17, 2023 · 14 comments

Comments

@aminebagga
Copy link

wifi_iot 0.3.18+1
withInternet false
android 12

I connect to an AP with no internet so withInternet = false, I accept the popup to connect to the wifi
then I can see a brief connected popup.
After the connect API I also call forceWifiUsage(true)
From the AP I can see that my phone is connected and I can even ping it
adb shell commands show also that I'm connected to the asked wifi

adb shell cmd wifi status
Wifi is enabled
Wifi scanning is always available
==== Primary ClientModeManager instance ====
Wifi is connected to "XXXXXXXXX"
WifiInfo: SSID: "XXXXXXXXX", BSSID: XX:XX:XX:XX:XX:XX, MAC: YY:YY:YY:YY:YY:YY, Security type: 2, Supplicant state: COMPLETED, Wi-Fi standard: 4, RSSI: -50, Link speed: 65Mbps, Tx Link speed: 65Mbps, Max Supported Tx Link speed: 72Mbps, Rx Link speed: 65Mbps, Max Supported Rx Link speed: 72Mbps, Frequency: 2437MHz, Net ID: 85, Metered hint: false, score: 0, CarrierMerged: false, SubscriptionId: -1, IsPrimary: 1
successfulTxPackets: 16
successfulTxPacketsPerSecond: 3.3097908512005812E-6
retriedTxPackets: 1
retriedTxPacketsPerSecond: 1.707389040735719E-21
lostTxPackets: 0
lostTxPacketsPerSecond: 0.0
successfulRxPackets: 3
successfulRxPacketsPerSecond: 6.709064673536853E-23

adb shell ifconfig
rmnet_ipa0 Link encap:UNSPEC  
          UP RUNNING  MTU:9216  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:0 TX bytes:0 

lo        Link encap:UNSPEC  
          inet addr:127.0.0.1  Mask:255.0.0.0 
          inet6 addr: ::1/128 Scope: Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:2268703 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:2268703 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:1795765448 TX bytes:1795765448 

wlan0     Link encap:UNSPEC    Driver icnss
          inet addr:192.168.0.10  Bcast:192.168.0.255  Mask:255.255.255.0 
          inet6 addr: XXXX::XXX:XXXX:XXXX:XXXX/64 Scope: Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:753808 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:160800 errors:0 dropped:7 overruns:0 carrier:0 
          collisions:0 txqueuelen:3000 
          RX bytes:872186321 TX bytes:64962198 

dummy0    Link encap:UNSPEC  
          inet6 addr: XXXX::XXXX:XXXX:XXXX:XXXX/64 Scope: Link
          UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:42 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:0 TX bytes:2940 

All seems to be ok, but I'm not able to communicate on the network, not even able to ping the gateway

adb shell ping 192.168.0.1
connect: Network is unreachable

Http requests failed with 111 errno

I/flutter ( 1481): Error: SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 192.168.0.10, port = 40148

If my understanding of the android wifi specifications is correct, android offer 3 APIs to connect to wifi

  • Suggestion API : To connect to a classif AP wifi with internet connection. This is implemented when we use wifi_iot connect with "withInternet" set to true.
  • Network request API: A peer to peer connection. This is implemented when we use wifi_iot connect with "withInternet" set to false. But to use this mode we cannot connect to classic AP. We should rather connect directly to the device that should support the P2P mode.
  • ACTION_WIFI_ADD_NETWORKS API: To connect to an AP with user approval. This is what I'm looking for and this mode should solve my problem. But I'm not able to make it work. When I look into the wifi_iot code I can see that "registerWifiNetwork" fullfill android requirement to use this mode but I'm always getting false when I call registerWifiNetwork.

Anyone can help to make it work please ? Any suggestations ? Should we really use registerWifiNetwork and how ?

@aminebagga
Copy link
Author

Infact "registerWifiNetwork" works well but in the dart file we are always returning false as it's a void function.
And I confirm that registerWifiNetwork does not resolve my problem.
I think this is an android limitation

@Alisofin
Copy link

Same problem here !

@Alisofin
Copy link

I have just managed to make it work by doing: await disconnect(), await connect(), await forceWifiUsage()

@aminebagga
Copy link
Author

Even with the disconnect, connect then forceWifiUsage it does not work for me.
I'm connected to the disired Wifi AP but the traffic is blocked

@daadu
Copy link
Member

daadu commented Oct 23, 2023

Infact "registerWifiNetwork" works well but in the dart file we are always returning false as it's a void function. And I confirm that registerWifiNetwork does not resolve my problem. I think this is an android limitation

@aminebagga There is a fix for returning proper response in PR #318 , almost ready to merge - you can point to it and test until released.

@daadu
Copy link
Member

daadu commented Oct 23, 2023

I will test out the package with Android 12, and get back with result. Debugging such things is hard. Once I spent 2 days to debug a similar issue but turned out that the WiFi device (which was an embedded/IoT device) had power issue, so it would reboot when device would connect to it - this behaviour was not consistent as well.

What I mean to say is, check whether there are no such other issues like wrong IP, etc - by connecting to the network independent of the package on PC to confirm if the issue is not in AP itself.

@aminebagga
Copy link
Author

I succeeded to upgrade my tablet to android 13 and still same issue and same behavior.
No the IP / network config is correct, even with adb shell commands I'm not able to reach the network.
But if I connect to the same AP manually from wifi settings, all work fine.
So it's not in the AP config but rather an application issue
Thank you @daadu.

@Jay-57blocks
Copy link

@aminebagga @daadu Have you solved this problem? I've encountered it too. #356

@aminebagga
Copy link
Author

Hi @Jay-57blocks, Only use register instead of connect, you will be able to communicate over your AP but still some issue with the register as we are not able to catch the dialog events

@Jay-57blocks
Copy link

Jay-57blocks commented Dec 4, 2023

@aminebagga thanks, do have you encountered this problem? #359

@aminebagga
Copy link
Author

@Jay-57blocks not sure to have encountered this problem, but as I know, scanning wifi is limited on recent android versions, you have a max number of staring scans.

@daadu
Copy link
Member

daadu commented Dec 17, 2023

@aminebagga I am unable to resolve/verify this as I don't have an Android 11 phone with me. Would urge you to debug it yourself, and see if it is "model specific" issue or in general issue with Android 11?

@aminebagga
Copy link
Author

@daadu yes I fix this issue using registerWifiNetwork instead of connect api but with these changes richirisu#1

@daadu
Copy link
Member

daadu commented Dec 21, 2023

@aminebagga Can you file a working PR for it - explaining clearly what the issue and the fix is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants