From 7b119249e9d5f96148a83dffea2e24d7080698a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Tue, 4 Jan 2022 11:05:11 +0100 Subject: [PATCH] next try --- main.py | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/main.py b/main.py index 0b70746..57bda3f 100644 --- a/main.py +++ b/main.py @@ -73,7 +73,24 @@ def power_toggle(channel): power_button_pressed = 'True' print('Toggle Power executed') -def led_main(): +#Web API +app = Flask(__name__) + +@app.route('/') +def index(): + command = str(request.args.get('command')) + if command == "switch-ilde-mode": + print('Switched Idlemode via API') + change_idle_mode + elif command == "switch-toggle-on-off": + print('Toggled Power via API') + power_toggle + + return command + +if __name__ == '__main__': + threading.Thread(target=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) @@ -122,23 +139,4 @@ def led_main(): time.sleep(1) except KeyboardInterrupt: setColor(strip, Color(0,0,0)) - GPIO.cleanup() - -#Web API -app = Flask(__name__) - -@app.route('/') -def index(): - command = str(request.args.get('command')) - if command == "switch-ilde-mode": - print('Switched Idlemode via API') - change_idle_mode - elif command == "switch-toggle-on-off": - print('Toggled Power via API') - power_toggle - - return command - -if __name__ == '__main__': - threading.Thread(target=lambda: app.run(host="0.0.0.0", port=80, debug=True, use_reloader=False)).start() - threading.Thread(target=lambda: led_main).start() \ No newline at end of file + GPIO.cleanup() \ No newline at end of file