Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mosquitto-dev] monitor client ID

We do it this way:

- onConnect a client sets a lastWill for the topic `APP_ID/CLIENT_ID/status` to `-1`
- when the client connected successfully, it sets `APP_ID/CLIENT_ID/status` to `1`
- if the client disconnected gracefully, it sets `APP_ID/CLIENT_ID/status` to `0`

All publishes have to be retain=true. We use qos = 0.

This way we know, if a client disconnected gracefully, or failed with a last Will.

Then on the server side, we have another small program acting as a watchdog, which subscribes to the wildcard `APP_ID/#/status`.

This means it gets all status information about the clients. This way a client only has to unsubscribe from `status` gracefully or via lastWill, and our watchdog will take care of cleaning up all used (retained) topics of a client (everything for `APP_ID/CLIENT_ID/#`)

So cleaning up a CLIENT_ID involves publishing a retained empty payload (empty byte array) to the retained `APP_ID/CLIENT_ID/status` . You can only delete topics in mosquitto by publishing empty payload to it.

This way, all new subscribers, which will subscribe after this CLIENT_ID deletion, (i.e. via `APP_ID/#/status`) will not know that this client existed, because it is gone.

All subscribers, which were subscribed during deletion of the CLIENT_ID will still get a message with an empty payload (which they should ignore).


Using the watchdog, we can control, if we want to delete the client immediately, or wait a little bit, if the lastWill was sent. Maybe the client is just flapping and will come back soon, so all other devices should know the client is currently not connected, but it was here a minute ago.


Greetings,

Jan


On 17 Jul 2015, at 10:09, Maciej Troszyński <mactro@xxxxxxxxx> wrote:

Hi,

regarding last will, I do it like this: on connection, I have a client publishing a message "online" in topic clientID/status. I set last will to also publish in that topic, but the message is then "offline". Both messages must have retain set to true. A "will" message will be published by the broker in the specified topic, only after it doesn't receive keep alive messages from client.



pozdrawiam
Maciej Troszyński

2015-07-17 9:57 GMT+02:00 Vishalkumar Maroorkar <vishalm101@xxxxxxxxx>:
Hi,

Does anyone tell me how to set a "will" to know unexpected disconnection to mqtt broker.

And also please provide me some examples on below options for mosquitto_pub client.

 --will-payload : payload for the client Will, which is sent by the broker in case of
                  unexpected disconnection. If not given and will-topic is set, a zero
                  length message will be sent.
 --will-qos : QoS level for the client Will.
 --will-retain : if given, make the client Will retained.
 --will-topic : the topic on which to publish the client Will.

Thanks,
Vishal


On Thu, Jul 16, 2015 at 11:57 AM, Nicholas O'Leary <nick.oleary@xxxxxxxxx> wrote:

Here's a more complete description of how you could do it...

http://stackoverflow.com/questions/23440043/implementing-xmpp-presence-feature-in-mqtt/23450804#23450804

Nick


On Thu, 16 Jul 2015 07:20 aventari <aventari@xxxxxxxxx> wrote:

Also you should set a will so that on unexpected disconnect, the 'will' will automatically set the presence to offline.

On Jul 15, 2015 10:37 PM, "Shirish Kumar" <shirish.kumar@xxxxxxxxx> wrote:
>
> I do think it is supported currently.  I have all my clients publish their presence on "presence" topics.  This also gives my a lot more flexibility in managing presence (other than just online/offline).
>
> On Wed, Jul 15, 2015 at 2:27 AM, Vishalkumar Maroorkar <vishalm101@xxxxxxxxx> wrote:
>>
>> Hi,
>>
>> Is there is any way to monitor which clients are connected or disconnected to mosquitto broker.
>> I need to check the presence of the client in MQTT, where as this feature is available in XMPP protocol.
>>
>> Thanks,
>> Vishal
>>
>> _______________________________________________
>> mosquitto-dev mailing list
>> mosquitto-dev@xxxxxxxxxxx
>> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
>> https://dev.eclipse.org/mailman/listinfo/mosquitto-dev
>
>
>
> _______________________________________________
> mosquitto-dev mailing list
> mosquitto-dev@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
> https://dev.eclipse.org/mailman/listinfo/mosquitto-dev

_______________________________________________
mosquitto-dev mailing list
mosquitto-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/mosquitto-dev

_______________________________________________
mosquitto-dev mailing list
mosquitto-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/mosquitto-dev


_______________________________________________
mosquitto-dev mailing list
mosquitto-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/mosquitto-dev

_______________________________________________
mosquitto-dev mailing list
mosquitto-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/mosquitto-dev


Back to the top