Added Flask Web API
parent
8148458496
commit
0e058b3b1c
22
main.py
22
main.py
|
@ -3,6 +3,27 @@ import requests
|
||||||
from rpi_ws281x import *
|
from rpi_ws281x import *
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
import os
|
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 strip configuration:
|
||||||
LED_COUNT = 60 # Number of LED pixels.
|
LED_COUNT = 60 # Number of LED pixels.
|
||||||
|
@ -66,6 +87,7 @@ def power_toggle(channel):
|
||||||
power_button_pressed = 'True'
|
power_button_pressed = 'True'
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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'
|
led_power = 'True'
|
||||||
idle_mode = 1
|
idle_mode = 1
|
||||||
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
|
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
|
||||||
|
|
Loading…
Reference in New Issue