# Cannot get RPi3 to handle WiFi disconnects

**URL:** <https://forums.balena.io/t/cannot-get-rpi3-to-handle-wifi-disconnects/2075>\
**Category:** Product support\
**Tags:** raspberrypi3, wifi\
**Created:** [October 25, 2017, 9:32pm UTC](https://forums.balena.io/t/cannot-get-rpi3-to-handle-wifi-disconnects/2075 "2017-10-25T21:32:10Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![teejK](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@teejK](https://forums.balena.io/u/teejK)\
**Post date:** [October 25, 2017, 9:32pm UTC](https://forums.balena.io/t/cannot-get-rpi3-to-handle-wifi-disconnects/2075/1 "2017-10-25T21:32:11Z")

</div>

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?

> [@Raspberry pi 3 Wifi issues on poor signal](https://forums.balena.io/t/raspberry-pi-3-wifi-issues-on-poor-signal/1205/27):
>
> Hello, have you tried setting autoconnect-retries=0 in your connection configuration file to see if that helps? You can read more about the network configuration here: [https://docs.resin.io/deployment/network/2.0.0/#introduction](https://docs.resin.io/deployment/network/2.0.0/#introduction) and you can read more about the NetworkManager options here: [https://developer.gnome.org/NetworkManager/unstable/nm-settings.html](https://developer.gnome.org/NetworkManager/unstable/nm-settings.html)

---

<div class="post-metadata">

**Author:** ![zwalchuk](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/zwalchuk/32/842_2.png) [@zwalchuk](https://forums.balena.io/u/zwalchuk)\
**Post date:** [October 25, 2017, 9:58pm UTC](https://forums.balena.io/t/cannot-get-rpi3-to-handle-wifi-disconnects/2075/3 "2017-10-25T21:58:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![teejK](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@teejK](https://forums.balena.io/u/teejK)\
**Post date:** [October 29, 2017, 9:16am UTC](https://forums.balena.io/t/cannot-get-rpi3-to-handle-wifi-disconnects/2075/4 "2017-10-29T09:16:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![floion](https://avatars.discourse-cdn.com/v4/letter/f/45deac/32.png) [@floion](https://forums.balena.io/u/floion)\
**Post date:** [October 29, 2017, 11:03am UTC](https://forums.balena.io/t/cannot-get-rpi3-to-handle-wifi-disconnects/2075/5 "2017-10-29T11:03:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![teejK](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@teejK](https://forums.balena.io/u/teejK)\
**Post date:** [November 1, 2017, 12:16pm UTC](https://forums.balena.io/t/cannot-get-rpi3-to-handle-wifi-disconnects/2075/6 "2017-11-01T12:16:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![floion](https://avatars.discourse-cdn.com/v4/letter/f/45deac/32.png) [@floion](https://forums.balena.io/u/floion)\
**Post date:** [November 1, 2017, 12:28pm UTC](https://forums.balena.io/t/cannot-get-rpi3-to-handle-wifi-disconnects/2075/7 "2017-11-01T12:28:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![letrich](https://avatars.discourse-cdn.com/v4/letter/l/8dc957/32.png) [@letrich](https://forums.balena.io/u/letrich)\
**Post date:** [May 3, 2018, 4:45am UTC](https://forums.balena.io/t/cannot-get-rpi3-to-handle-wifi-disconnects/2075/8 "2018-05-03T04:45:03Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![letrich](https://avatars.discourse-cdn.com/v4/letter/l/8dc957/32.png) [@letrich](https://forums.balena.io/u/letrich)\
**Post date:** [May 15, 2018, 9:10am UTC](https://forums.balena.io/t/cannot-get-rpi3-to-handle-wifi-disconnects/2075/9 "2018-05-15T09:10:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [May 22, 2018, 4:20pm UTC](https://forums.balena.io/t/cannot-get-rpi3-to-handle-wifi-disconnects/2075/10 "2018-05-22T16:20:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![letrich](https://avatars.discourse-cdn.com/v4/letter/l/8dc957/32.png) [@letrich](https://forums.balena.io/u/letrich)\
**Post date:** [May 25, 2018, 4:45am UTC](https://forums.balena.io/t/cannot-get-rpi3-to-handle-wifi-disconnects/2075/11 "2018-05-25T04:45:58Z")

</div>

Thanks!  
Wil wait for results.

---

<div class="post-metadata">

**Author:** ![i\_ball8](https://avatars.discourse-cdn.com/v4/letter/i/3ab097/32.png) [@i\_ball8](https://forums.balena.io/u/i_ball8)\
**Post date:** [June 18, 2018, 12:35am UTC](https://forums.balena.io/t/cannot-get-rpi3-to-handle-wifi-disconnects/2075/13 "2018-06-18T00:35:05Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![majorz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/majorz/32/639_2.png) [@majorz](https://forums.balena.io/u/majorz)\
**Post date:** [June 20, 2018, 11:55am UTC](https://forums.balena.io/t/cannot-get-rpi3-to-handle-wifi-disconnects/2075/17 "2018-06-20T11:55:13Z")

</div>

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.:

```auto
DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket

```

```auto
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.

---

<div class="post-metadata">

**Author:** ![i\_ball8](https://avatars.discourse-cdn.com/v4/letter/i/3ab097/32.png) [@i\_ball8](https://forums.balena.io/u/i_ball8)\
**Post date:** [June 20, 2018, 11:37pm UTC](https://forums.balena.io/t/cannot-get-rpi3-to-handle-wifi-disconnects/2075/28 "2018-06-20T23:37:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![majorz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/majorz/32/639_2.png) [@majorz](https://forums.balena.io/u/majorz)\
**Post date:** [June 21, 2018, 6:26am UTC](https://forums.balena.io/t/cannot-get-rpi3-to-handle-wifi-disconnects/2075/29 "2018-06-21T06:26:11Z")

</div>

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.
