status-tower
Software powering my Raspberry Pi build server status tower light
API server
src/server.py is a small HTTP API for controlling the tower. It uses only the
Python standard library (plus RPi.GPIO on the Pi).
STATUS_TOWER_TOKEN=change-me python3 src/server.py
| Variable | Default | Description |
|---|---|---|
STATUS_TOWER_TOKEN |
required | Token clients must send in the X-API-Token header |
STATUS_TOWER_HOST |
0.0.0.0 |
Bind address |
STATUS_TOWER_PORT |
8080 |
Bind port |
STATUS_TOWER_LIGHT_SHOW |
1 |
Set to 0 to skip the startup light show |
STATUS_TOWER_MOCK |
unset | Set to 1 to run without GPIO hardware |
Endpoints
Every request needs the X-API-Token header.
GET /state: the current state of every color.
POST /state: set one or more colors. Each color can be "on", "off",
or a blink interval {"on_ms": N, "off_ms": N} (minimum 50ms each). You can set
"others_off": true to turn off any unspecified colors.
curl -H 'X-API-Token: change-me' -d '{
"colors": {
"red": "on",
"green": {"on_ms": 500, "off_ms": 1500}
},
"others_off": true
}' http://tower.local:8080/state
Both endpoints respond with the resulting state:
{
"red": {"mode": "on"},
"yellow": {"mode": "off"},
"green": {"mode": "blink", "on_ms": 500, "off_ms": 1500},
"blue": {"mode": "off"}
}
Valid colors are red, yellow, green and blue.
Delayed changes
Add "delay_s": N (seconds, fractions allowed) to apply the change after a
delay.
# Show green now, then turn everything off in 5 minutes unless something else happens first
curl -H 'X-API-Token: change-me' -d '{"colors": {"green": "on"}, "others_off": true}' http://status-tower.local:8080/state
curl -H 'X-API-Token: change-me' -d '{"others_off": true, "delay_s": 300}' http://status-tower.local:8080/state
Languages
Python
100%