Building the control script
Now that we have designed our system the way we want it to work, we can start writing our Bash control script. As before, we'll locate our scripts in the folder, /etc/pi-alarm
, which, you'll remember from Chapter 7, Building a Web-Based Control Panel, is also where our Web-based control panel writes its configuration status file, alarm.cfg
to. We'll be referring to that file in our scripts too.
In this script, we are going to use the bc tool (the Bash command-line calculator) to convert hex values to binary. It's not installed by default, so you'll need to get the package:
$ sudo apt-get update $ sudo apt-get install bc
Tip
Our script file is quite long so, as before, you might want to sit on the sofa and write it on your laptop using something such as Notepad++. Remember, however, if you're using a PC, ensure that the end-of-line (EOL) format is converted to the Unix format, otherwise the Bash script won't run on the Pi when you copy it across. Notepad++ will do...