mosquitto_sub: how to find out to which topic a messages belong to

46 views
Skip to first unread message

Grossmann200

unread,
Apr 15, 2017, 1:12:27 PM4/15/17
to MQTT
Hi,
I am using several mqtt-topics to control my home-network.
In order to get an overview of all messages which have been send, I can use the #-wildcard: mosquitto_sub -h <IP> -p <port> "home/#".
But the output will be the messages only, without the full topic behind it.

E.g. I have two lamps, each controlled by it's own topic:
Lamp living-room: /home/lamp/living-room
Lamp kitchen: /home/lamp/kitchen

If the lamps are now turned on/off, mosquitto_sub -h <IP> -p <port> "home/lamp/#" will only tell me
on
on
off
... and I will not see, which lamp was turned on/off

Frank Pagliughi

unread,
Apr 15, 2017, 1:43:26 PM4/15/17
to mq...@googlegroups.com
Use the "-v" switch for mosquitto sub. It will print the topic on which the message arrived and then the payload - separated by a space, I believe.
You will see something like:
$ mosquitto_sub -v -t "home/#"
home/lamp/livingroom on
home/lamp/kitchen on
home/lamp/livingroom off

From the mosquitto_sub man page:
       -v, --verbose
           Print received messages verbosely. With this argument, messages will be printed as "topic
           payload". When this argument is not given, the messages are printed as "payload".

Frank
--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
To post to this group, send email to mq...@googlegroups.com.
Visit this group at https://groups.google.com/group/mqtt.
For more options, visit https://groups.google.com/d/optout.

Grossmann200

unread,
Apr 15, 2017, 2:07:34 PM4/15/17
to MQTT
Frank, thanks a lot! That is exactly what I was looking for.
(... I am so stupid, indeed I also checked the manpages ... but somehow overlooked verbose)

:-)
Reply all
Reply to author
Forward
0 new messages