tripflex / WifiWizard2

A Cordova plugin for managing Wifi networks (new version of WiFiWizard) - Latest is version 3+
https://www.npmjs.com/package/cordova-plugin-wifiwizard2
Apache License 2.0
123 stars 146 forks source link

Anyone getting a disconnect within about a minute of connection? #61

Open simonkincaidkintronix opened 5 years ago

simonkincaidkintronix commented 5 years ago

Hi,

3.1.0 version is great, especially now that the UI doesn't hang on connect. Thanks guys!

My problem now is that I am getting a connection, but for some reason the wifi decides to drop within one minute of connection. Does anyone know why this might be happening?

simonkincaidkintronix commented 5 years ago

Upon further testing I can give some more info:

If I forget all networks using the standard Android OS interface, and then run the app once, and then I re-add the networks, there is a consistent connection, and this behaviour is not reproduced.

The Wifi I connect to does not have internet access, it is just a local hotspot. Perhaps this might have something to do with it?

shootdaj commented 5 years ago

I am having the same issue with my Pixel 2 XL (Android 9.0). I do NOT get this behavior with my old phone which is a Samsung Note 5 Android 6. So Android/Pixel must have introduced this behavior recently. Anyone know of a fix to this issue?

simonkincaidkintronix commented 5 years ago

I am having the same issue with my Pixel 2 XL (Android 9.0). I do NOT get this behavior with my old phone which is a Samsung Note 5 Android 6. So Android/Pixel must have introduced this behavior recently. Anyone know of a fix to this issue?

As far as I can tell the only way to deal with this on newer models is to forget all networks and then make the connection. You can then add other networks back in, and the connection stays stable.

shootdaj commented 5 years ago

Yeah I noticed that also in a post in the Android blog post (https://android-developers.googleblog.com/2016/07/connecting-your-app-to-wi-fi-device.html) that it dynamically optimizes connections (I'm guessing that part of this optimization is that if a Wifi connection does not have internet connection, it will reconnect to the old one - sounds kind of a premature optimization to me). This seems like unwanted behavior for an IoT app where you have to connect to a device and configure it. It may not have internet until you connect to it and configure it to connect to your Wifi. Even then, it may not share its internet connection. I don't know how the Android team expects people to be able to develop IoT apps without the feature of being able to stay connected to a Wifi network in a stable manner.

On another note, Google Home seems to be able to work even with these restrictions. I can use Google Home to configure a Chromecast. The way it does this is it connects to the Chromecast device, configures it to connect to my Wifi, and then the app reconnects my phone to my Wifi. So if Google Home is doing it, surely it's possible to do with other apps (unless they have some special permission because Android and Google Home are both made by Google).

In any case, this is super frustrating and it seems like this is basic functionality that should work. I've spent countless hours on trying to figure this out. Next thing I'm going to try is just force connect to the IoT device if it's not connected for each command I'm sending to it. It seems to stay connected for a few seconds so that window should be enough to send a request and receive a response (hopefully). Otherwise I'll just put it in a try-catch loop so it keeps doing it until it works lol. I don't know of any better ways around it and this seems quite hacky, but it's the best I've got for now.

If anyone has any suggestions, please post them. Thank you.

simonkincaidkintronix commented 5 years ago

I think you've shed some light on the situation actually. I get the feeling it's something to do with the bindAll feature, so I'm going to have a play around with that, see if I can get it working. Will let you know!

shootdaj commented 5 years ago

@simonkincaidkintronix I actually found a (kind of) solution for this. Before connecting to Wifi network via your app, you need to make sure that you have not connected to the Wifi network via the Wifi manager on Android. The network needs to be forgotten manually if you have connected to it manually before. Once you have forgotten the network, then try connecting via your app again and when I tested, it stayed connected.

In all my tests, I had set bindAll to true. I think the last time I had bindAll = false, it was routing the connection through my data signal instead of the Wifi since the data signal stays connected when there is no internet connectivity on the Wifi.

tripflex commented 5 years ago

@simonkincaidkintronix @shootdaj yes, newer versions of Android, if the wifi network does not have internet all data will be routed through the cellular network, not through the wifi network (regardless of what you do on your phone, like clicking stay connected).

That's actually one of the main reasons I forked this library to begin with (among other things), you can find more details in the PR that brought in the bindall feature: https://github.com/tripflex/WifiWizard2/pull/8

It also explains in the readme about what's new in 3.x+: https://github.com/tripflex/WifiWizard2#new-to-300 https://android-developers.googleblog.com/2016/07/connecting-your-app-to-wi-fi-device.html

In regards to the wifi network editing, this is in the readme too: https://github.com/tripflex/WifiWizard2#android-permissions-and-notes

Newer versions of Android will not allow you to remove, update existing configuration, or disable networks that were not created by your application. If you are having issues using this features, with your device connected to your computer, run adb logcat to view Android Logs for specific error.

shootdaj commented 5 years ago

Newer versions of Android will not allow you to remove, update existing configuration, or disable networks that were not created by your application. If you are having issues using this features, with your device connected to your computer, run adb logcat to view Android Logs for specific error.

So I guess the "update" part also means that if you connect to a network via your app that you have connected to manually before and the network doesn't have internet connectivity, that it will disconnect automatically.

Honestly I'm not sure if internet connectivity matters. I'm thinking that since the network was present before your app tried to connect to it, that Android will disconnect anyway since your app did not create it. Not 100% about this though since every time I connect to a Wifi via my app, it has been to a network without internet connectivity.

tripflex commented 5 years ago

@shootdaj IIRC it shouldn't, unless you specifically didn't select "remain connected" or whatever the prompt is when android detects no internet, which is the only thing i can think that would cause an immediate disconnect like that (it should remain connected).

You can still connect to networks that were setup by other apps (or manually), which is why the disconnect issue is weird .. as it shouldn't automatically disconnect.

If you are having issues using this features, with your device connected to your computer, run adb logcat to view Android Logs for specific error.

What does logcat output when it disconnects?

simonkincaidkintronix commented 5 years ago

Currently the app is behaving itself, but my colleague sees the drops intermittently on their phone. @tripflex - Could I please confirm what I should be doing? My app needs to connect to a WiFi hotspot on a raspberry PI, which doesn't provide internet access. Assuming the phone will have cellular, should WiFiWizard work if I am using BindAll(), in your opinion?

simonkincaidkintronix commented 5 years ago

Hi @tripflex, So, I've managed to get the connection solid on the newer Android - @shootdaj was correct - initially I thought I had to remove all networks before running the app, but actually you just need to make sure that phone doesn't know about/connect to the network prior to the app doing this. Which makes sense, and I'm happy with that...

The only thing that I want to find out is whether we can do something to disable that 'no internet do you want to switch popup' so users don't have to select this?

tripflex commented 5 years ago

@simonkincaidkintronix yes you should pass true to the bind argument to force it to bind to that network (when no internet on wifi network).

Try using the bindall feature and see if it still gives the notice

simonkincaidkintronix commented 5 years ago

@tripflex Yes I am bindAll'ing but still get the notice asking whether i want to stay on the network, because there is no internet access. Any ideas?

shootdaj commented 5 years ago

@simonkincaidkintronix Yes I have not found a way to do that either. I hope it is removable too.

simonkincaidkintronix commented 5 years ago

@tripflex Hi Tripflex, I'm happy to put in some digging on this, any ideas where to start?

tripflex commented 5 years ago

@simonkincaidkintronix no i do not know of any way to prevent that from showing -- i think it's native to Android itself -- the only way i can think of would be to have some kind of DNS responder that fakes internet connection but that would be something outside the scope of this plugin and would be something you would have to handle one the device that is running the wifi AP

AFA-janw commented 5 years ago

Just a little info that might be useful to some of you...

On certain Android versions, I too was facing the problem of Android disconnecting from an IoT device (without internet) and then reverting back to the previous WiFi connection. Even when I was using the bindAll flag and the device wasn't 'known' yet in the native WiFi settings.

What helped for me was to first call the disableWifi() method, and then call connect() with the IoT device's SSID (which automatically enables WiFi again). Now, it seemed like the IoT device had become the 'primary' device, because the connection remained intact! Can other people confirm this behaviour for me?

sw-tt-vidhithakkar commented 1 year ago

I have same issue, I connect to my IOT device through wifi which has no internet & when i am sending commands to it through socket suddenly wifi with no internet disconnect & I got error of Software cause connection abort. could anyone help me on this?

I tried with bindAll to true & forget all networks but still having same issue in Android.