树莓派Pico与Node-RED的项目实践
1. 项目预热:按钮与LED的双向通信
在之前的基础上,我们需要对脚本进行一个小改动,主要在 main 函数中,改动后的代码如下:
de main(server, topic, username, passw):
client = MQTTClient( CLIENT_ID,
SERVER,
user=USER,
password=PASSWORD,
keepalive=3600
)
client.set_callback(on_message)
client.connect()
client.subscribe(topic)
print("Connected to %s, subscribed to %s topic" % (server, topic))
try:
while True:
client.wait_msg()
#client.check_msg() # OK TO REMOVE
#sleep(1) # OK TO REMOVE
finally:
client.disconnect()
这里新添
超级会员免费看
订阅专栏 解锁全文
71

被折叠的 条评论
为什么被折叠?



