Get a list of connected client IDs from MQTT client

Andreas Linden picture Andreas Linden · Mar 19, 2012 · Viewed 38.3k times · Source

As a mqtt client connected to mosquitto is it possible to retrieve a list of client IDs who are also connected to the broker?

Answer

horacex picture horacex · Mar 12, 2013

one way to implement this is let the client publish a message with topic "status/client-id" and payload "1" every time when it connects the broker, and with payload "0" when it disconnects.

Then on the server(broker) side, setup another client subscribe to the topic "status/#", when it gets any message like this, store the client-id and payload(connected or not) into database.

then you can read the database to know exactly which client is online or offline.