Cannot get RPi3 to handle WiFi disconnects

The WiFi in my house is crappy, it’ll probably disconnect for a period every 48 hours or so for several minutes before righting itself.

My RPi3 running resin/raspberrypi3-python does not reconnect to WiFi after those WiFi drops.

I have tried the suggestion from izavits below, putting ‘autoconnect-retries=0’ in ‘resin-wifi’ so the file starts with:

[connection]
id=resin-wifi
type=wifi
autoconnect-retries=0

I don’t know if I’m putting that in the right file? In the right place?

Hello,

The file resin-wifi is the correct place for this setting. It should be located in a folder named system-connections. Have you tried rebooting the raspberry pi after this setting has been applied?

Hey @zwalchuk yep, so it’s in the right file. Rebooted many times since.
There doesn’t seem to be any change to wifi behaviour.
Is there any logging I can turn on / find?

Hi @teejK we believe this problem is fixed in the master git. This fix will make it into the next resin OS release for the raspberry pi 3, which will be in the following next days. So stay tuned for the next release

Excellent thanks!
So to be clear, “autoconnect-retries=0” will still be a required part of the “resin-wifi” file
after the resinOS update for the desired wifi reconnect behaviour to be true?

Hi, I would say first to try with the pristine image we will release before changing anything in the resin-wifi file

Hello,
Seems, we have the same issue with RPi3.
Resin OS version 2.12.5+rev2 (prod).
Wi-Fi router: USR-g806 4g
WiFi connection was configured with resin-wifi-connect app.
If wi-fi signal lost we need to reboot RPi to reconnect. This happening approximately once a day or two.
On the same site we have another resin device based on Raspberry Pi Zero W. It is connected to the same WiFi router and resin-wifi-connect app was used for configuration also. This device have no issues with reconnection.
Please note, we solve such issues with RPi3 running raspbian in the past wtih:
cp /etc/wpa_supplicant/ifupdown.sh /etc/ifplugd/action.d/ifupdown
But what should i do now?

The same issue with Raspberry Pi Zero W and USR-g806 4g router.
Now we resetting wifi connection once per hour with dbus command. But this is not a solution for us.

Hi, we have a wifi testing setup, just running our tests on the Pi Zero W and the Pi 3, and get back to you about what we find in a bit.

1 Like

Thanks!
Wil wait for results.

I am having the same issue. I have to reboot after it looses wifi connection. Also a power outage will cause this issue. I’m assuming the reconnect times out before the router is able to setup a wifi signal. I am using Resin OS 2.12.7+rev1 (prod) on Raspberry Pi 3. Has this issue been resolved yet?

Also, if wifi connection is lost, the program I am running stops. Is there a way to have the program run in the last known state while the device tries to reconnect to the internet? Here is my start.sh.

#!/usr/bin/env bash

export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket

iwgetid -r

if [ $? -eq 0 ]; then
   printf 'Skipping WiFi Connect\n'
else
   printf 'Starting WiFi Connect\n'
   ./wifi-connect
fi

modprobe i2c-dev && modprobe v4l2_common && python3 /usr/src/app/main.py

Appreciate any help!

I have investigated a couple of times similar issues. I could not reproduce locally, but here is the reason I found:

NetworkManager can block a connection from autoconnecting if attempts for establishing it have failed (due to various reasons). In this case when a scheduled rescan is executed, NetworkManager will ignore this network from then on. This should be fixable by restarting NetworkManager, e.g.:

DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
dbus-send --system --print-reply --dest=org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.RestartUnit string:"network-manager.service" string:"fail"

You may execute a shell script with a loop that sleeps for a minute for example. You may check the exit code of iwgetid -r to see whether there is an active wifi connection and restart NetworkManager if there is not any.

Thanks for the quick response!

In my case, I need to keep my main program running while it continues to check for an internet connection. How could I keep wifi-connect from exiting my main code and check for a connection simultaneously?

In the meantime I’ll try restarting network manager to reconnect without rebooting.

I think you may do all of that from your main application. One approach could be to have a timer with a callback that executes iwgetid -r to check whether there is an active wifi connection. If there is not any at some point due to the problem above, then you can restart NetworkManager from inside your application. Instead of dbus-send you may use a D-Bus package according to the language you use, e.g. dbus for Python, etc. After NetworkManager is restarted you may wait for certain amount of seconds, and then check for an active wifi connection again. If there is not any, you may launch wifi-connect from your application as a child process. This way you will be able to keep track of whether it is still running or not, and integrate all of this into your application logic. This is probably how I would go about all of this. We had an internal discussion and we will soon investigate in more detail the issue of wifi disconnects and maybe we will come up with a better solution than restarting NetworkManager. We will post an update on this thread when we have more results.