UIFlow Guide
Connects to MQTT server for subscription and topic publishing.
from m5stack import *
from m5ui import *
from uiflow import *
from m5mqtt import M5mqtt
import time
setScreenColor(0x222222)
def fun__dev_sub_(topic_data):
# global params
print('topic: /dev/sub received:')
print(topic_data)
pass
m5mqtt = M5mqtt('id_123456', 'broker.emqx.io', 1883, 'user_123456', 'pwd_123456', 20)
m5mqtt.subscribe(str('/dev/sub'), fun__dev_sub_)
print('mqtt connecting....')
m5mqtt.set_last_will(str('/dev/last_will'),str('device disconnect'))
m5mqtt.start()
print('mqtt connected')
while True:
m5mqtt.publish(str('/dev/pub'), str('Hello'), 0)
wait(10)
wait_ms(2)
m5mqtt = M5mqtt('id_123456', 'broker.emqx.io', 1883, 'user_123456', 'pwd_123456', 20)
m5mqtt = M5mqtt('id_123456', 'broker.emqx.io', 1883, 'user_123456', 'pwd_123456', 20, ssl = True, ssl_params = {'key': "/flash/res/certificate.pem.crt", 'cert': "/flash/res/private.pem.key"})
+
sign.m5mqtt.set_last_will(str('/dev/last_will'),str('device disconnect'))
m5mqtt.start()
m5mqtt.publish(str('/dev/pub'), str('Hello'), 0)
def fun__dev_sub_(topic_data):
print(topic_data)
pass
m5mqtt.subscribe(str('/dev/sub'), fun__dev_sub_)