通讯猫上云
公共MQTT服务器 有在线客户端 无需注册无须麻烦的调试 通讯猫下载
它的在线版的应用,没有客户端的稳定,所以我这里用客户端演示
1.客户端调成如图所示
2.用代码创建一个发布的主题
这里的simple.py 在这篇帖没睡醒的番茄
from machine import Pin,Timer
from simple import MQTTClient#这个simple.py 在帖子里
import utime,time,network
#连接网络
def WIFI_Connect():
WIFI_LED=Pin(2,Pin.OUT)
wlan=network.WLAN(network.STA_IF)
wlan.active(True)
start_time=utime.time()
if not wlan.isconnected():
print('connecting to network...')
wlan.connect('se','123456789')
while not wlan.isconnected():
WIFI_LED.value(1)
utime.sleep_ms(300)
WIFI_LED.value(0)
utime.sleep_ms(300)
if utime.time()-start_time>15:
print('WIFI Connected Timeout!')
break
if wlan.isconnected():
WIFI_LED.value(1)
print('network information:',wlan.ifconfig())
return True
else:
return False
#******************************************************************************#
#******************************************************************************#
def MQTT_Send(tim):
client.publish(TOPIC,"这里填入数据")
if WIFI_Connect():
SERVER='mq.tongxinmao.com'
PORT=18830
CLIENT_ID='we231'
#这里是发布的主题
TOPIC='/public/love1024/temperature'#这里的love1024可以改动
client=MQTTClient(CLIENT_ID,SERVER,PORT)
client.connect()
tim=Timer(-1)
tim.init(period=1000,mode=Timer.PERIODIC,callback=MQTT_Send)
while True:
pass
3.填入相关订阅主题
4.大功告成
点击启用,订阅主题