--- title: internet alarm subtitle: whens the internet coming back? author: david marsh date: 2023-08-30 keywords: [raspberry pi, piface, internet alarm] abstract: Recently we've had some internet outages. --- Whenever the internet would go down I'd be asked by nearly everyone "Is the internet down?" and "When's it coming back?" [![Currently undergoing an internet outage]][110948218029284428] [![Well the nbn has been out most of the day]][110950233108236967] I can't automate the answer to the second question about when it'll be back[^1] but the first I certainly can. Previously the we'd check a light on the router, but it's hard to see, and where's the fun in that when you can have an over-the-top solution instead? So, in the spirit of an almost [useless device], I made an "The Internet is (still) down!" flashy light thing using an old [Raspberry Pi], a [PiFace IO board] and a cheap kids toy. First step was to install the older [Raspberry Pi OS Lite (Legacy)][pios] version, as this Pi is getting old in the tooth. As the Pi is basically doing nothing for the majority of the time, there's no point using a higher spec Pi for this job. Another advantage is of this Pi is that it is hardwired network only, providing a more reliable connection than wifi. One day I may replace it with a [Raspberry Pi Pico], but for now this is good enough. First the standard stuff; make sure the PiFace board is installed, copy the OS to the SD Card, connect the power and network, and confirm I could ssh to the device. I updated the OS and installed the needed software: ``` apt-get update apt-get upgrade apt-get install pifacecommon pifacedigitalio ``` I then downloaded and ran the `blink.py` test program from the [PiFace github examples]. The light stared blinking and everything was working as expected. Somewhere I'd gotten a cheap orange flashing light and it was perfect for this as it's way over the top. Previously I'd swapped out the switch with wires for using with the PiFace board and now I finally had an excuse to use it in a "real" project. So I connected the wires to relay0 in the PiFace board, connecting one wire to common and one to normally open. It doesn't matter which way around the wires are. Here's the very simple code that I use to turn the light on: `light_on.py`: ``` python #!/usr/bin/python3 import pifacedigitalio if __name__ == "__main__": pifacedigital = pifacedigitalio.PiFaceDigital() pifacedigital.relays[0].turn_on() ``` and this is to turn it off: `light_off.py`: ``` python #!/usr/bin/python3 import pifacedigitalio if __name__ == "__main__": pifacedigital = pifacedigitalio.PiFaceDigital() pifacedigital.relays[0].turn_off() ``` Testing went well; light on, light off, light on, light off. I then added a job to ping my ISP every 2 mins in cron. If the ping is successful it runs `light_off.py`, otherwise it runs `light_on.py`. ``` bash */2 07-22 * * * if ping -c2 nnn.nnn.nnn.nnn >/dev/null 2>&1 ; then /home/rdm/light_off.py ; else /home/rdm/light_on.py ; fi ``` So we don't wake everyone up in the middle of the night, the cron script only runs between 7am and 11pm. At 11pm the off job will run just to make sure the light is off: ``` bash 00 23 * * * /home/rdm/light_off.py ``` If the Pi can't ping my ISP, everyone will be able to quickly tell with this helpful, highly visible and stress-inducing light: ![flashing orange light](internet_alarm.gif "oh no the internet is down") Now I just need to have it answer "When’s it coming back?" with "I don’t know" and I've automated 90% of the home admin work I do. [^1]: Generally the answer to when is it coming back is "I don't know" [Currently undergoing an internet outage]: 110948218029284428.webp "Currently undergoing an internet outage" [Well the nbn has been out most of the day]: 110950233108236967.webp "Well the nbn has been out most of the day" [110948218029284428]: https://mastodon.au/@davidmarsh/110948218029284428 "Currently undergoing an internet outage" [110950233108236967]: https://mastodon.au/@davidmarsh/110950233108236967 "Well the nbn has been out most of the day" [useless device]: https://en.wikipedia.org/wiki/Useless_machine [Raspberry Pi]: https://www.pololu.com/product/2750 [PiFace IO board]: https://core-electronics.com.au/piface-digital-i-o-expander.html [pios]: https://www.raspberrypi.com/news/new-old-functionality-with-raspberry-pi-os-legacy/ [PiFace github examples]: https://github.com/piface/pifacedigitalio/blob/master/examples/blink.py [Raspberry Pi Pico]: https://www.raspberrypi.com/products/raspberry-pi-pico/