Skip to content

Instantly share code, notes, and snippets.

@jbonney
Last active August 29, 2015 14:22
Show Gist options
  • Save jbonney/d2b88fcb9512d8abec1b to your computer and use it in GitHub Desktop.
Save jbonney/d2b88fcb9512d8abec1b to your computer and use it in GitHub Desktop.
Script to check the internet connection of a kiosk and reload the active page in case the connection drops and then comes back online. Sources: -http://alexba.in/blog/2015/01/14/automatically-reconnecting-wifi-on-a-raspberrypi/ - http://raspberrypi.stackexchange.com/questions/6981/auto-refresh-for-midori - http://www.lynsayshepherd.com/blog/2014…
*/2 * * * * DISPLAY=:0 sh /usr/local/bin/wifi_reloader.sh
#!/bin/bash
# The IP for the server you wish to ping (8.8.8.8 is a public Google DNS server)
# SERVER=8.8.8.8
# Only send two pings, sending output to /dev/null
# ping -c2 ${SERVER} > /dev/null
# Using alternative method to pinging to check if the page exists
wget -q --spider http://www.google.com
# If the return code from ping / wget ($?) is not 0 (meaning there was an error)
if [ $? != 0 ]
then
# Exit full screen in case of error
xdotool search --onlyvisible "Chromium" windowactivate --sync key F11
# Restart the wireless interface
sudo ifdown --force wlan0
sudo ifup wlan0
# Sleep for 45 seconds to give a chance to the network adapter to get an IP
sleep 45s
# Reload the active page (Google Analytics)
xdotool search --onlyvisible "Chromium" windowactivate --sync key F5
# Restore full screen once connection is established
xdotool search --onlyvisible "Chromium" windowactivate --sync key F11
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment