buzzard51
buzzard51

Reputation: 1467

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

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)?

Upvotes: 0

Views: 3494

Answers (1)

hardillb
hardillb

Reputation: 59658

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.

Upvotes: 3

Related Questions