-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpio.py
42 lines (33 loc) · 982 Bytes
/
gpio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import RPi.GPIO as GPIO
from time import sleep
import requests
API_URL = 'http://192.168.178.39:9094'
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(8, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP)
pinsEndpoints = [
{
'pin': 10,
'endpoint': '/room-toggle'
},
{
'pin': 8,
'endpoint': '/room-scene/Vibing'
},
{
'pin': 12,
'endpoint': '/room-scene/Relax'
}
]
def togglePin(pinNum, endpoint):
input_state = GPIO.input(pinNum)
if input_state == False:
print('doing req too: ' + API_URL + endpoint)
response = requests.get(API_URL + endpoint)
print('btn pressed', response.text)
while True:
for i in range(len(pinsEndpoints)):
togglePin(pinsEndpoints[i]['pin'], pinsEndpoints[i]['endpoint'])
sleep(0.2)