So solving my connection problems to a Pi by turning off power savings didn’t work. I’m now using a crude but effective method where the Pi pings the gateway every 2 minutes.
Start by adding this script to /etc/keepalive.sh:
#!/bin/bash PING_HOST="10.0.0.1" SECONDS_BETWEEN_PINGS=120 while : do ping -c 1 ${PING_HOST} > /dev/null sleep ${SECONDS_BETWEEN_PINGS} done
This script works in an infinite loop, sending a single ping every 120 seconds. Call chmod 755 /etc/keepalive.sh
to make it executable. Next, call it from /etc/rc.local:
/etc/keepalive.sh &
Which will run the script on the next reboot. Call /etc/keepalive.sh &
in a shell to start it running, and you’re done.
So far, this seems to make ssh connections start immediately every time. I’d like to figure out what the actual problem is, but this will do.
You could instead add an entry to the pi user’s crontab, something like:
*/2 * * * * ping -q -W 1 -c 1 10.0.0.1 > /dev/null
This will attempt to ping your gateway every two minutes, with a timeout of one second so the command doesn’t hang if your network’s down.