#!/usr/bin/python3
import os
os.environ['RPI_LGPIO_REVISION'] = "800012"
import requests
import RPi.GPIO as GPIO
RED = "\033[91m"
GREEN = "\033[92m"
RESET = "\033[0m"
BenBusyRRCSdataRising = '''
PressKeyEx
C0000000001
64
46
0
2
0
1
1
1
1
'''
BenBusyRRCSdataFalling = '''
PressKeyEx
C0000000002
64
46
0
2
0
1
1
0
1
'''
def button_callback(channel):
if GPIO.input(channel):
print(f"{RED}Button pressed{RESET}")
r = requests.post(
'http://10.75.120.229:8193',
headers={'content-type': 'text/xml'},
data=BenBusyRRCSdataRising
)
else:
print(f"{GREEN}Button released{RESET}")
r = requests.post(
'http://10.75.120.229:8193',
headers={'content-type': 'text/xml'},
data=BenBusyRRCSdataFalling
)
print(r.text)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
# One event detector, both edges:
GPIO.add_event_detect(12, GPIO.BOTH, callback=button_callback, bouncetime=200)
input("Press enter to quit\n\n")
GPIO.cleanup()