import network
import time
from umqtt.simple import MQTTClient
from machine import Pin
from machine import ADC
#Conectamos con la red WIFI
print("Conectando al wifi", end="")
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('Wokwi-GUEST', '')
while not sta_if.isconnected():
print(".", end="")
time.sleep(0.1)
print(" Conectado!")
print("Conectando al server MQTT", end="")
client = MQTTClient(client_id=b"100",
server=b"50965d6f0e6f4ff5bc574315cd61b405.s1.eu.hivemq.cloud",
port=0,
user=b"Prueba",
password=b"Prueba1234",
ssl=True,
ssl_params={ "server_hostname": "50965d6f0e6f4ff5bc574315cd61b405.s1.eu.hivemq.cloud"} )
client.connect()
print(" Conectado!")
sensor = ADC(0)
ultimo_valor=0
while True:
valor=sensor.read()
if ultimo_valor != valor:
ultimo_valor=valor
mensaje="slider,id=100 value="+str(valor)
print("Cambio de valor, enviando: "+mensaje)
client.publish("Topico", mensaje)
time.sleep(1)
Loading
esp32-c3-devkitm-1
esp32-c3-devkitm-1