[Buildroot] Recommended way to auto-reconnect wifi?

Nicolas Cavallari nicolas.cavallari at green-communications.fr
Wed Sep 22 08:19:27 UTC 2021


On 22/09/2021 02:16, Jeremy Fleischman wrote:
> I've been happily using buildroot for a growing number of Raspberry PIs at
> home. However, I've noticed that whenever our wifi cuts out, they do not
> reconnect when it comes back.
> 
> I've got them configured using BusyBox init + mdev + ifupdown +
> wpa_supplicant. I've skimmed through /etc/inittab, and I think I understand
> how everything is wired together:
> 
>    - /etc/init.d/S10mdev: mdev starts up, and asynchronously starts
> discovering devices.
>    - /etc/init.d/S40network: This runs /sbin/ifup -a. I think this runs
> while mdev is still discovering devices, which is fine, because there's a
> wait-delay configured in /etc/network/interfaces:
> 
> # cat /etc/network/interfaces
> auto lo
> iface lo inet loopback
> 
> auto wlan0
> iface wlan0 inet dhcp
>      hostname thermometer
>      pre-up wpa_supplicant -D nl80211 -i wlan0 -c /etc/wpa_supplicant.conf -B
>      post-down killall -q wpa_supplicant
>      *wait-delay 15*
> 
> iface default inet dhcp
> 
> As far as I can tell, this all only ever happens at startup, and there
> isn't any mechanism that would attempt to reconnect to a wifi network after
> a disconnect. I've done some googling, and here's what I've learned:
> 
>    - I'm pretty sure that wpa_supplicant is not supposed to handle this.
>    - It looks like some people write scripts to handle this for themselves.
> See this SO answer <https://raspberrypi.stackexchange.com/a/5121> and
> this dweeber/WiFi_Check
> repo <https://github.com/dweeber/WiFi_Check>.
> 
> Am I correct that this is something I should fix by adding some sort of
> background/cron process to do something like the WiFi_Check script above?
> Or is this something buildroot does have baked in support for, and I just
> haven't found it yet?

Buildroot has nothing out of the box for this, short of 
NetworkManager/connman or the likes.

In your case, wpasupplicant should reconnect automatically if it is 
disconnected, but the busybox DHCP client, udhcpc  won't retry 
indefinitely by default. If you use a custom busybox configuration, you 
can modify CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS to make udhcpc go into 
background and retry indefinitely.

Also, note that you can copy the Debian ifupdown scripts into your image 
and then use the Debian's wpa-* options in /etc/network/interface. You 
will have to tweak them a bit because buildroot install wpasupplicant in 
/usr/sbin instead of /sbin.


More information about the buildroot mailing list