From 4d2e67a29a367aede813b1906150027236ef47c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Wed, 27 Jul 2022 15:46:21 +0200 Subject: [PATCH] changed order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- main.py | 91 +++++++++++++++++++++++++++--------------------- requirements.txt | 2 +- 2 files changed, 52 insertions(+), 41 deletions(-) diff --git a/main.py b/main.py index 12f2221..c090db3 100644 --- a/main.py +++ b/main.py @@ -155,49 +155,60 @@ if __name__ == '__main__': mode = 3 elif payload == "Random Color per LED": mode = 4 + + if os.path.isfile(current_path+r'/.env') == False: + # If not create it and add content + with open(current_path+r'/.env', 'w') as f: + var_lines = ["SPOTIPY_CLIENT_ID = ", "SPOTIPY_CLIENT_SECRET = ", "SPOTIPY_USER_NAME = ", "SPOTIPY_REDIRECT_URI = "] + for var_line in var_lines: + f.write(var_line+'\n') + print('Please fill out the variables in the .env file ( '+current_path+r'/.env )') + exit() + else: + load_dotenv() - strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) - strip.begin() + strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) + strip.begin() - mode = 0 - power = "True" - global r - r = 255 - global g - g = 255 - global b - b = 255 + mode = 0 + power = "True" + global r + r = 255 + global g + g = 255 + global b + b = 255 - mqttBroker ="homeassistant.ping-mee.local" - client = mqtt.Client("server_rack_led") - client.username_pw_set("mqtt", "pmMQTT_11!") - debug_print("Connecting to MQTT Broker "+str(mqttBroker)) - client.connect(mqttBroker) - client.on_connect = mqtt_on_connect - client.on_message = mqtt_on_message + mqttBroker ="homeassistant.ping-mee.local" + client = mqtt.Client("server_rack_led") + client.username_pw_set("mqtt", "pmMQTT_11!") + debug_print("Connecting to MQTT Broker "+str(mqttBroker)) + client.connect(mqttBroker) + client.on_connect = mqtt_on_connect + client.on_message = mqtt_on_message - client.publish("server-rack-led/power", "True") - client.publish("server-rack-led/mode", "Rainbow") + client.publish("server-rack-led/power", "True") + client.publish("server-rack-led/mode", "Rainbow") - try: - client.loop_start() - while True: - if power == "True": - if mode == 0: - rainbowCycle(strip) - elif mode == 1: - setColor(strip, Color(int(r), int(g), int(b))) - elif mode == 2: - strobe(strip, Color(int(r), int(g), int(b))) - elif mode == 3: - randomColor(strip) - elif mode == 4: - randomColorPerLED(strip) - else: - setColor(strip, Color(0,0,0)) + try: + client.loop_start() + while True: + if power == "True": + if mode == 0: + rainbowCycle(strip) + elif mode == 1: + setColor(strip, Color(int(r), int(g), int(b))) + elif mode == 2: + strobe(strip, Color(int(r), int(g), int(b))) + elif mode == 3: + randomColor(strip) + elif mode == 4: + randomColorPerLED(strip) + else: + setColor(strip, Color(0,0,0)) - except KeyboardInterrupt: - client.publish("server-rack-led/power", "False") - client.loop_stop() - setColor(strip, Color(0,0,0)) - GPIO.cleanup() + except KeyboardInterrupt: + client.publish("server-rack-led/power", "False") + client.loop_stop() + setColor(strip, Color(0,0,0)) + GPIO.cleanup() diff --git a/requirements.txt b/requirements.txt index 829f954..e50619e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,5 +3,5 @@ paho_mqtt==1.6.1 Pillow==9.2.0 python-dotenv==0.20.0 requests==2.28.1 -rpi_ws281x==4.3.4 spotipy==2.20.0 +rpi_ws281x==4.3.4