Added Flask Web API

master
Ebbe Baß 2022-01-04 02:33:29 +01:00
parent 8148458496
commit 0e058b3b1c
1 changed files with 22 additions and 0 deletions

22
main.py
View File

@ -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)