Page 1 of 1

MQTT: Wildcard support

Posted: Tue Nov 19, 2019 10:40 am
by arunvtec
Hello,

Does the ESP-MQTT support wildcard in the MQTT topic? Is there an example on this?

I published the topic -

Code: Select all

/multisensor/device-ID/measurements/temperature/GET
and it works fine.

But with wildcard in the topic

Code: Select all

/multisensor/+/measurements/temperature/GET
, there is no response. 'mqtt_event_handler' is never called.

Thanks,
Arun

Re: MQTT: Wildcard support

Posted: Wed Nov 20, 2019 8:40 am
by ESP-Marius
Which version are you running (IDF and MQTT)?

It worked fine when I tested it right now with the master branch and a local Mosquitto broker.

Subscribing to

Code: Select all

/topic/+/esp32
and then publishing to

Code: Select all

 /topic/qos0/esp32

Code: Select all

 /topic/qos1/esp32

Code: Select all

/topic/qos2/esp32
gives me the expected result. I receive the data from all the published messages.

Could it be that your broker doesn't support wildcards?

Re: MQTT: Wildcard support

Posted: Wed Nov 20, 2019 4:36 pm
by tommeyers
I have a feeling that the OP is publishing a wildcard not subscribing with a wildcard. OP what do you say. Sorry if I am wrong.

Re: MQTT: Wildcard support

Posted: Thu Nov 21, 2019 12:50 am
by ESP-Marius
tommeyers wrote:
Wed Nov 20, 2019 4:36 pm
I have a feeling that the OP is publishing a wildcard not subscribing with a wildcard. OP what do you say. Sorry if I am wrong.
Re-reading the question I see that you are probably right.

OP: if you are trying to publish with a wildcard then the answer is that this is not a part of the MQTT spec.

It says that:
The Topic Name in the PUBLISH Packet MUST NOT contain wildcard characters

Although technically there should be nothing in the esp MQTT client preventing you from publishing to an invalid topic, we don't do any checks on the content of the topic, but a well-behaving broker will probably close the connection.

Re: MQTT: Wildcard support

Posted: Fri Nov 22, 2019 9:21 pm
by tommeyers
One other suggestion:

My MQTT broker (mosquitto) gives me some tools for debug and monitor:

I can start the broker with verbose logging and see all kinds of events

There is a generic subscriber

There is a generic publisher.

Good tools for an MQTT developer.

Tom Meyers