python3 ./main.py
Space Switch handles the hardware space switch and updating the state in the Nova Labs Event Service. Toggling the physical switch updates the Event Service and changes the physical LEDs. The LEDs indicate the current state, and transitions.
Left LEDs | Right LEDs | State |
---|---|---|
RED | RED | CLOSED |
ORANGE | ORANGE | ASSOCIATE |
GREEN | GREEN | OPEN |
GREY | GREY | BOOT |
ANY | GREY | Switch changed, updating Event Service |
GREEN | DARK RED | Changing to CLOSED, Event Service updated, pulling from Event Service |
ORANGE | DARK ORANGE | Changing to ASSOCIATE, Event Service updated, pulling from Event Service |
RED | DARK GREEN | Changing to OPEN, Event Service updated, pulling from Event Service |
ANY | YELLOW | Error connecting to Event Service |
The script runs as root, since it needs write access to /dev/mem. Clone the repository into /root/space_switch.
Configure Event Service URL, in main.py. This is the base URL of the service.
EVENT_SERVICE_BASE_URL="https://event.nova-labs.org"
Install and enable init script. This will start/stop on boot.
cp init.d/space_switch /etc/init.d
systemctl enable space_switch
Manually start/stop.
systemctl start space_switch
systemctl stop space_switch
- Script starts
- Initializes hardware
- LEDs changed to boot color (grey)
- Switch position read
- Update state
- Switch position changed, value read (OPEN/CLOSED)
- Update state
- Right LEDs changed to "state changing" color (grey)
- Event with new state added to Event Service (RESTful POST call)
- Right LEDs changed with "state changed" color
- Dark Green - successfully updated Event Service to OPEN
- Dark Orange - successfully updated Event Service to ASSOCIATE
- Dark Red - successfully updated Event Service to CLOSED
- Yellow - error communicating with Event Service
- Latest event fetched from Event Service (RESTful GET call)
- All LEDs changed to current state color
- Red - CLOSED
- Orange - Associate
- Green - OPEN
- python >= 3.0
- python modules
- json
- logging
- math
- requests
- requests
- signal
- sys
- time
- RPi.GPIO - install via pip3
- adafruit-circuitpython-neopixel - install via pip3
- rpi_ws281x
NeoPixel library (rpi_ws281x)
The NeoPixel library controls the LEDs.
RPi.GPIO library (RPi.GPIO)
The RPi.GPIO library reads the switch position using the GPIO pin outs.
Adafruit CircuitPython Neopixel library (adafruit-circuitpython-neopixel)
The CircuitPython library is now the preferred setup for accessing neopixels