Skip to content
Go to file
Cannot retrieve contributors at this time
87 lines (66 sloc) 2.85 KB
Huxley - UK Live Train Status Blinky Tape Example
This example uses the Huxley Live Departure Board delays endpoint:
If there are delays between the configured stations then the Blinky Tape will throb red.
To run on default (Raspberry Pi) USB serial port: python &
(C) 2015 James Singleton (
MIT Licensed
import tempfile
import json
from blinkytape import BlinkyTape
from time import sleep
from itertools import chain
import optparse
import sys
if sys.version_info > (3, 0):
import urllib.request as requestlib
import urllib2 as requestlib
# This token will only work on the demo server. You may also want to host Huxley yourself.
# Get a token here:
accessToken = "DA1C7740-9DA0-11E4-80E6-A920340000B1"
# CRS codes here:
crs = "clj" # Clapham Junction
filterCrs = "wat" # to Waterloo
# STD of a specific train to look for (24hr format HHmm) blank for none
trainTime = ""
# Default Blinky Tape port on Raspberry Pi is /dev/ttyACM0
parser = optparse.OptionParser()
parser.add_option("-p", "--port", dest="portname",
help="serial port (ex: /dev/ttyACM0)", default="/dev/ttyACM0")
(options, args) = parser.parse_args()
if options.portname is not None:
port = options.portname
print("Usage: python -p <port name>")
print("(ex.: python -p /dev/ttyACM0)")
url = "{}/to/{}/50/{}?accessToken={}".format(
crs, filterCrs, trainTime, accessToken)
bt = BlinkyTape(port)
# Some visual indication that it works for headless setups (green tape)
bt.displayColor(0, 100, 0)
# Tape resets to stored pattern after a couple of seconds of inactivity
while True:
print("GET %s" % (url))
rawHttpResponse = requestlib.urlopen(url)
stationStatus = json.load(rawHttpResponse)
if not len(stationStatus) or stationStatus is None:
raise Exception("Error parsing data")
alert = stationStatus["delays"] # bool
print("%s to %s - Trains Delayed by over 5 minutes: %s" % (
stationStatus["locationName"], stationStatus["filterLocationName"], stationStatus["delays"]))
# Throb red for delays (or black for none) - takes at least 2 min
for x in range(60):
for y in chain(range(100), range(100, 0, -1)):
bt.displayColor(y * alert, 0, 0)
# Blue indicates an error
bt.displayColor(0, 0, 100)
sleep(120) # wait 2 min
You can’t perform that action at this time.