How do you send a PINGREQ in python for paho mqtt?

空扰寡人 提交于 2019-12-13 03:25:04

问题


I connect to my mosquitto broker with

client.connect("192.168.1.1",1883,60)

to establish the connection, and the server expects traffic every 60 seconds. The paho documentation refers to a PINGREQ/PINGACK message which I would like to use to keep the connection alive.

Can't find any examples of this - how to do this in python (2.7)?


回答1:


The short answer is you don't

The pings are handled by the MQTT Client network loop. You need to start this after connecting. There are 3 ways to run the loop:

  1. client.start_loop() This starts the network loop on a background thread
  2. client.loop_forever() This starts the network loop on the current thread and will block forever.
  3. client.loop() this executes one cycle of the network loop and must be called as part of your own loop.


来源:https://stackoverflow.com/questions/48613123/how-do-you-send-a-pingreq-in-python-for-paho-mqtt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!