I find that my Zero W 2 (headless) will drop the wi-fi connection randomly. Could work for an hour or maybe 24 hours (although never longer than that??). The application is a CCTV cam so disconnections are bad.
I found this thread discussing turning off power save and setting the region.
I’ve set the region and in Terminal turned off power save, then confirmed same. Seems to make no difference as Wi-Fi still disconnects. If I reboot the Zero and check power save, it’s on.
I’ve tested this when connected to the Wi-fi extender and directly to the router. I suspected this could be a lease issue but that would not be random disconnects (?) and my Pico W’s seem to happily stay connected to the same devices permanently.
It sounds like you’ve already taken some good steps, setting the Wi-Fi country and trying to disable power saving. But if the power save setting isn’t sticking after reboot, that might be a key issue.
Try creating or editing the following file to disable Wi-Fi power saving permanently:
sudo nano /etc/rc.local
Add this line above the exit 0 line:
iw dev wlan0 set power_save off
Save and exit. This should apply the setting at boot.
Once that’s in place, give it a test run, leave it on for a while and see if the connection stays up. Let us know how it goes and if the dropout still happens; there might be a deeper issue to dig into if it persists.
Call me cynical…but I’m going to reinstall the OS now and test the wi-fi for a few days on a fresh, updated Pi Zero 2 W before recoding the Camera. This to prove (or not) that the upteen camera coding setups I’ve done are not the cause of the disconnections.
Thats a good approach! Isolating the OS and testing Wi-Fi performance before diving back into the camera code sounds like a solid plan. It’ll definitely help narrow things down and confirm whether it’s a software issue or something else at play. Keep us posted with how it goes after a few days of testing!
So I reinstalled the OS, ran updates, set the region, wi-fi settings and connected. Set power save to off.
For 24 hours the connection was stable and I randomly checked this by making a remote connection with VNC, each time confirming that power save was off.
A few minutes into the 25th hour wi-fi stopped. Connected my kb/mouse/monitor to find the Zero operating fine and it showing wi-fi as active (which it was not). Toggled the wi-fi and its back on the network.
The Zero connects to my router as does my Pico W weather station. It stays online as it should so I don’t see this being related to the router.
So, the issue is not related to any CCTV coding I’ve done, nor is it to do with power save. The log files only seem to cover the last boot?
I could write some code to reboot the zero periodically, or maybe toggle the wi-fi but this would be a work around, not a solution. This seems (when searching for answers) to be a common issue although I can’t find a common agreed upon diagnosis or fix.
Is there a log that I can enable that shows wi-fi status? I’ve just now set storage in journal to persistent. That said, it would probably show no change as the desktop shows it active even when its not.
Are the disconnects random, or does it just seem like that? The router will check the lease at 50% and 87.5% by default, and then 100%, so there are three points at which disconnection can occur if the Zero is not awake. Combine that with any uncertainty about when the lease was acquired or renewed then that could easily appear random.
There is the odd random (or appears to be) disconnect where the wi-fi de-activates. No rhyme or reason to the timing.
I’ve run three > 24 hour tests now and in each the wi-fi re-activated minutes into the 25th hour, so that’s consistent.
One difference between the Zero and the Picos I realised this morning is that the Pico’s addresses are reserved in the router whereas the Zero’s was not. I’ve set this now and started another test.
So it looks like it was a lease issue after all. I found the router’s DHCP Lease setting set to its default 24 hours which correlates to the 24-25 hour disconnects I was seeing. I changed it to 72 hours and the Zero is still connected 96 hours later.
What I don’t understand is why the Zero had this issue while other network devices do not, and why the Zero now appears to be stable?
Most devices on our home network (TVs, computers, tablets, phones, robot vacuum, etc) connect when required but this would be for a few hours at a time so the lease issue would not come in to play.
But then there’s the PV inverter, pool pump, HWS, wi-fi extenders, CCTV cameras, a couple of Pico W, a Pi5 running HA, etc. All of the these devices are permanently online and do not drop out.
What makes the Zero 2 W different? Is it that the Zero has to have a program running to renew the connection? If so, why don’t the Pico’s?
Just brain storming here…. do you have any dhcp server logs? I am wondering if the Pico’s just get an IP and keep using it (i.e. ignore the lease period) and the zero is trying to honor the lease. Even with a fixed dhcp lease the client should expire its ip and renew, so if you can get logs, you should see them all request inline with the lease times.
Honestly, it’s hard to say exactly why the Zero 2 W behaves differently. It might be that the Pi’s DHCP client or network management needs an active program or process running to handle lease renewals properly, whereas devices like the Pico W have simpler or more dedicated firmware that manages connections differently.
Another possibility is that the Pico’s network stack or Wi-Fi chip handles DHCP leases more efficiently or uses longer leases by default. Without digging into the exact networking details of each device, it’s mostly educated guesswork. Looks like extending the DHCP lease time helps, but the root cause could be a mix of how the Pi’s OS, network services, and power management interact.
Nonetheless, I’m sure the steps you detailed here to get a better connection will be helpful for others
The Zero thinks it is still connected … until it tries using wi-fi - at which point it automatically reconnects and continues like any of your other devices.
This was an issue with my RasPi Zero back in July 2023. Pinging to the Zero gives “Destination Host Unreachable” - however it could communicate out. At the time iw dev wlan0 set power_save off was considered the best solution, but that may have changed since. Check out the Raspberry Pi forum. From memory the default was to save power in case the Zero was battery powered. Alternatively ping the router every so often to keep the communication considered active.
Wi-fi Access Points (WAP), such as those built into wi-fi-routers, have a separate table with details about each connected wi-fi device. I discovered that old wireless routers (like I used at the time) only supported 10 concurrent wi-fi connections. I replaced it with a modern router - residential models generally support about 30 concurrent wi-fi connections, and the expensive commercial grade usually more … but manufacturers never include this number in their specs.
Mark, you mention CCTV, a wi-fi repeater, and upteen camera coding setups … could it be that you’re approaching the limit of how many wi-fi devices your wi-fi router can keep track of ? What if your WAPs table of currently connected wi-fi devices (not to be confused with router number of devices, or NAT or DHCP) is full, what should a router do ?
Typically Wi-fi devices are portable, or not permanently connected, so it’s reasonable to assume that one or more may no longer be powered on or within range of the WLAN. So the WAP picks the device that has not communicated for the longest time, and just reuses that slot for the new device. Effectively the oldest device has been dropped from the WLAN and won’t be available from the WLAN … though it may actually still be running happily.
If/when the oldest device next communicates, the WAP finds that it is not in the Wi-fi devices table, and adds it as a new connection; dropping another device if necessary. Normally the wi-fi device initiates communication, so this works out OK.
The router has capacity for 32 static address of which I have 3 reserved. Nothing in the manual about total leases but right now there are 19. I’ve been starting each test before 0600 (I’m an early riser) so the Zero would drop off at the same time the next day when there’d be <10 devices connected. The correlation to the 3 tests I did that dropped our after 24+ hours correlates to the (then) 24 hour lease time. So my read is the router dropped the lease and the Zero did not renew.
I’d be will to bet that if I coded a renewal in the Zero to occur every 20 hours it’d stay connected forever.