ESP32, MQTT, and LED temperature trigger

ivanhosa13
Posts: 1
Joined: Fri Apr 17, 2020 9:35 pm

ESP32, MQTT, and LED temperature trigger

Postby ivanhosa13 » 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:

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()

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: ESP32, MQTT, and LED temperature trigger

Postby chegewara » Mon Apr 20, 2020 6:51 am

Micropython experts please.

Who is online

Users browsing this forum: No registered users and 67 guests