This blog is also available on Gemini (What's Gemini?)

Keep WiFi Alive on Raspberry Pi

2014-11-16

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.