我想问一下是否有人可以在这个mqtt发布脚本中建议我做错了什么。
import paho.mqtt.client as mqtt
from datetime import datetime
import schedule, time, random
import requests, json
client = mqtt.Client()
client.connect("test.mosquitto.org", 1883, 60)
def pub_message():
rand_num = int(random.uniform(0,50))
time_record = datetime.utcnow().strftime("%Y:%m:%d %H:%M:%S:%f")
message = {
"Random Number":rand_num,
"Time": time_record
}
log_print = client.publish("testing", json.dumps(message))
print log_print
schedule.every(1).seconds.do(pub_message)
while True:
schedule.run_pending()
client.loop()
time.sleep(1)
client.disconnect()
出于某种原因,当我在mqtt发布终端
上检查rc时,我一直收到此错误(0,1)
(0,2)
(0,3)
(0,4)
[Errno 32] Broken pipe
(1,5)
(4,6)
...
...
我确实在这里发现了同样的问题:Python Paho client publish failures with at least 1 missed publsh但是我不太明白如何将它与我的剧本联系起来。
感谢您的帮助。