Get a list of connected client IDs from MQTT client


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

Best Solution

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.

Related Question