My Pi keeps showing offline after 20 idle minutes and wakes up when I SSH in
Hi all. Final year project, a Pi 3B+ in the greenhouse we use for the project reading a BME280 every 15 minutes and sending to Hermetry over MQTT (paho, keepalive left at default 60). Pi is on the shared Wi-Fi there.
It works for a while after boot, then the device goes offline in Hermetry and the readings stop. The weird bit is that as soon as I SSH in to look (which takes a long time to connect), everything comes back and the device is online again. Feels like the Pi is going to sleep.
The device’s Log tab in Hermetry says:
Disconnected Reason: keepalive_timeout
Is there a sleep mode on Raspberry Pi OS I can turn off? I couldn’t find one in raspi-config.
What I already tried: lowering the publish interval to 1 minute (made it last a bit longer, maybe 40 minutes), a different power supply (official 2.5 A one), and checking dmesg, which shows nothing obvious around the time it drops. The Pi itself is clearly running, because a cron job writing the CPU temperature to a local file every minute keeps writing the whole time, even while Hermetry says offline. I’m on Raspberry Pi OS Bookworm Lite, 32-bit.
I think there’s a screen blanking option in raspi-config, maybe that’s putting it to sleep? Mine turns the HDMI off after 10 min.
It’s headless, no screen at all. I turned blanking off anyway just in case, no change.
Screen blanking won’t do it. Classic Wi-Fi power saving on the Pi’s Broadcom chip, I had the same with a Pi 3B+ in a pump house. The Pi doesn’t sleep, the Wi-Fi does, and incoming packets get delayed or lost. Your paho client sends a ping every 60 s, the answer doesn’t come back in time, Hermetry sees nothing within the keepalive and closes the session, hence keepalive_timeout. Your SSH wakes the radio up, which is why everything comes back then.
Check it:
iw wlan0 get power_save
Power save: on
Turn it off for good on Bookworm with NetworkManager:
sudo tee /etc/NetworkManager/conf.d/wifi-powersave.conf <<EOF
[connection]
wifi.powersave = 2
EOF
sudo systemctl restart NetworkManager
(2 means disabled.) If you’re on an older image with dhcpcd, put iw wlan0 set power_save off in a script that runs after the network is up.
Also make your client reconnect on its own: client.reconnect_delay_set(1, 120) and loop_forever or loop_start, so a short drop fixes itself.
Power save was on. Added the conf file, restarted NetworkManager, and it’s been online for 3 days straight now, no keepalive_timeout in the Log tab since. SSH is instant too, which I hadn’t even realised was related. Thank you Ciaran!
Ha, so the Wi-Fi was asleep, not the Pi. Checking mine now.
- You must be logged in to reply to this topic.
Join the conversation
Sign in to ask and answer, like helpful posts and mark the reply that solved your problem. Every contribution earns points and levels.

