1
votes

Let's say I have two clients with client id's device1 and device2. Before device1 sends a publish message to broker it needs to check if device2 is still connected to the broker. How can I check the connectivity of device2 from client device1.?

I am using mosquitto broker and paho client

1

1 Answers

2
votes

The short answer is you can not do this at the MQTT protocol level.

The best you can do is use a status topic. When a client connects it publishes a retained message with payload true to a topic like status/[client-id]. Just before it disconnects is publishes a message with the payload false to the same topic. To sure it's marked as away if it crashes then you need to set a Last Will and Testament message to publish false when the broker notices the client is no longer responding to pings.