Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the simply-static domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/html/wp-includes/functions.php on line 6121
esp32测试mqtt

esp32测试mqtt

import network,time,os
import usocket as socket  # 引用socket模块
from machine import UART
import select,json
from umqtt.simple import MQTTClient
def sub_cb(topic, msg):
        global statemqtt
        print((topic, msg))   #打印收到信息
        if msg == b"on":
            lcdmain.my_text_out("mqtt"+":on",0,32)#单片机显示接收的信息
            statemqtt = 1
        elif msg == b"off":
            lcdmain.my_text_out("mqtt"+":off",0,32)
            statemqtt = 0
        elif msg == b"toggle":
            # LED is inversed, so setting it to current state
            # value will make it toggle
            lcdmain.my_text_out("mqtt"+":tog",0,32)
            statemqtt = 1 - statemqtt
def main():
    c = MQTTClient("umqtt_client", "1.tcp.vip.cpolar.cn",20257)
     #建立一个MQTT客户端
    c.set_callback(sub_cb) #设置回调函数
    c.connect() #建立连接
    c.subscribe(b"mqtt/mypi") #监控ledctl这个通道,接收控制命令

if __name__ == '__main__':
    while True:
      main()