MQTT input example needed

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

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

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

Perfect, now i got it :smile::smile: - 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

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