My emonpi2 will not reconnect to wifi

Hi,

I have an emonpi2, without an ethernet port.

The Wi-Fi connection works fine most of the time, but if the connection drops ( e.g. router is restarted) , the Wi-Fi does not reconnect.

The only way seems to be to power cycle the emonpi2 (or enable ap mode and restart the whole connection process).

Either way it requires physical presence. Is there a config option I have missed to enable it to retry a failed connection. (On the basis that it can’t hurt, as it is just sitting doing nothing).

Thanks

Have you tried a search? I seem to recall seeing similar questions asked quite some time ago, I think the answer was to reset the WiFi with a Cron job, but I can’t remember the details.

I have a very early emonPi with a WiFi USB dongle and when that drops out, unplugging the dongle for 30 s or so is enough. I haven’t got around to finding a permanent solution.

Exact same problem here with a UniFi system, any time the APs go down for firmware update the EmonPi never reconnects and requires a manual restart.

@TrystanLea ?

FWIW, I operate a number of Raspberry Pis for different purposes with different OSes on them and the EmonPi is the only one that ever has issues, and it’s fairly repeatable.

What logs should I be watching for, the wifi-check script ones?

Yes, but do any of those have the ability to connect to them with an AP on first use? I suspect it is the mechanism used to do that on first boot that then causes the reconnection issues.

Have you given the emonPi2 (and each of the others) a fixed IP address in your router? I assume you will have, but it’s worth clarifying.

The ones that are static have static IPs defined in their networkd settings, the EmonPi is just using DHCP, but my DHCP server/router gives it the same IP consistently.

I don’t believe DHCP is the culprit here as my AP logs show it as disconnecting from the AP completely which is a physical/L1 networking problem, not an IP problem.

@borpin you mention the AP on startup, that’s a good point - however when the EmonPi is in this state and I access the LCD on it, the AP is down and the WiFi is also showing as disconnected.

Is there some script or logic that is checking for AP/wlan0 liveness or is doing ifup/ifdown?

@glyn.hudson & @TrystanLea did this feature.

Managed to capture some logs this evening:

