glossyio / traffic-monitor

Traffic Monitor built with edge ML for object detection and radar for speed monitoring
GNU General Public License v3.0
11 stars 1 forks source link

RPi WiFi has intermittent connectivity #25

Open glossyio opened 3 weeks ago

glossyio commented 3 weeks ago

Describe the bug

The Raspberry Pi (RPi) WiFi connection irregularly fails to connect to any external IP address, as described here: https://github.com/raspberrypi/bookworm-feedback/issues/220#issuecomment-2429774412 and RPi 5 wifi loses connection after hours or days of correct operation when shared between accesspoint and a wifi cliient. Note that the RPi continues to run the Traffic Monitor software and will occasionally send a small payload message or fully reconnect. However, typically this is intermittent at best.

I commonly get THIS error message from the Node-RED flow on the Traffic Monitor when it has connectivity issues: RequestError: getaddrinfo EAI_AGAIN <URL> It can happen for any telemetry payload to ThingsBoard. It happens when the device has intermittent connectivity issues, but it also happened just before the device went offline from a ThingsBoard perspective. I think EAI_AGAIN is symptomatic of the WiFi interface not working properly and not the cause; evidenced by pings to the RPi failing.

When physically connected to the device with monitor/keyboard: It will error when trying to ping either a LAN IP address (even the Gateway IP address) with error Destination Host Unreachable or any domain name with error Temporary failure in name resolution. However, it does successfully ping localhost (127.0.0.1).

To fix this, I am able to bring the RPi back online by physically connecting monitor/keyboard and running an nmcli device down wlan0 followed by nmcli device up wlan0. So, it is only the network for some reason.

To Reproduce

Steps to reproduce the behavior: Irregular behavior, but this has occurred on multiple RPi5/4GB units connected to different physical networks with different network infrastructure. Sometimes this happens within minutes of reboot, sometimes days or weeks. This is regardless of whether or not there is network activity.

Expected behavior

Want the RPi to remain connected to WiFi or properly reconnect if it loses signal.

Screenshots

See linked issue above

Raspberry Pi

(please complete the following information):

Additional context

As an example:


- The TM was still collecting data and running properly (it usually does).  So when I got access, I was able to see the data it had collected while it had connectivity issues.
glossyio commented 2 weeks ago

I had not previously run across this:

Sometimes my Raspberry Pi disconnects from the wifi and I can't connect again

There is an option that manages the power of the wifi and allows to put it in saving mode. Disabling this option may help you to avoid this problem. First check if the wifi power save feature is enabled or not:

iw wlan0 get power_save

If it is enabled, then edit the following file (replace HOSTNAME with the name you set for your Raspberry Pi):

sudo nano /home/HOSTNAME/.bashrc

And add the following line at the end:

sudo iwconfig wlan0 power off

Reboot and check again typing the first command to see if the feature is enabled or not.

From https://gitlab.com/idotj/enviroplusweb

I can see it is indeed on by default on my RPis

glossyio commented 2 weeks ago

As a follow-up, a few other ways to change power mode: https://raspberrypi.stackexchange.com/questions/96606/make-iw-wlan0-set-power-save-off-permanent#96608

In particular, we could use this nmcli command, but it would only for the specified connection profile:

sudo nmcli con mod preconfigured wifi.powersave disable

rektosaure commented 2 weeks ago

Does this actually fix the issue? I encounter similar random behaviour, going to try this.

glossyio commented 2 weeks ago

It looks promising but cannot yet confirm. There's more discussion on our Zulip chat: https://trafficmonitor.zulipchat.com/#narrow/channel/443554-general/topic/TM.20stops.20connecting