Initial code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http.server | |
import socketserver | |
import RPi.GPIO as GPIO | |
import time | |
PORT = 31234 | |
chan = 7 | |
doDoor = False | |
uuid = 'some-random-uuid-token-here' | |
class MyHandler(http.server.SimpleHTTPRequestHandler): | |
def do_HEAD(self): | |
self.send_response(200) | |
self.send_header("Content-Type", "application/json") | |
self.end_headers() | |
def do_GET(self): | |
if not self.path.startswith('/' + uuid): | |
self.send_response(403) | |
self.end_headers() | |
return | |
self.send_response(200) | |
self.send_header("Content-Type", "application/json") | |
self.end_headers() | |
self.wfile.write(b"[]") | |
global doDoor | |
doDoor = True | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(chan, GPIO.OUT) | |
GPIO.output(chan, GPIO.LOW) | |
Handler = MyHandler | |
with socketserver.TCPServer(("", PORT), Handler) as httpd: | |
while True: | |
doDoor = False | |
GPIO.output(chan, GPIO.LOW) | |
httpd.handle_request() | |
if doDoor: | |
print("Actuating door...") | |
time.sleep(1) | |
GPIO.output(chan, GPIO.HIGH) | |
time.sleep(7) | |
GPIO.output(chan, GPIO.LOW) | |
print("Door done.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment