diff --git a/main.py b/main.py index 8ddeaef..f04cd6e 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,27 @@ import requests from rpi_ws281x import * import RPi.GPIO as GPIO import os +try: + from flask import Flask, request +except: + os.system('pip3 install Flask') + os.system('sudo pip3 install Flask') + from flask import Flask, request +import threading + +#Web API +app = Flask(__name__) + +@app.route('/') +def index(): + command = str(request.args.get('command')) + if command == "switch-ilde-mode": + change_idle_mode() + elif command == "switch-toggle-on-off": + power_toggle() + + return command + # LED strip configuration: LED_COUNT = 60 # Number of LED pixels. @@ -66,6 +87,7 @@ def power_toggle(channel): power_button_pressed = 'True' if __name__ == '__main__': + threading.Thread(target=lambda: app.run(host="0.0.0.0", port=80, debug=True, use_reloader=False)).start() led_power = 'True' idle_mode = 1 strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)