Last active
July 26, 2017 18:00
-
-
Save LucaTNT/d3218f33ab1372fc9d423842950df3c6 to your computer and use it in GitHub Desktop.
Script that triggers a relay connected to GPIO 25 on a Raspberry Pi in order to open a garage door
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
#!/usr/bin/env python | |
from gpiozero import LED, Button | |
from time import sleep | |
from flask import Flask | |
import datetime | |
portone = LED(25) | |
app = Flask(__name__) | |
@app.route('/') | |
def index(): | |
return '{"door-state": "closed"}' | |
@app.route('/apriGarage', methods=['GET', 'PUT', 'POST']) | |
def openDaGatePlz(): | |
portone.off() | |
sleep(1) | |
portone.on() | |
with open('/var/log/garage', 'a') as outf: | |
outf.write(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + '\n') | |
return '{"door-state": "closed"}' | |
if __name__ == '__main__': | |
app.run(debug=True, host='0.0.0.0') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment