Network Check Script installation - markmac99/ukmon-pitools GitHub Wiki

You will need some familiarity with Linux to use this script.

  • Download the script from here (if the link opens in your web browser then right click and select Save As).
  • Copy it to /home/pi on your Pi.
  • Make sure the file is in unix format as follows:
    • open the Pi's file manager and locate the file.
    • right-click on it and select "Text Editor". The file will open in an editor.
    • If you're using a Pi3, select File/Save-As and make sure the line ending "LF" is selected in the box above the Save button. If it says CR or CR+LF then change it to LF and save the file.
    • If you're using a Pi4, select Document/Line Endings and make sure its set to Unix(LF) and then save the file.
  • Now replace MYROUTER with your router's IP address.
  • Save and exit the Text Editor then right click on the file again. This time select Properties.
    • On the Permissions tab, set Execute to Only Owner then click OK.
  • Now open a Terminal window and type the following:
EDITOR=nano crontab -e
  • This will open a new editor window where we are going to add a scheduled job that will start the script every time the Pi is rebooted.
  • Go to the bottom of the file and insert a new line containing the following exactly:
@reboot sleep 300 && /home/pi/networkCheck.sh >/dev/null 2>&1
  • Press Control-X to exit and press Y to save changes.
The script will now start five minutes after the Pi is rebooted and will check the network connection every minute. If it can't contact your router, it will wait 30 seconds and try again, then it will stop and restart the wifi.

Checking it is Working

Open a terminal window and type

grep networkCheck /var/log/messages
You'll see something like this:
(vRMS) pi@testpi4:~/source/RMS $ grep networkCheck /var/log/messages
Nov 21 09:54:53 testpi4 networkCheck: starting
Nov 21 10:06:27 testpi4 networkCheck: wifi went off
⚠️ **GitHub.com Fallback** ⚠️