Recipe: Raspberry Pi à la data

Louise Yang
KPCC Labs
Published in
3 min readFeb 2, 2018
Pear-raspberry pie by elizaraxi

KPCC is an organization that tracks company and team goals based on data. A dashboard of key numbers, trends, and graphs is useful for teams to see how close they are to hitting their goals. Being a newsroom, we have plenty of screens and monitors around. I wanted to find a low cost, low maintenance way to display data to different teams — a way to set it and forget it. Enter Raspberry Pi.

Ingredients:

  • Raspberry Pi starter kit from Canakit ($70)
  • spare monitor
  • URLs for dashboard to display

Directions:

  1. Secure the device by changing the default user (pi) password from raspberry to something else:
$ passwd

2. (optional) Change the root user’s password.

3. Install the TabCarousel extension for Chromium. Set rotation speed to 30 seconds.

4. Deny all incoming traffic using iptables:

# Set default chain policies
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
# Accept on localhost
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
# Allow established sessions to receive traffic
iptables -A INPUT -m conntrack — ctstate ESTABLISHED,RELATED -j ACCEPT

5. Disable screen sleep:

# edit: /etc/lightdm/lightdm.conf
# Add the following to the [SeatDefaults] section:
xserver-command=X -s 0 dpms

6. Create script to rejoin wifi if there is loss in connectivity: /usr/local/bin/wifi_reconnector.sh

#!/bin/bash# Ping the public Google DNS server
SERVER=8.8.8.8
# Only send two pings, sending output to /dev/null
ping -c2 ${SERVER} > /dev/null
# If the return code from ping indicates an error
if [ $? != 0 ]
then
# Restart the wireless interface
sudo ifdown — force wlan0
sudo ifup wlan0
fi

7. Schedule /usr/local/bin/wifi_reconnector.sh to run in root’s crontab:

* * * * * /usr/local/bin/wifi_reconnector.sh

8. Create script to launch Chromium and load URLs for the dashboard. Put script in /home/pi/.config/lxsession/LXDE-pi/chromium_loop.sh:

#!/bin/bash# space-separated URLs
URLS=’DASHBOARD_URL1 DASHBOARD_URL2 DASHBOARD_URL3'

while :; do
/usr/bin/chromium-browser — noerrdialogs — disable-session-crashed-bubble — disable-infobars — kiosk $URLS
sleep 2
done

This script starts Chromium in kiosk mode, which will fullscreen it and prevent people from bringing up right-click menus.

9. Make wifi_reconnector.sh and chromium_loop.sh executable by chmod-ing them with the correct permissions.

10. Add chromium_loop.sh our session autostart:

# In .config/lxsession/LXDE-pi/autostart
@bash /home/pi/.config/lxsession/LXDE-pi/chromium_loop.sh

11. Set it and forget it.

spot the Raspberry Pi

Tips:

Enable ssh traffic to the Raspberry Pi by adding (as the root user) to iptables:

iptables -I INPUT -p tcp --dport 22 -j ACCEPT

Similarly, open port 5900 to allow VNC traffic.

If you need to get your Raspberry Pi’s IP but can’t plug directly into it, you can get it from another computer on the same network. This is based on the fact that the MAC address of Raspberry Pi’s all have B8:27:EB

sudo nmap -sP <ETHERNET_IP/NETMASK> | awk ‘/^Nmap/{ip=$NF}/B8:27:EB/{print ip}’

For example, if your local subnet was 192.168.1.0/24, then this command will produce the IP of the raspberry pi:

sudo nmap -sP 192.168.1.0/24 | awk ‘/^Nmap/{ip=$NF}/B8:27:EB/{print ip}’

If ssh-ing is insufficient and you’d like to do things like logging onto something in the browser, using a VNC client to connect to the device is almost as good as plugging a keyboard and mouse directly into it. On a Mac, I use RealVNC.

--

--