-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
I try umqtt.simple to connect my raspberry with MQTT. But I found it's offline after 10+ seconds, and then I receive the error code in webrepl. Has anyone had the same problem?
The main snippets is:
def main(server=MQTT_SERVER_EMQX):
# 连接WiFi
connect_wifi()
c = MQTTClient(generate_client_id(), server, keepalive=10)
c.set_last_will(topic=b"esp8266/will", msg='offline', retain=True)
c.set_callback(lambda topic, msg: sub_cb(topic, msg, c))
# c.set_callback(sub_cb)
res = c.connect(clean_session=False)
if (res != 128):
print('当前连接的MQTT服务器是:' + server)
c.publish(b'esp8266/will', msg='online', retain=True)
c.publish(b'led/status', msg=getLedStatus(), retain=True)
c.subscribe(b'led/ctl')
while True:
if True:
# Blocking wait for message
c.wait_msg()
else:
# Non-blocking wait for message
c.check_msg()
# Then need to sleep to avoid 100% CPU usage (in a real
# app other useful actions would be performed instead)
time.sleep(1)
c.disconnect()
if __name__ == "__main__":
main()Metadata
Metadata
Assignees
Labels
No labels
