从Paho MQTT发送到云时,一些数据丢失

时间:2019-07-10 05:56:50

标签: python mqtt paho

我正在尝试将大约500个标签的数据(每秒更改数据)从Paho MQTT发送到Cloud。最初,所有数据都会被接收,但是一段时间后,它将开始丢失样本。

  • 试图更改“保持活动时间”
  • 选中了Wireshark以监控流量。

我的代码的一部分

def queue_consumer(queue):
    global TestCount

    global responseList
    while True:
        TestCount=0
        for items in range(0, queue.qsize()):
            responseList.append(queue.get_nowait())
            queue.task_done()
        item1="topicName"
        if item1 is None:
            print("BREAKKK")
            break
        else:
            mqttmessage1 = json.dumps(responseList)
            objClient = ConnectionClient()
            objClient.client.publish("topicName", mqttmessage1 , qos=1)
            responseList=[]
            del objClient
        time.sleep(1)           # time after which the next items in queue
                                # would be processed for publishing

我希望所有数据都将带有时间戳发布到云中。

1 个答案:

答案 0 :(得分:1)

不清楚您的ConnectionClient()是否在主循环中每次都打开和关闭连接。但是,好像您每次都关闭连接(通过del objClient)。如果是这样,建议您在启动时创建一个mqtt.Client并连接到该服务。然后,每次运行主循环时,都会发送消息,并且在程序退出之前不要关闭连接。

您还可以检查服务提供商是否未应用某些限制。除非您为服务付费,否则每秒可能有500个主题。