parent
b64d7789b8
commit
4d2e67a29a
91
main.py
91
main.py
|
@ -156,48 +156,59 @@ if __name__ == '__main__':
|
|||
elif payload == "Random Color per LED":
|
||||
mode = 4
|
||||
|
||||
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
|
||||
strip.begin()
|
||||
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()
|
||||
|
||||
mode = 0
|
||||
power = "True"
|
||||
global r
|
||||
r = 255
|
||||
global g
|
||||
g = 255
|
||||
global b
|
||||
b = 255
|
||||
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
|
||||
strip.begin()
|
||||
|
||||
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
|
||||
mode = 0
|
||||
power = "True"
|
||||
global r
|
||||
r = 255
|
||||
global g
|
||||
g = 255
|
||||
global b
|
||||
b = 255
|
||||
|
||||
client.publish("server-rack-led/power", "True")
|
||||
client.publish("server-rack-led/mode", "Rainbow")
|
||||
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
|
||||
|
||||
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))
|
||||
client.publish("server-rack-led/power", "True")
|
||||
client.publish("server-rack-led/mode", "Rainbow")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
client.publish("server-rack-led/power", "False")
|
||||
client.loop_stop()
|
||||
setColor(strip, Color(0,0,0))
|
||||
GPIO.cleanup()
|
||||
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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue