from machine import Pin
from rede import Rede
from umqtt.simple import MQTTClient
topico = b'ifrs/rg/auto/1e1/213/m'
topcom = b'ifrs/rg/auto/1e1/213/lampada'
rele = Pin(23, Pin.OUT, value=0)
def fofoqueiro(t, p):
if t == topcom:
msg = p.decode()
if msg == 'on':
rele.on()
else:
rele.off()
else:
print (t, p)
r = Rede('Wokwi-GUEST', '', conecta=False)
r.conectar(tentativas=40, intervalo=500)
adamastor = MQTTClient('crrinfo1602','broker.hivemq.com')
adamastor.set_callback(fofoqueiro)
adamastor.connect()
adamastor.subscribe(topcom)
while True:
adamastor.check_msg()