Apr 12 19:19:01 emoncms CRON[5110]: (root) CMD (/usr/local/bin/wifi-check >> /var/log/emoncms/wificheck.log 2>&1)
Apr 12 19:19:01 emoncms CRON[5109]: pam_unix(cron:session): session closed for user root
Apr 12 19:19:38 emoncms wpa_supplicant[585]: wlan0: CTRL-EVENT-DISCONNECTED bssid=e2:63:da:37:ff:18 reason=0 locally_generated=1
Apr 12 19:19:38 emoncms wpa_supplicant[585]: ap0: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
Apr 12 19:19:38 emoncms wpa_supplicant[585]: ap0: CTRL-EVENT-REGDOM-CHANGE init=USER type=COUNTRY alpha2=GB
Apr 12 19:19:38 emoncms NetworkManager[578]: <info>  [1776017978.0757] device (wlan0): supplicant interface state: completed -> disconnected
Apr 12 19:19:38 emoncms NetworkManager[578]: <info>  [1776017978.0759] device (p2p-dev-wlan0): supplicant management interface state: completed -> disconnected
Apr 12 19:19:38 emoncms NetworkManager[578]: <info>  [1776017978.1731] device (wlan0): supplicant interface state: disconnected -> scanning
Apr 12 19:19:38 emoncms NetworkManager[578]: <info>  [1776017978.1733] device (p2p-dev-wlan0): supplicant management interface state: disconnected -> scanning
Apr 12 19:19:38 emoncms wpa_supplicant[585]: wlan0: Trying to associate with SSID 'MGIO-IoT-Trusted'
Apr 12 19:19:38 emoncms NetworkManager[578]: <info>  [1776017978.7528] device (wlan0): supplicant interface state: scanning -> associating
Apr 12 19:19:38 emoncms NetworkManager[578]: <info>  [1776017978.7529] device (p2p-dev-wlan0): supplicant management interface state: scanning -> associating
Apr 12 19:19:39 emoncms wpa_supplicant[585]: wlan0: CTRL-EVENT-ASSOC-REJECT bssid=00:00:00:00:00:00 status_code=16
Apr 12 19:19:39 emoncms NetworkManager[578]: <info>  [1776017979.3208] device (wlan0): supplicant interface state: associating -> disconnected
Apr 12 19:19:39 emoncms NetworkManager[578]: <info>  [1776017979.3210] device (p2p-dev-wlan0): supplicant management interface state: associating -> disconnected
Apr 12 19:19:39 emoncms NetworkManager[578]: <info>  [1776017979.8228] device (wlan0): supplicant interface state: disconnected -> scanning
Apr 12 19:19:39 emoncms NetworkManager[578]: <info>  [1776017979.8229] device (p2p-dev-wlan0): supplicant management interface state: disconnected -> scanning
Apr 12 19:19:40 emoncms wpa_supplicant[585]: wlan0: Trying to associate with SSID 'MGIO-IoT-Trusted'
Apr 12 19:19:40 emoncms NetworkManager[578]: <info>  [1776017980.4053] device (wlan0): supplicant interface state: scanning -> associating
Apr 12 19:19:40 emoncms NetworkManager[578]: <info>  [1776017980.4054] device (p2p-dev-wlan0): supplicant management interface state: scanning -> associating
Apr 12 19:19:40 emoncms wpa_supplicant[585]: wlan0: CTRL-EVENT-ASSOC-REJECT bssid=00:00:00:00:00:00 status_code=16
Apr 12 19:19:40 emoncms NetworkManager[578]: <info>  [1776017980.9710] device (wlan0): supplicant interface state: associating -> disconnected
Apr 12 19:19:40 emoncms NetworkManager[578]: <info>  [1776017980.9712] device (p2p-dev-wlan0): supplicant management interface state: associating -> disconnected
Apr 12 19:19:41 emoncms NetworkManager[578]: <info>  [1776017981.9952] device (wlan0): supplicant interface state: disconnected -> scanning
Apr 12 19:19:41 emoncms NetworkManager[578]: <info>  [1776017981.9954] device (p2p-dev-wlan0): supplicant management interface state: disconnected -> scanning
Apr 12 19:19:42 emoncms wpa_supplicant[585]: wlan0: Trying to associate with SSID 'MGIO-IoT-Trusted'
Apr 12 19:19:42 emoncms NetworkManager[578]: <info>  [1776017982.5711] device (wlan0): supplicant interface state: scanning -> associating
Apr 12 19:19:42 emoncms NetworkManager[578]: <info>  [1776017982.5714] device (p2p-dev-wlan0): supplicant management interface state: scanning -> associating
Apr 12 19:19:44 emoncms wpa_supplicant[585]: wlan0: Associated with e2:63:da:33:7f:5a
Apr 12 19:19:44 emoncms wpa_supplicant[585]: wlan0: CTRL-EVENT-CONNECTED - Connection to e2:63:da:33:7f:5a completed [id=0 id_str=]
Apr 12 19:19:44 emoncms wpa_supplicant[585]: wlan0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0
Apr 12 19:19:44 emoncms wpa_supplicant[585]: ap0: CTRL-EVENT-REGDOM-CHANGE init=COUNTRY_IE type=COUNTRY alpha2=GB
Apr 12 19:19:44 emoncms NetworkManager[578]: <info>  [1776017984.8267] device (wlan0): supplicant interface state: associating -> completed
Apr 12 19:19:44 emoncms NetworkManager[578]: <info>  [1776017984.8269] device (p2p-dev-wlan0): supplicant management interface state: associating -> completed
Apr 12 19:19:44 emoncms NetworkManager[578]: <info>  [1776017984.8270] device (wlan0): ip:dhcp4: restarting
Apr 12 19:19:44 emoncms NetworkManager[578]: <info>  [1776017984.8850] dhcp4 (wlan0): canceled DHCP transaction
Apr 12 19:19:44 emoncms NetworkManager[578]: <info>  [1776017984.8851] dhcp4 (wlan0): activation: beginning transaction (timeout in 45 seconds)
Apr 12 19:19:44 emoncms NetworkManager[578]: <info>  [1776017984.8852] dhcp4 (wlan0): state changed no lease
Apr 12 19:19:44 emoncms NetworkManager[578]: <info>  [1776017984.8855] dhcp4 (wlan0): activation: beginning transaction (timeout in 45 seconds)
Apr 12 19:19:44 emoncms NetworkManager[578]: <info>  [1776017984.9284] dhcp4 (wlan0): state changed new lease, address=172.16.250.53
Apr 12 19:19:44 emoncms dbus-daemon[525]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service' requested by ':1.7' (uid=0 pid=578 comm="/usr/sbin/NetworkManager --no-daemon")
Apr 12 19:19:45 emoncms systemd[1]: Starting NetworkManager-dispatcher.service - Network Manager Script Dispatcher Service...
░░ Subject: A start job for unit NetworkManager-dispatcher.service has begun execution
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░
░░ A start job for unit NetworkManager-dispatcher.service has begun execution.
░░
░░ The job identifier is 1668.
Apr 12 19:19:45 emoncms dbus-daemon[525]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr 12 19:19:45 emoncms systemd[1]: Started NetworkManager-dispatcher.service - Network Manager Script Dispatcher Service.
░░ Subject: A start job for unit NetworkManager-dispatcher.service has finished successfully
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░
░░ A start job for unit NetworkManager-dispatcher.service has finished successfully.
░░
░░ The job identifier is 1668.
Apr 12 19:19:55 emoncms systemd[1]: NetworkManager-dispatcher.service: Deactivated successfully.
░░ Subject: Unit succeeded
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░
░░ The unit NetworkManager-dispatcher.service has successfully entered the 'dead' state.
Apr 12 19:20:01 emoncms CRON[5151]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Apr 12 19:20:01 emoncms CRON[5152]: (root) CMD (/usr/local/bin/wifi-check >> /var/log/emoncms/wificheck.log 2>&1)
Apr 12 19:20:01 emoncms CRON[5151]: pam_unix(cron:session): session closed for user root

I find these particularly interesting:

wlan0: CTRL-EVENT-ASSOC-REJECT bssid=00:00:00:00:00:00 status_code=16

The internet tells me:

The CTRL-EVENT-ASSOC-REJECT status_code=16 error on Raspberry Pi devices (particularly RPi 3A+, 3B+, 4, and 400) typically indicates an incompatibility between the brcmfmac driver and specific Wi-Fi features like SAE (WPA3), 802.11r fast roaming , or authentication offloading (SWSUP).

My network is in WPA2/WPA3 transition mode but has 802.11r disabled.

So I created a file `/etc/modprobe.d/brcmfmac.conf with the following:

options brcmfmac roamoff=1 feature_disable=0x82000

Going to reboot the pi with those changes in place and see what’s what.

So,

For what it’s worth - still no communication loss, which is unusual, normally dies every two days or so.

What remains unanswered is that if this does fix it, why does it not affect any of my other Pis that also run Debian derivatives.

Is EmonPi Raspbian based?

Because the other instances are not setup to create an AP if no connection is established (is my suspicion).