Skip to content
Martin Beckmann edited this page Sep 5, 2016 · 1 revision

Scoreboard Software on the Raspberry Pi

This wiki describes the software preparations necessary to control a scoreboard based upon the software in the bigdisp repositories. All software was run and tested on both a raspberry pi version 3 and a raspberry pi version 1. Including the preparations described in this wiki, it should be possible to use either version of the pi to control the board. The drawback of version 1, however, is that it does not bring a wifi module and therefore needs an external usb wifi dongle which supports access point mode. This is not the case for every dongle so check carefully that the dongle you choose supports it.

The configuration described in the following will set up the raspberry pi to work as an access point for arbitrary clients and redirect almost any web address to the local webserver run on the raspberry pi so that users connecting to the board will have no trouble controlling it. It will setup the example page in this software repository to control the board and make it the default website that is shown when the pi is addressed. The raspberry pi does not need a connection to the board for the configuration, only for the final test a connection is recommended.

Requirements

  • Raspberry Pi of any version
  • If older than version 3, a usb wifi dongle capable of access point mode
  • An SD card containing a recent version of Raspian.
  • An internet connection and a power supply for the raspberry pi.
  • Some way to control the raspberry pi, e.g. a ssh connection via LAN (not wifi, since we will reconfigure that connection) or direct control using a local keyboard and screen. No graphical interface is required.

Preparations

To prepare the raspberry pi, start the configuration tool by typing sudo raspi-config into the console. Go to 9 Advanced Options and enable the i2c interface in A6 I2C. You can also change the hostname of the raspberry pi to something different here (e.g. "scoreboard") if you wish, but that is not required. Next, turn off desktop boot by returning to the main menu and navigating to 2. Boot options and selecting B1 Console. This will speed up the boot process since the desktop will not be needed when the raspberry pi controls the scoreboard. It is also recommended to change the login password for the user pi from the default to provide some sort of security on the board.

Next, install the additional required software by updating the package sources with sudo apt-get update and then typing sudo apt-get install i2c-tools apache2 git php5 iw hostapd dnsmasq. This will install apache and php for the web interface, the i2c-tools for communicating with the board via i2c and hostapd and dnsmasq for the access point mode. The iw package is used to check for compatibility of the wifi dongle. If you use a raspberry pi of version 3, you can omit that package since the integrated wifi module is supported by default. More recent versions of PHP should be possible.

Configuration

Web Interface

We start by configuring the web interface of the raspberry pi:

  • Navigate to /var/www/html (cd /var/www/html).
  • Make your current user the owner of /var/www/html (sudo chown pi /var/www/html).
  • Download the web frontend via git to /var/www/html/scoreboard-php-api/ (git clone https://github.com/bigdisp/scoreboard-php-api.git scoreboard-php-api)
  • Copy the file /var/www/html/scoreboard-php-api/src/example/index.php to /var/www/html/index.php and adjust the path information at the top of the new file.
  • Create a file /var/www/html/scoreboard_data.txt (sudo touch scoreboard_data.txt) and make it writeable by the webserver (sudo chown www-data:www-data scoreboard_data.txt)
  • Compile the file /var/www/html/scoreboard-php-api/csrc/main.c (gcc -O2 -o shutdown main.c or cc -O2 -o shutdown main.c). Name the resulting executable shutdown and place it in the same folder. It must belong to root (sudo chown root:root shutdown) and the suid bit must be set (chmod u+s shutdown).
  • Create symbolic links in /var/www/html for /var/www/html/scoreboard-php-api/src/example/scoreboard and /var/www/html/scoreboard-php-api/csrc/shutdown (ln -s path linkname)
  • Delete /var/www/html/index.htm
  • Enable mod rewrite on apache
  • copy the .htaccess file from /var/www/html/scoreboard-php-api/src/example/ to /var/www/html/. Replace local IPs in the file if your IPs deviate.
  • Restart apache (sudo apachectl restart)

You should now be able to control the board by accessing the raspberry pi using its web interface by navigating to the raspberry pis local IP. If the local IP is 192.168.0.2 for example, type http://192.168.0.2 into your browser.

Wifi Accesspoint

Next we need to setup dnsmasq and hostapd. Following the steps below will mess up the dns resolution of the raspi. This can always be tempoarily repaired by disabling dnsmasq, which is responsible for the confusion because it redirects almost all dns requests to the raspberry pis own webserver. If this is not desired and you wish to redirect only specific adresses to the scoreboard, only a slight alteration to the configuration of dnsmasq is required.

This section was created mostly based upon the ubuntuusers.de wiki page on "WLAN Router", but there is a large number of other pages describing how to configure access point mode using hostapd and dnsmasq. After finishing the steps in the two following sections, you should be able to connect to your raspberry pis wifi named "Scoreboard" and any webpage you try to open should be redirected to the scoreboard control.

hostapd

We need to set the wifi interface to acesspoint mode. First check, whether your wifi dongle is capable of this by typing iw list when the dongle is connected. This should output a long list of information, including a category named "Supported interface modes:". In the list that follows, an entry "AP" can be found if the dongle supports access point mode. If no such list is output, you might be missing a driver for your dongle or it is not supported by hostapd, check the internet to see how to install your dongle correctly.

First, we need to configure a static IP for the wifi interface. You can do this by editing /etc/network/interfaces and removing or commenting all entries for your wifi adapter and then adding:

# Static IP for wlan0
allow-hotplug wlan0
iface wlan0 inet static
    address 192.168.2.1
    netmask 255.255.255.0
    network 192.168.2.0
    broadcast 192.168.2.255

Next, create a configuration file for hostapd by creating /etc/hostapd/hostapd.conf with the following content:

# Interface and driver (adjust driver if you use an external dongle)
interface=wlan0
driver=nl80211

# Wifi configuration
ssid=Scoreboard
channel=1

# ESSID visible
ignore_broadcast_ssid=0

# Country settings (germany)
country_code=DE
ieee80211d=1

# Transmission band and channel (2.4 ghz)
hw_mode=g
channel=6

# Optional settings
# supported_rates=10 20 55 110 60 90 120 180 240 360 480 540

# activate draft-n mode (optional, only for appropriate wifi adapters)
ieee80211n=1

# wmm-functionality
wmm_enabled=1

# Transmission mode / bandwidth 40MHz
# ht_capab=[HT40][SHORT-GI-40][DSSS_CCK-40]

# Beacons
beacon_int=100
dtim_period=2

# MAC-authentication
macaddr_acl=0

# max number of clients
max_num_sta=20

# Size of data packages
rts_threshold=2347
fragm_threshold=2346

# hostapd log settings
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2

# temporary config files
dump_file=/tmp/hostapd.dump
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0

# Authentication, encryption
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
wpa_passphrase=thisIsTheWifiPasswordPleaseChangeMe2

Please make sure you change the wifi password in the last line to something sensible or random.

dnsmasq

The configuration for dnsmasq can be found in /etc/dnsmasq.conf. You can alternatively also create your own configuration file in /etc/dnsmasq.d/, but in the following, the alterations to /etc/dnsmasq.conf are described instead. It is assumed that the wifi IP of the raspberry pi was set to 192.168.2.1 above. You will need to adjust the IP adresses and dhcp range appropriately if you chose a different address.

  1. Enforce several tld to be redirected to the local ip:

      address=/com/192.168.2.1
      address=/de/192.168.2.1
      address=/net/192.168.2.1
      address=/scoreboard/192.168.2.1
    
  2. Limit the interface to wifi:

      interface=wlan0
    
  3. Set the dhcp range appropriately:

      dhcp-range=interface:wlan0,192.168.2.10,192.168.2.100,12h