Ping and Repower

Using our LieberLieber PiSaint Solution (http://blog.lieberlieber.com/2015/07/14/home-automation-made-easy-with-pisaint-1/) enables us to develop such a solution to re-power instable Internet Access Routers of some providers.

1.) Ping 8.8.8.8 (it is google.com and should be alive 24/7)

2.) on error: turn off power of power sockets (default is on, off is set with high)

3.) wait 10 secs

4.) turn on power of power sockets again

5.) wait 10 mins

6.) goto 1.)

Here the bash script (developed by our junior, junior engineers)


gpio -g mode 21 out
gpio -g write 21 0
while true
do
ping 8.8.8.8 -c 1 > ping.txt
a=$(grep -r  -i 'errors' ping.txt)
if [ ! -z '$a' ];
then
gpio -g write 21 1
sleep 10
gpio -g write 21 0
fi
sleep 6000
done

Of course there is an entry in /etc/rc.local to start this script.