# MQTT plugin not writing data to influxdb

**URL:** https://community.influxdata.com/t/mqtt-plugin-not-writing-data-to-influxdb/25632
**Category:** Telegraf
**Tags:** mqtt
**Created:** [July 3, 2022, 8:27pm UTC](https://community.influxdata.com/t/mqtt-plugin-not-writing-data-to-influxdb/25632 "2022-07-03T20:27:37Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![jmo](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jmo/32/10473_2.png) [@jmo](https://community.influxdata.com/u/jmo)
#### Post date: [July 3, 2022, 8:27pm UTC](https://community.influxdata.com/t/mqtt-plugin-not-writing-data-to-influxdb/25632/1 "2022-07-03T20:27:38Z")

</div>

Hello all! I’m really new to all this so I imagine I may have a few errors here. I am using influxdb v1.8 and telegraf v1.23.

I have two instances of the MQTT plugin, first one for an `int` data type and the second for `json` data type. The first instance works fine and writes to my database into the table named mqtt\_consumer.

I’m trying to get the second instance to write to a new table called `mqtt_sensors` for the values received from the MQTT broker. Any help is very much appreciated. Below is my config for the MQTT inputs.

```auto
[[inputs.mqtt_consumer]]
   servers = ["tcp://192.168.50.36:1883"]
   topics = [
     "perfscore"
   ]
   topic_tag = "topic"
   qos = 0
   connection_timeout = "30s"
   max_undelivered_messages = 1000
   persistent_session = false
   data_format = "value"
   data_type = "integer"

[[inputs.mqtt_consumer]]
   name_override = "mqtt_sensors"
   servers = ["tcp://192.168.50.36:1887"]
   topics = [
     "meraki/v1/mt/+/ble/+/temperature",
     "meraki/v1/mt/+/ble/+/humidity",
     "meraki/v1/mt/+/ble/+/batteryPercentage"
   ]

   topic_tag = "sensors"
   qos = 0
   connection_timeout = "30s"
   max_undelivered_messages = 1000
   persistent_session = false
   data_format = "json_v2"
   [[inputs.mqtt_consumer.topic_parsing]]
     topic = "+/+/+/+/+/+/temperature"
     tags = "_/_/_/network/_/device/_"
	 [inputs.mqtt_consumer.json_v2]
	   [inputs.mqtt_consumer.json_v2.fields]
	     fahrenheit = "float"
		 celcius = "float"
   [[inputs.mqtt_consumer.topic_parsing]]
     topic = "+/+/+/+/+/+/humidity"
     tags = "_/_/_/network/_/device/_"
	 [inputs.mqtt_consumer.json_v2]
	   [inputs.mqtt_consumer.json_v2.fields]
	   humidity = "float"

```

The payload for the three topics in the second instance are as follows:  
Topic: temperature  
Payload: {“ts”:“2021-08-12T17:44:46Z”, “fahrenheit”:72.6, “celsius”:22.6}  
Topic: humidity  
Payload: {“ts”:“2021-08-12T17:44:46Z”, “humidity”:62}  
Topic: batteryPercentage  
Payload: {“ts”:“2021-08-12T21:30:48Z”, “battery percentage”:100}

---

<div class="post-metadata">

### Author: ![phill](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@phill](https://community.influxdata.com/u/phill)
#### Post date: [July 3, 2022, 9:25pm UTC](https://community.influxdata.com/t/mqtt-plugin-not-writing-data-to-influxdb/25632/2 "2022-07-03T21:25:36Z")

</div>

Hi @jmo - I’m fairly new as well, but it may be that two occurrences of the `[[inputs.mqtt_consumer]]` block in the same telegraf.conf file is problematic. It sounds like the first is working and the second is being ignored (i.e., no activity or output). Clearly you understand the plug-in’s usage well enough because the first one is working.

I’d suggest setting `debug = true` in the agent section and temporarily removing the first one in order to focus on the second. Once you get that working, put the first one back in but **after** the JSON version and see what happens.

---

<div class="post-metadata">

### Author: ![jmo](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jmo/32/10473_2.png) [@jmo](https://community.influxdata.com/u/jmo)
#### Post date: [July 4, 2022, 12:45am UTC](https://community.influxdata.com/t/mqtt-plugin-not-writing-data-to-influxdb/25632/3 "2022-07-04T00:45:12Z")

</div>

Thanks @phill for the recommendation. I have enabled debug and commented out the first `[[inputs.mqtt_consumer]]` instance. From the logs I see it connecting to the broker for the second instance but thereafter I only see writes to the database. I also am using SNMP so I assume those writes are for that particular data. No change in the database schema to reflect any new table.

Log output:

```auto
2022-07-04T00:35:36Z D! [agent] Connecting outputs
2022-07-04T00:35:36Z D! [agent] Attempting connection to [outputs.influxdb]
2022-07-04T00:35:36Z D! [agent] Successfully connected to outputs.influxdb
2022-07-04T00:35:36Z D! [agent] Starting service inputs
2022-07-04T00:35:36Z I! [inputs.mqtt_consumer] Connected [tcp://192.168.50.36:1887]
2022-07-04T00:35:46Z D! [outputs.influxdb] Wrote batch of 60 metrics in 5.281927ms
2022-07-04T00:35:46Z D! [outputs.influxdb] Buffer fullness: 0 / 10000 metrics
2022-07-04T00:35:56Z D! [outputs.influxdb] Wrote batch of 77 metrics in 5.776582ms
2022-07-04T00:35:56Z D! [outputs.influxdb] Buffer fullness: 0 / 10000 metrics

```

Database output:

```auto
> show measurements
name: measurements
name
----
cpu
disk
diskio
kernel
mem
mqtt_consumer
mqtt_perfscore
processes
snmp
swap
system

```

---

<div class="post-metadata">

### Author: ![Jay\_Clifford](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jay_clifford/32/8287_2.png) [@Jay\_Clifford](https://community.influxdata.com/u/Jay_Clifford)
#### Post date: [July 4, 2022, 10:06am UTC](https://community.influxdata.com/t/mqtt-plugin-not-writing-data-to-influxdb/25632/4 "2022-07-04T10:06:21Z")

</div>

Hi @jmo @phill,  
So it is more than acceptable to have two or even more of the same plugin type within your config. In some cases we even encourage it to spread the load with large datasets. Can I propose a config reshuffle:

```auto
[[inputs.mqtt_consumer]]
   servers = ["tcp://192.168.50.36:1883"]
   topics = [
     "perfscore"
   ]
   topic_tag = "topic"
   qos = 0
   connection_timeout = "30s"
   max_undelivered_messages = 1000
   persistent_session = false
   data_format = "value"
   data_type = "integer"

[[inputs.mqtt_consumer]]
   name_override = "mqtt_sensors"
   servers = ["tcp://192.168.50.36:1887"]
   topics = [
     "meraki/v1/mt/+/ble/+/temperature",
     "meraki/v1/mt/+/ble/+/humidity",
     "meraki/v1/mt/+/ble/+/batteryPercentage"
   ]

   topic_tag = "sensors"
   qos = 0
   connection_timeout = "30s"
   max_undelivered_messages = 1000
   persistent_session = false
   data_format = "json_v2"

   [[inputs.mqtt_consumer.topic_parsing]]
     topic = "+/+/+/+/+/+/+"
     tags = "_/_/_/network/_/device/_"

 [[inputs.mqtt_consumer.json_v2]]
 [[inputs.mqtt_consumer.json_v2.object]]
path = "@this"

```

---

<div class="post-metadata">

### Author: ![jmo](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jmo/32/10473_2.png) [@jmo](https://community.influxdata.com/u/jmo)
#### Post date: [July 4, 2022, 5:21pm UTC](https://community.influxdata.com/t/mqtt-plugin-not-writing-data-to-influxdb/25632/5 "2022-07-04T17:21:04Z")

</div>

Thank you @Jay_Clifford! I now see data in Influx with your proposed change. Much appreciate the help from the community here.

---

<div class="post-metadata">

### Author: ![Jay\_Clifford](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jay_clifford/32/8287_2.png) [@Jay\_Clifford](https://community.influxdata.com/u/Jay_Clifford)
#### Post date: [July 5, 2022, 8:30am UTC](https://community.influxdata.com/t/mqtt-plugin-not-writing-data-to-influxdb/25632/6 "2022-07-05T08:30:31Z")

</div>

No worries @jmo ! Happy to help anytime 🙂
