Minimal python HTTP server with CORS support to control RaspberryPi GPIOs, for example to control relays.
You can control up to 24 GPIO.
- download the project
- run
pip install -r requirements.txt
- defines the GPIOs pins to control in server.py
Run with python server.py
/gpio/7
: get pin 7 current status/gpio/7/output/0
: set pin 7 output to GPIO.LOW/gpio/7/output/1
: set pin 7 output to GPIO.HIGH
Sample test UI : https://jsbin.com/mahexo
API returns:
{
"pin": 7,
"value" : true
}
Use the physical port to address the API
Physical port | GPIO# |
---|---|
7 | 7 |
8 | 15 |
10 | 16 |
11 | 0 |
12 | 1 |
13 | 2 |
15 | 3 |
16 | 4 |
18 | 5 |
19 | 12 |
21 | 13 |
22 | 6 |
23 | 14 |
24 | 10 |
26 | 11 |
29 | 21 |
31 | 22 |
32 | 26 |
33 | 23 |
35 | 24 |
36 | 27 |
37 | 25 |
38 | 28 |
40 | 29 |
- add
/home/pi/httprelay/start.sh &
to your/etc/rc.local
- the sample
start.sh
script shows how to start the process in a screen session