# MQTT - parsing / topic problem

**URL:** <https://community.influxdata.com/t/mqtt-parsing-topic-problem/29061>\
**Category:** Telegraf\
**Tags:** mqtt\
**Created:** [March 14, 2023, 6:01pm UTC](https://community.influxdata.com/t/mqtt-parsing-topic-problem/29061 "2023-03-14T18:01:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Heinz](https://avatars.discourse-cdn.com/v4/letter/h/f04885/32.png) [@Heinz](https://community.influxdata.com/u/Heinz)\
**Post date:** [March 14, 2023, 6:01pm UTC](https://community.influxdata.com/t/mqtt-parsing-topic-problem/29061/1 "2023-03-14T18:01:59Z")

</div>

i am reading data from a microcontroller  
home/room/workshop/temperature1 20.36  
home/room/workshop/humidity 46.36  
home/room/workshop/pressure 996.27  
home/room/workshop/temperature2 16.94

i read in this data with telegraf  
telegraf.conf  
…  
[[inputs.mqtt\_consumer]]  
…  
topics = [  
“home/+/+/+”,  
]  
…  
data\_format = “value”  
data\_type = “float”

and  
[[inputs.mqtt\_consumer.topic\_parsing]]  
topic = “home/+/+/+”  
measurement = “measurement/_/_/_"  
tags = "_/location1/location2/field”  
#fields = “_/_/\_/test”

# ## Value supported is int, float, unit

# # [[inputs.mqtt\_consumer.topic.types]]

# key = float

[[processors.pivot]]  
tag\_key = “field”  
value\_key = “value”

output from the log file

home,location1=room,location2=workshop,topic=home/room/workshop/temperature2 temperature2=16.88 1678815798606918574

my problem is now, the issue of topic=.. since this is also written to the database

A solution is to leave out the topic area [[inputs.mqtt\_consumer.topic\_parsing]], but then telegraf no longer starts.  
2023-03-14T17:53:25Z E! [telegraf] Error running agent: could not initialize input inputs.mqtt\_consumer: config error topic parsing: measurement length does not equal topic length  
the database entry  
Table: keys: [\_start, \_stop, \_field, \_measurement, location1, location2, topic]  
\_start:time \_stop:time \_field:string \_measurement:string location1:string location2:string topic:string \_time:time \_value:float

* * *

2023-03-14T17:27:59.732326779Z 2023-03-14T17:57:59.732326779Z temperature1 home room workshop home/room/workshop/temperature1 2023-03-14T17:31:18.550720212Z 20.19

I don’t know how I don’t get this entry topic= transferred to the database  
Tanks

---

<div class="post-metadata">

**Author:** ![srebhan](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/srebhan/32/8572_2.png) [@srebhan](https://community.influxdata.com/u/srebhan)\
**Post date:** [March 15, 2023, 11:25am UTC](https://community.influxdata.com/t/mqtt-parsing-topic-problem/29061/2 "2023-03-15T11:25:12Z")

</div>

Your topic parsing section is screwed… Every element there has to have the same (topic-length) number of elements e.g.

```toml
[[inputs.mqtt_consumer.topic_parsing]]
  topic = "home/+/+/+"
  measurement = "/measurement/_/_/_"
  tags = "/_/location1/location2/field"

```

---

<div class="post-metadata">

**Author:** ![Heinz](https://avatars.discourse-cdn.com/v4/letter/h/f04885/32.png) [@Heinz](https://community.influxdata.com/u/Heinz)\
**Post date:** [March 15, 2023, 1:31pm UTC](https://community.influxdata.com/t/mqtt-parsing-topic-problem/29061/3 "2023-03-15T13:31:29Z")

</div>

Hi,  
I don’t understand the hint.  
My topic from controller is:  
home/room/workshop/temperature1 23.02  
home/room/workshop/humidity 37.63  
home/room/workshop/pressure 1012.33  
home/room/workshop/temperature2 19.06

I have four entries  
home measurement  
room location1  
workshop location2  
temperature1 field

[[inputs.mqtt\_consumer.topic\_parsing]]  
topic = “home/+/+/+”  
measurement = “measurement/_/_/_"  
tags = "_/location1/location2/field”  
#fields = “_/_/\_/field”

The entry in the database is:  
Table: keys: [\_start, \_stop, \_field, \_measurement, location1, location2, topic]  
\_start:time \_stop:time \_field:string \_measurement:string location1:string location2:string **topic:string** \_time:time \_value:float

* * *

2023-03-15T13:15:07.861256140Z 2023-03-15T13:25:07.861256140Z temperature2 home room workshop **home/room/workshop/temperature2** 2023-03-15T13:24:48.356193692Z 19.31

It doesn’t look bad, but the **topic** entry shouldn’t be there.  
I can’t get rid of this entry with telegraf.

---

<div class="post-metadata">

**Author:** ![Heinz](https://avatars.discourse-cdn.com/v4/letter/h/f04885/32.png) [@Heinz](https://community.influxdata.com/u/Heinz)\
**Post date:** [March 17, 2023, 4:58pm UTC](https://community.influxdata.com/t/mqtt-parsing-topic-problem/29061/4 "2023-03-17T16:58:21Z")

</div>

I tested a little.  
The configuration works fine, but the “topic” entry in the database doesn’t have to be.

[[inputs.mqtt\_consumer.topic\_parsing]]  
topic = “home/+/+/+”  
measurement = “measurement/_/_/_"  
tags = "_/location1/location2/field”  
#fields = “_/_/\_/field”

[[processors.pivot]]  
tag\_key = “field”  
value\_key = “value”

It just takes up space.  
If someone else has an idea, that would be nice, otherwise I’ll write a program.

2023-03-17T16:40:57.273213356Z 2023-03-17T16:50:57.273213356Z temperature2 home room workshop **home/room/workshop/temperature2** 2023-03-17T16:50:32.177384182Z 19.31

Note: the description “MQTT Consumer Telegraf Input Plugin” does not work

> **[MQTT Consumer Telegraf Input Plugin | InfluxData](https://www.influxdata.com/integration/mqtt-telegraf-consumer/)**
>
> InfluxData Integrations: Learn how to consume MQTT messages using Telegraf.

example  
…  
[[inputs.mqtt\_consumer]]  
…  
topics = “/sensors/#”  
[[inputs.mqtt\_consumer.topic\_parsing]]  
measurement = “/measurement/_/_/_/_”  
tags = “/\_/site/version/device\_name/field”  
[[processors.pivot]]  
tag\_key = “field”  
value\_key = “value”

greetings

---

<div class="post-metadata">

**Author:** ![srebhan](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/srebhan/32/8572_2.png) [@srebhan](https://community.influxdata.com/u/srebhan)\
**Post date:** [March 21, 2023, 9:39am UTC](https://community.influxdata.com/t/mqtt-parsing-topic-problem/29061/5 "2023-03-21T09:39:24Z")

</div>

@Heinz the topic takes up exactly **one time** the byte size of the topic text for InfluxDB, but you can get rid of it using [metric modifiers](https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#modifiers) more specifically `tagexclude`.

---

<div class="post-metadata">

**Author:** ![Heinz](https://avatars.discourse-cdn.com/v4/letter/h/f04885/32.png) [@Heinz](https://community.influxdata.com/u/Heinz)\
**Post date:** [April 6, 2023, 4:14pm UTC](https://community.influxdata.com/t/mqtt-parsing-topic-problem/29061/6 "2023-04-06T16:14:56Z")

</div>

Thanks for the info.  
I wasn’t at home and will try it now.

---

<div class="post-metadata">

**Author:** ![Heinz](https://avatars.discourse-cdn.com/v4/letter/h/f04885/32.png) [@Heinz](https://community.influxdata.com/u/Heinz)\
**Post date:** [April 12, 2023, 8:40am UTC](https://community.influxdata.com/t/mqtt-parsing-topic-problem/29061/7 "2023-04-12T08:40:06Z")

</div>

Hello,  
i have some problems with the syntax.  
tagexclude = [“home”] doesn’t work that way  
my solution is:  
[[inputs.mqtt\_consumer]]  
…

## Topics that will be subscribed to.

```
 topics = [
     "home/#"
 ]

```

…  
data\_format = “value”  
data\_type = “float”  
topic\_tag = “”

now the topic is no longer stored in the database.  
\_start:time \_stop:time \_field:string \_measurement:string location1:string location2:string \_time:time \_value:float

* * *

2023-04-12T08:27:32.087611861Z temperature2 home room workshop 2023-04-12T08:28:11.393511938Z 10.69  
2023-04-12T08:27:32.087611861Z temperature2 home room workshop 2023-04-12T08:29:11.396965350Z 10.75

I don’t know if it’s the best solution, but this is how it works

---

<div class="post-metadata">

**Author:** ![srebhan](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/srebhan/32/8572_2.png) [@srebhan](https://community.influxdata.com/u/srebhan)\
**Post date:** [May 16, 2023, 2:30pm UTC](https://community.influxdata.com/t/mqtt-parsing-topic-problem/29061/8 "2023-05-16T14:30:21Z")

</div>

Well it would be `tagexclude = ["topic"]` as the tag is named `topic`…
