These are very brief instructions on how to set up the Raspberry PI, including:
- Install Apache and PHP to host the web user interface
- Install web pages and script to enable the interface between the raspberry and the arduino
- Set up passwords for some of the admin functions
- Configure BIND, to provide DNS services (optional).
Before you start, download software2016R2.zip and copy it on to your raspberry.
2016 UPDATE: Alternatively you can download the scoreboard-web-interfacev2.zip developed by Chris R at Bradford upon Avon CC (see details of their build here). As you will see from the online demo that Chris hosts, there are a number of enhancements to the user interface which I really like. Note that in this code the overs and wickets have been swapped around.
Completing basic setup of the Raspberry
There are lots of guides on how to do this, including the quick start. Some basic understanding of any Linux operating system will help, it is likely someone in your club will know the basics. If you really need to, then you can get a book!
As an absolute minimum, you will need to connect the Raspberry to a network, and give it access to the Internet. Once you have completed the setup, you will need to give the device a static IP address.
You will also need to disable console output to the serial port. You can do this by running:
Choose Advanced options and disable serial console, before rebooting the pi
Install Apache and PHP
Before installing any software, tell the software installer to update itself:
sudo apt-get update
When this completes (it may take some time) , you can install apache and php with the following command:
sudo apt-get install apache2 php5 libapache2-mod-php5
Apache needs a basic configuration change, to allow you to use htaccess override file (which we use to password protected the shutdown and reboot functions from the admin page). To do this on Wheezy open /etc/apache2/sites-available/default or /etc/apache2/sites-available/000-default.conf in an editor, and update the AllowOverride directive. On Jessie, open the /etc/apache2/apache2.conf file and find the <Directory /var/www/> section and modify the AllowOverride section there.
Once the config has been updated, you will need to restart Apache with the following command:
sudo service apache2 restart
As we are using the PHP-SERIAL library to send scoreboard updates to the Arduino, we need to allow apache to interact with he USB port. To enable this, we need to add the apache user to the dialout group with the following command:
sudo usermod -a -G dialout www-data
Installing the UI
Unzip software2016R2.zip, and use the tar command to unpack the raspberry web pages and script. Copy the webpages to the /var/www/ directory, and change the ownership to allow apache to serve them correctly:
unzip software.zip tar -zxvf raspberry.tgz sudo cp -r var/www/* /var/www/ sudo chown -R www-data: /var/www
The UI should now be displayed, by using a web browser to connect to the Raspberry. Note: the UI works best using Chrome, Firefox or a mobile device web browser. The UI does not operate correctly in Internet Explorer.
Now navigate in to the reboot directory from the web root. Issue the following command to set the reboot password:
sudo htpasswd .reboot.password reboot
Repeat the last step from the shutdown directory with the following command:
sudo htpasswd .shutdown.password shutdown
Setting up the scripts
Now copy the scoreboard scripts to the /usr/local/bin/scoreboard directory.
sudo mkdir /usr/local/bin/scoreboard sudo cp -r usr/local/bin/scoreboard/* /usr/local/bin/scoreboard/ sudo chown -R root: /usr/local/bin/scoreboard/ sudo chmod 755 /usr/local/bin/scoreboard/*.sh
Once the scripts are in place, change to the root user and edit the crontab with the following command:
sudo su - crontab -e
Add the following lines to the bottom of the file before saving and closing (ctrl x):
* * * * * /usr/local/bin/scoreboard/checkReboot.sh * * * * * /usr/local/bin/scroreboard/checkShutdown.sh @reboot /usr/local/bin/scoreboard/loadSerialSettings.sh @reboot /usr/local/bin/scoreboard/cleanup.sh
What the scripts do
loadSerialSettings.sh – Loads default serial settings for the Arduino serial port, including speed and duplex. If this is not in place, speed and duplex will not be consistent and the Arduino will not work
readFromSerial.sh – This script can be run manually as root, reading response codes from the Arduino and writing them to /var/log/scoreboard.log Note this script does not run automatically.
checkReboot.sh – This script runs every minute from cron. It looks for reboot.server file in /var/www/reboot directory (put there from the admin.htm file), and reboots the raspberry
checkShutdown.sh – This script runs every minute from cron. It looks for shutdown.server in /var/www/reboot directory (put there by the admin.htm file), and shuts down the raspberry.
Setting up Bind for DNS
We wanted to make it simple for the scorer to connect to the scoreboard, using a domain name and not a IP address. To do this, we need to install Bind on the Raspberry Pi.
The following article from Sam Culley provides an excellent tutorial on how to complete this. You will need to make sure that your Raspberry Pi can access the Internet before you install the Bind software.
The bind configs we used are here, to give you an example. This is based on:
- woscc.org.uk is the domain name we want to use
- Scoreboard is the host name of the raspberry pi running the scoreboard software
- The raspberry pi has the IP address of 192.168.1.5
- The wireless gateway is 192.168.1.1