# MQTT input example needed

**URL:** <https://community.influxdata.com/t/mqtt-input-example-needed/9840>\
**Category:** Telegraf\
**Tags:** telegraf\
**Created:** [May 18, 2019, 3:46pm UTC](https://community.influxdata.com/t/mqtt-input-example-needed/9840 "2019-05-18T15:46:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pemca](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@pemca](https://community.influxdata.com/u/pemca)\
**Post date:** [May 18, 2019, 3:46pm UTC](https://community.influxdata.com/t/mqtt-input-example-needed/9840/1 "2019-05-18T15:46:03Z")

</div>

Hi there,  
I’m new to influx and telegraf. I’m trying to send MQTT Publish to Telefgraf inputs.mqtt\_consumer plugin.  
I’m trying to use data\_format = “influx” or data\_format = “json” but i’m getting parsing errors in my log.  
Does anyone have some examples sending MQTT with these formats ?

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![jsimpson](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jsimpson/32/3031_2.png) [@jsimpson](https://community.influxdata.com/u/jsimpson)\
**Post date:** [May 19, 2019, 5:54am UTC](https://community.influxdata.com/t/mqtt-input-example-needed/9840/2 "2019-05-19T05:54:11Z")

</div>

Here are the relevant sections of **telegraf.conf** that I use.

```
[agent]
  # Data collection interval for all inputs
  interval = "1s"
  flush_interval = "1s"

[[inputs.mqtt_consumer]]
  servers = ["localhost:1883"]
  qos = 0
  topics = ["wemos1/thermo/temp"]
  data_format = "value"
  data_type = "float"
  max_undelivered_messages = 1000
```

---

<div class="post-metadata">

**Author:** ![rawkode](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/rawkode/32/5161_2.png) [@rawkode](https://community.influxdata.com/u/rawkode)\
**Post date:** [May 19, 2019, 7:03am UTC](https://community.influxdata.com/t/mqtt-input-example-needed/9840/3 "2019-05-19T07:03:35Z")

</div>

> **[influxdb-examples/telegraf/mqtt at master · rawkode/influxdb-examples](https://github.com/rawkode/influxdb-examples/tree/master/telegraf/mqtt)**
>
> master/telegraf/mqtt

---

<div class="post-metadata">

**Author:** ![pemca](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@pemca](https://community.influxdata.com/u/pemca)\
**Post date:** [May 19, 2019, 7:40am UTC](https://community.influxdata.com/t/mqtt-input-example-needed/9840/4 "2019-05-19T07:40:33Z")

</div>

Hi,  
Thank you for answer.  
I already tried the combination sending a single value with MQTT using the data\_format and data\_type parameters, but my goal is to send more measurements values at the same time. For example in json format.  
thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![pemca](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@pemca](https://community.influxdata.com/u/pemca)\
**Post date:** [May 19, 2019, 8:03am UTC](https://community.influxdata.com/t/mqtt-input-example-needed/9840/5 "2019-05-19T08:03:46Z")

</div>

Perfect, now i got it 😄😄 - Thank You.

```
# telegraf.conf
data_format = "json"       
json_string_fields = ["txt_field_1"]              

# mqtt sent without text field 
mosquitto_pub -h localhost -m '{"temperature":25,"airpressure":1010,"humidity":77}' -t 'telegraf/test' 

 # mqtt sent with text field
 mosquitto_pub -h localhost -m '{"temperature":26,"airpressure":1011,"humidity":78,"txt_field_1":"Testing"}' -t 'telegraf/test' 

```

> select \* from mqtt\_consumer  
> name: mqtt\_consumer  
> time airpressure host humidity temperature topic txt\_field\_1

* * *

1558252574294674524 1010 nuc1 77 25 telegraf/test  
1558252770297595536 1010 nuc1 77 25 telegraf/test  
1558252888092790790 1011 nuc1 78 26 telegraf/test Testing

>

---

<div class="post-metadata">

**Author:** ![pemca](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@pemca](https://community.influxdata.com/u/pemca)\
**Post date:** [May 19, 2019, 10:45am UTC](https://community.influxdata.com/t/mqtt-input-example-needed/9840/6 "2019-05-19T10:45:27Z")

</div>

Here i send a mesurement with data\_format = “influx” via mqtt - you are not bound to the mqtt\_consumer name.

mosquitto\_pub -h localhost -m ‘peter\_test,greenhouse=garden temperature=25,airpressure=1010’ -t ‘telegraf/test’

> select \* from peter\_test  
> name: peter\_test  
> time airpressure greenhouse host temperature topic

* * *

1558262625068976346 1010 garden nuc1 25 telegraf/test
