-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f47cc40
commit 8c9c68c
Showing
6 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
TOKEN=sigbvddvujkbsihxhktp | ||
LED_PIN=18 | ||
TIMES_TO_BLINK=5 | ||
SECONDS_TO_BLINK_ON=2 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from flask import Flask, request, make_response, abort | ||
from ledapi import led | ||
from dotenv import load_dotenv | ||
import os | ||
|
||
load_dotenv() | ||
app = Flask(__name__) | ||
|
||
TOKEN = os.getenv('TOKEN') | ||
LED_PIN = os.getenv('LED_PIN') | ||
TIMES_TO_BLINK = os.getenv('TIMES_TO_BLINK') | ||
SECONDS_TO_BLINK_ON = os.getenv('SECONDS_TO_BLINK_ON') | ||
|
||
|
||
@app.route('/warning-light/<token>', methods=['POST']) | ||
def warning_light(token): | ||
if request.method == 'POST': | ||
if token == os.getenv(TOKEN): | ||
led.go(LED_PIN, num_times=TIMES_TO_BLINK, seconds_on=SECONDS_TO_BLINK_ON) | ||
return make_response(('', 202)) | ||
else: | ||
abort(401) | ||
else: | ||
abort(501) | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(debug=True, port=5000) |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import RPi.GPIO as GPIO | ||
import time | ||
|
||
|
||
def setup(led_pin): | ||
# setup | ||
GPIO.setmode(GPIO.BOARD) | ||
GPIO.setwarnings(False) | ||
GPIO.setup(led_pin, GPIO.OUT, initial=GPIO.LOW) | ||
|
||
|
||
def blink_led(led_pin, num_times=1, seconds_on=1): | ||
i = 1 | ||
while i <= num_times: | ||
# led on | ||
GPIO.output(led_pin, GPIO.HIGH) | ||
time.sleep(seconds_on) | ||
# led off | ||
GPIO.output(led_pin, GPIO.LOW) | ||
|
||
|
||
def tear_down(): | ||
GPIO.cleanup() | ||
|
||
|
||
def go(led_pin, num_times, seconds_on): | ||
setup(led_pin) | ||
blink_led(led_pin, num_times=num_times, seconds_on=seconds_on) | ||
tear_down() | ||
|
||
|
||
if __name__ == '__main__': | ||
go(18, 5, 2) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Click==7.0 | ||
Flask==1.0.2 | ||
itsdangerous==1.1.0 | ||
Jinja2==2.10 | ||
MarkupSafe==1.1.0 | ||
pkg-resources==0.0.0 | ||
RPi.GPIO==0.6.5 | ||
Werkzeug==0.14.1 |