Android Question Android seems to drop WiFi when away from home

Didier9

Well-Known Member
Licensed User
This is maybe not a question about B4A but it seems to be an Android "feature".

Long post, I am sorry (I have been working on this for a couple of weeks now).

I have a B4A app that I use to control devices via WiFi.

The devices have an off-the-shelf WiFi-Serial module that can be configured to show up as an access point. The serial port goes to a microcontroller. The WiFi modules are used in "transparent" serial emulation mode, all the heavy lifting is done by the microcontroller.

I connect the tablet to the module/access point, the wifi module is configured to listen to port 8899 (TCP) over IP address 10.10.100.254.

My app opens this port for TCP, sends commands to that port and gets responses from the microcontroller over that port. Of course, the WiFi module is not connected to my home network, but the home network is visible from the Android tablet.

As long as I am at home, all goes well. I have also used it at my customer's location (where there also is a WiFi network) and there also all goes well. My app can use UDP or TCP and at home, both work equally well.

The site where these systems are eventually used does not actually have a WiFi network, so when at the site, the WiFi module's access point is the only visible WiFi device.

When we start the tablet and the WiFi device at the site, all goes OK, we connect to the access point, start the app and all goes well.

After about a minute, the port goes dead. The tablet shows being connected to the access point, but the app cannot open the TCP port. It's like the tablet simply refuses to even try to connect (I get Socket1_Connected( False ) instantly), yet the tablet shows being connected to the access point and if I open the browser on the tablet, I can get to the WiFi module's configuration web page.

If I reboot the tablet, I get another minute or so of WiFi and then the socket dies again. If I simply toggle wifi on and off on the tablet, sometimes the tablet will refuse reconnecting to the module, saying "no internet", but even in the cases where it does reconnect to the access point, the socket won't open.

If I then put the tablet and device in the car and drive home, as soon as I pull in the driveway and the tablet sees my internet connected home wifi router, it all starts running again. If I drive off away from home with the app running, it seems to be running fine as long as I do not disconnect. If I manually disconnect, I cannot reconnect.

It is as if as long as the tablet sees an access point that it knows to be internet connected (even though it is not associated with it), you get full wifi (all ports). Otherwise, after a minute or so, only port 80 works.

I have used two tablets, one with Android 6.0 and another with 4.4, and a phone with Android 5.1 and they all do the same thing.

Has anyone (like robot or drone designers) encountered a problem like this?

I wonder how the drone people are doing it since drones are used outside, typically away from other WiFi networks, maybe they use Port 80 for everything, or maybe there is an Android switch somewhere to keep WiFi up?

Thanks in advance for any suggestion.

<edit 3:46 PM>
The first round of Google searches did not yield anything but a second round yielded a number of issues with Android dropping WiFi when it cannot call home (I suppose it pings the mothership, googoe.com). I have tried a couple of apps that are supposed to keep WiFi up in a case like this but so far, while it seems to delay the inevitable, no success. I am still looking for a fix that works.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Upvote 0

Didier9

Well-Known Member
Licensed User
Thanks for the suggestions Erel. This issue looks to be a little different. The tablets I am using do not have 3G/4G, only WiFi. I also tried with my Moto-X (4G/Verizon) and it's exactly the same problem, works fine at home (even with 4G data enabled), and disconnects away from home.

For grins, I resurrected my old Nexus 7 WiFi (rooted) and reset it (reinstall OS), and I did not enter a Google account info so that it would not try to connect to Google (I do not know that for a fact, it may still try even though there is no account info), and I did not connect it to my home network, so it only knows about the WiFi module, even though it can see my home network. It works fine at home. I will take it out of the house later today.

I have seen a number of similar issues (Google: "android dropping wifi when no internet") and looked at some of the suggested solutions. One involves a superuser command that I will try on the Nexus later today since it is the only rooted device I have.
https://android.stackexchange.com/q...allow-to-keep-a-wi-fi-without-internet-access

I need to try the wifi lock also. I do not have much hope it will help in this instance but I am getting desperate...

The last test I want to do is take a router with me in the car to see if the simple presence of another WiFi access point is sufficient for Android to keep the WiFi up.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
I have tried the stackexchange suggestion on both the Nexus 7 (it is rooted, so I entered the command directly from a su terminal emulator) and the Lenovo Yoga Tab 3 (sending the command via adb) and it made no difference.

Last test, the router in the car. I need to hook a battery up to it.

Googling "drone app wifi problem with android" seems to indicate I am not the only one with that problem...
 
Upvote 0

DonManfred

Expert
Licensed User
I wonder how the drone people are doing it since drones are used outside, typically away from other WiFi networks, maybe they use Port 80 for everything, or maybe there is an Android switch somewhere to keep WiFi up?
The solution with the DJI Drones is that the APP running on the device is connected via USB-Cable with the Remote-controller. No need for a WIFI-Network.
The App sends the commands over USB to the remotecontroller which then sends the command over the Air-connection to the drone.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
The solution with the DJI Drones is that the APP running on the device is connected via USB-Cable with the Remote-controller. No need for a WIFI-Network.
The App sends the commands over USB to the remotecontroller which then sends the command over the Air-connection to the drone.

That seems to indicate that there is indeed an issue. What baffles me is how well it works at home even though I am not connected to my network. I have been working on this app now for many months, I have demoed it to my customer (in his facility) and several of his customers are using it without problem.
The first sign that something was off when one of his customers wanted to use it in an area where there is no WiFi at all and the app would only work for a minute or two.

It has to be something that tells Android to disconnect the WiFi, or ignore some type of traffic. If so, there has to be a switch somewhere to turn that behavior off. Just have to find it...

I have posted a message on StackExchange this morning, no response yet.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Tried with the (battery powered) router in the car, did not help. Of course, it was only broadcasting, it is possible that Android wants to see some traffic, so that is still inconclusive.

I have a couple more things to try but looking at the relative absence of comments, it seems that I am the only one who has ever faced this issue, which is hard to believe, or maybe I am the only one who uses an app away from Internet traffic.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Latest test: I setup a separate HttpJob task on my app, running on a timer which polls the WiFi module's configuration page every 2 seconds, just to keep some traffic on port 80, while the rest of the app is running.

While at home, it does not appear to affect performance in any way (that traffic does not go through the serial port, it is entirely handled within the WiFi module, so it is fast) , so I put the tablet and target in the car and drove away.
After about a minute, the app lost connection (on port 8899) but the keepalive HttpJob kept working well after port 8899 died, so I though I had it fixed, then a minute later the keepalive HttpJob died too :(

I guess the next step is to run WireShark to understand what kind of traffic Android expects on the WiFi channel to keep itself happy. This is way more work that what I signed up for...

I believe this is a bug on Android's part, to not even have a switch to keep the wifi open (there is a switch, but it does not work). There is traffic and as long as there is traffic, I do not understand why they have to turn it off.
 
Upvote 0
Top