from machine import reset
from random import choice
from rede import Rede
from time import sleep_ms
from json import load
from ntptime import settime
from umqtt.robust import MQTTClient
def debug(arg):
print(arg)
def fofoqueira(t, p):
print(f"{t} -> {p}")
try:
with open('config.json') as arq:
cfg = load(arq)
except:
print ("Deu ruim no arquivo")
topAcao = b'ifrsrg/infoind/alfandega/acao'
topMsg = b'ifrsrg/infoind/alfandega/mensagem'
r = Rede(cfg['rede'], cfg['senha'],
cb=debug)
if r.conectado:
settime()
cliente = MQTTClient(cfg["clientId"],
cfg["broker"])
cliente.set_callback(fofoqueira)
cliente.connect()
cliente.subscribe(topAcao)
cliente.subscribe(topMsg)
else:
print ('Deu ruim...Reiniciando')
sleep_ms(2000)
reset()
filas = ('Livre', 'A', 'B', 'C')
while True:
cliente.check_msg()
#fila =choice(filas)
#print (fila)
#sleep_ms(2000)