Fixing Zero 2W suspending itself restricting ssh login

 

It is frustrating when a process you expect to work all the time only works intermittently. Using ssh to login into a headless device should be deterministic. The device has ssh enabled and the sshd server enabled and running, the Avahi server for mDNS is also running so you expect that ssh into <host>.local will work. Unfortunately sometimes it does not.

In my repository of Raspberry Pi hardware, I have a Pi Zero 2W which is a training ground for learning about flask. It was setup using the usual methods documented by Raspberry Pi. At times the Zero would not let me login via ssh. The board was powered up with a standard Pi USB power supply and usually I could just ssh in. However there were many instances where ssh would result in an "Unknown host error" message or "Could not resolve error" message. 

After fixing the ssh problems with the Pi 5 earlier, I decided to investigate whether the same fix is applicable to the Zero 2W. Research indicated that the Zero 2W has a powersave feature. Previous Pi boards have this feature disabled as a default. Unfortunately the Zero 2W Pi has the feature enabled as a default. This means that the Pi would go to sleep. Attempting to ssh with <hostname>.local or with the internal LAN address did not work. The only solution is a reboot ... which I got tired of doing. 

Check if the power save feature is enabled using: 

  • iw wlan0 get power_save 

If on then you will see

  • power_save: on

 Of the several solutions suggested, 2 recent and plausible fixes were:

  1.  Use a crontab so that when the Zero is booted powersave is disabled 
  2.  Use nmcli to disable powersave. 

I used both. Here they are in detail.

  1.     Using a crontab
       sudo crontab -e
  • @reboot  /usr/sbin/iw wlan0 set power_save off > /home/username/power_save_log.txt 2>& 1
  • ensure you have the @ at the start and the appropriate username 
  1.  use nmcli (install nmcli if you do not have it available)
  •  sudo nmcli con mod preconfigured power_save disable
  • sudo reboot

I might look into putting the 2nd fix into a crontab too if there are still issues.

After the reboot, ssh worked fine. I logged out, tried again after a couple of hours and it continued to work. Next step is to leave it for a day or so and firstly see if it has locked up my terminal and then try to ssh once more.

I will update the post when I find out if the solutions have worked.

Update: Since implementing the above fixes logging into the Zero 2W has worked flawlessly overnight and after multiple reboots.

Cheers

 

Popular posts from this blog

Raspberry Pi 5 with NVME Base Duo and 256 SSD

Installing the NVME Base Duo