Wild card or regex in Topic name in MQTT broker

Hi
I am using InfluxDB 2.0.4 and Teleraf 1.22.1 for reading the from MQTT broker.
I am getting multiple device data in my broker. For one device it creates the one topic.
Now no of the topics getting increased now I want to wild card in the topic name so when new devices come I don’t have to add a topic name in Telegraf configuration

suppose I have topic name below

topics = [
“device1”,
“device2”,
“device3”,
“device4”,
“device5”,
]

I want to pass something like topics = [
“device/*”,

]

Something like that so I don’t have to update the config when a new device comes.

@Jay_Clifford Can you help me here please?

Hi @Ravikant_Gautam,
To pull all topics and topic layers you can use the following notation:

topics = [
“#”
]

This would be subscribing to all topics from your MQTT broker. It is not best practice to subscribe to the root layer. Instead, I would like to set up your device topics like so:

device/device1
device/device2
device/device3

Then you can do:

device/#

I highly recommend checking out this awsome blog from HiveMQ: MQTT Topics & Best Practices - MQTT Essentials: Part 5

1 Like