diff --git a/main.py b/main.py index 4d7aaf0..066879d 100644 --- a/main.py +++ b/main.py @@ -1,16 +1,13 @@ from base64 import b16decode import time -import os from datetime import datetime from requests import request try: from rpi_ws281x import * import RPi.GPIO as GPIO - from flask import Flask, render_template, request, redirect, url_for, flash, jsonify import json from argparse import ArgumentParser - import threading import paho.mqtt.client as mqtt except ImportError: print('Some modules are missing. Try to install them with "pip3 install -r requirements.txt"') @@ -66,99 +63,6 @@ def mqtt_on_connect(client, userdata, flags, rc): if __name__ == '__main__': - app = Flask(__name__) - - #api - @app.route('/api/') - def index(): - return ''' - - - - - - - Server Rack LED stripe - - - -

My Server Rack LED stripe control API

-
-

How to use the API:

- /power?power=True -
- /power?power=False -
- /mode?mode=0 -
- /mode?mode=1&r=0&g=0&b=0 - - - ''' - - @app.route('/api/mode', methods=['GET']) - def mode(): - global mode - global r - global g - global b - args = request.args - mode = str(args.get('mode')) - r = str(args.get('r')) - g = str(args.get('g')) - b = str(args.get('b')) - if mode is None: - return 'No mode specified' - elif mode == "": - return 'No mode specified' - elif mode == "0": - mode = 0 - return 'Rainbow Cycle' - elif mode == "1": - if r is None or g is None or b is None: - return 'No color specified' - elif r == "" or g == "" or b == "": - return 'No color specified' - else: - mode = 1 - return 'Color: '+str(r)+','+str(g)+','+str(b) - - @app.route('/api/power', methods=['GET']) - def power(): - global power - power = request.args.get('power') - if power is None: - return 'No power argument specified' - elif power == "": - return 'No power argument specified' - elif power == "True": - power = "True" - return 'Power: ON' - elif power == "False": - power = "False" - return 'Power: OFF' - def mqtt_on_message(client, userdata, msg): print("topic: " ,str(msg.topic)) print("payload: " ,str(msg.payload.decode("utf-8"))) @@ -191,8 +95,6 @@ if __name__ == '__main__': mode = 0 power = "True" - threading.Thread(target=lambda: app.run(host='0.0.0.0', port=80)).start() - mqttBroker ="homeassistant.ping-mee.local" client = mqtt.Client("server_rack_led") client.username_pw_set("mqtt", "pmMQTT_11!")