Is there a way to check if a client has initially connected. I want to send a message to a topic if a client has "logged in".
Asked
Active
Viewed 48 times
1 Answers
3
There is no client presence detection built into MQTT at the protocol level.
But there is nothing to stop you building it yourself.
Have the client publish a retained message on a known topic e.g. presence/<client-id> and then set up a Last Will and Testament to either clear the message or publish a different value (e.g. online vs offline). You will also need to explicitly clear it if the client shuts down cleanly.
Other clients can subscribe to presense/+ in order to keep track of which clients are online.
hardillb
- 12,813
- 1
- 21
- 34