ESP32, MQTT, and LED temperature trigger
Posted: Fri Apr 17, 2020 9:48 pm
Hello everyone,
i am trying to use a WS2812B LED strip to work with a code that i have for the esp32. the code is a MQTT subscription code that subscribe to a temperature topic that i run on another ESP32. in this code if the temperature get higher than a certain degree, it will print a danger message. but what i need help with is to connect the led strip to esp32 and make the led turn on whenever the temperature get higher than a certain degree. also is it possible to run the LED strip using just the esp32?
here is the code:
i am trying to use a WS2812B LED strip to work with a code that i have for the esp32. the code is a MQTT subscription code that subscribe to a temperature topic that i run on another ESP32. in this code if the temperature get higher than a certain degree, it will print a danger message. but what i need help with is to connect the led strip to esp32 and make the led turn on whenever the temperature get higher than a certain degree. also is it possible to run the LED strip using just the esp32?
here is the code:
Code: Select all
import time
from umqtt.robust import MQTTClient
SERVER = '172.20.10.11' # MQTT Server Address (Change to the IP address of your Pi)
CLIENT_ID = 'ESP32_2'
TOPIC = b'temp_humidity'
def sub_cb(topic, msg):
print((topic, msg))
if float(msg.decode().split(",")[0])>30:
print("danger")
c = MQTTClient(CLIENT_ID, SERVER)
c.DEBUG = True
c.set_callback(sub_cb)
if not c.connect(clean_session=False):
print("New session being set up")
c.subscribe(TOPIC)
while 1:
c.wait_msg()
c.disconnect()