Query mosquitto MQTT broker on one specific topic for what ever is retained there, then disconnect

127 views
Skip to first unread message

K Smith

unread,
Jul 9, 2019, 6:25:04 AM7/9/19
to MQTT
Does anyone know how to query the mosquitto MQTT broker for one specific topic for what ever is retained there, then disconnect?
I have had a fairly extensive look through mosquito_sub man file and couldn't see anything, unless I missed it.

Andy Stanford-Clark

unread,
Jul 9, 2019, 6:32:27 AM7/9/19
to 'Simon Walters' via MQTT
assuming you want to use mosquito_sub and not write a program to do it, then.
-C 1
… wait for one message to be received.
This only works if there’s definitely a retained topic there… otherwise it will wait until the next message comes along (which might be never ;))

If you are happy to write some code, you can add a watchdog timer to make it return “nothing” if the retained message doesn’t come through within a couple of seconds.

Andy

On 9 Jul 2019, at 11:25, K Smith <kes...@gmail.com> wrote:


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.
To view this discussion on the web visit https://groups.google.com/d/msgid/mqtt/98467eb5-b432-492e-830f-42a2e288adff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

K Smith

unread,
Jul 9, 2019, 7:55:18 AM7/9/19
to MQTT

Thank you.

I was querying the retained status of a sonoff with Tasmota flashed onto it (that is very sucessfully switching my printer in the living room on and off as needed). 

For no particular reason I though retained messages were set. They were'nt.

I had been going in circles and had tried -C 1 a number of times and thought it should work. 
It does work now that the topic is set to be retained by the broker
    mosquitto_sub -C 1 -h 192.168.1.120 -t home/livingroom/printer

Setting the topic to be retained by the broker on the Tasmota can be done two ways
- in the console type PowerRetain on, or 
 - enter into the web browser
http://192.168.1.245/cm?cmnd=PowerRetain%20on
where 192.168.1.245 is the IP address of the tasmota switch.




On Tuesday, 9 July 2019 11:32:27 UTC+1, andysc wrote:
assuming you want to use mosquito_sub and not write a program to do it, then.
-C 1
… wait for one message to be received.
This only works if there’s definitely a retained topic there… otherwise it will wait until the next message comes along (which might be never ;))

If you are happy to write some code, you can add a watchdog timer to make it return “nothing” if the retained message doesn’t come through within a couple of seconds.

Andy

On 9 Jul 2019, at 11:25, K Smith <kes...@gmail.com> wrote:


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 mq...@googlegroups.com.

Andy Stanford-Clark

unread,
Nov 8, 2022, 3:43:01 AM11/8/22
to 'Simon Walters' via MQTT
That’s weird - a message from 2019 popped into my inbox!

On 8 Nov 2022, at 08:41, KC help <he...@kettlecompanion.com> wrote:

Great tips - thank you :)

--
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.
Reply all
Reply to author
Forward
0 new messages