diff --git a/.notes.txt.swp b/.notes.txt.swp deleted file mode 100644 index bcc52d3..0000000 Binary files a/.notes.txt.swp and /dev/null differ diff --git a/__pycache__/fl-app.cpython-37.pyc b/__pycache__/fl-app.cpython-37.pyc new file mode 100644 index 0000000..35bbf51 Binary files /dev/null and b/__pycache__/fl-app.cpython-37.pyc differ diff --git a/fl-app.py b/fl-app.py new file mode 100644 index 0000000..04a1c0c --- /dev/null +++ b/fl-app.py @@ -0,0 +1,29 @@ +#!/usr/bin/python3 + +from flask import request +from flask_api import FlaskAPI +import RPi.GPIO as GPIO + +LEDS = {"green": 16, "red": 18} +GPIO.setmode(GPIO.BOARD) +GPIO.setup(LEDS["green"], GPIO.OUT) +GPIO.setup(LEDS["red"], GPIO.OUT) + +app = FlaskAPI(__name__) + +@app.route('/', methods=["GET"]) +def api_root(): + return { + "led_url": request.url + "led/(green | red)/", + "led_url_POST": {"state": "(0 | 1)"} + } + +@app.route('/led//', methods=["GET", "POST"]) +def api_leds_control(color): + if request.method == "POST": + if color in LEDS: + GPIO.output(LEDS[color], int(request.data.get("state"))) + return {color: GPIO.input(LEDS[color])} + +if __name__ == "__main__": + app.run()