Control relay board with REST API on a Raspberry Pi
Under development - current version is a proof of concept only!
Tested with:
- Python 2.7.9
- Bottle 0.12
- gpiozero 1.4.0
- Raspberry Pi 2 running Raspbian Jessie
- Noname "Arduino 4 channel relay module board" from eBay
- Control GPIO output pins with simple REST API
- One output emulates myStrom WiFi Switch API for simple integration into other scripts
- Runs as system service (see scripts/init.d)
-
Install bottle and gpiozero Python libraries:
pip install bottle sudo apt install python-gpiozero
-
Copy this file to /home/pi
or wherever you prefer, e.g. /usr/local/bin
-
Connect relay module board:
- verify if relays are active high or low. Adapt Python script accordingly.
- set BCM pin numbers in Python script
-
Install script as system service:
if this script was not installed in /home/pi: change $DIR and $LOG_DIR in pi-power-api script.
sudo copy ./scripts/init.d/pi-power-api /etc/init.d/ sudo chmod 755 /etc/init.d/pi-power-api sudo update-rc.d pi-power-api defaults
-
Start daemon
sudo service pi-power-api start
- Externalize hard coded values into configuration file
- Support remote GPIO
- Simple web-interface