Basic JSON>MQTT>Telegraf issues

I’m just getting started w/ influx and telegraf and I’m running into issues with collecting and tagging data. I’m looking to field air quality monitors which will send readings and device info via MQTT. I’ve successfully setup an [[inputs.mqtt_consumer]] using data_format="value" to pull the readings from MQTT into influx. However, I want more control over the tagging and so I’m now attempting to use JSON-formatted data without much success. The telgraf service runs without error, but no data is submitted to the database with the settings shown below. Reverting back to data_fromat="value" with readings split out into separate topics works as expected.

I’m probably just doing something dumb here but I’ve yet to figure out the magic configuration to make all this work. If anyone could offer some guidance I sure would appreciate it.

Here’s the data being published to MQTT:
topic: graqmpublish/graqm005
message: {"device":"graqm005","geohash":"dpe5eqr5","transport":"WiFi","PM1":"2","PM25":"3","PM10":"4","O3":"152","pressure":"29.47","humidity":"44.91","temperature":"22.21"}

Here’s the input plugin configuration from telegraf.conf:

# Read metrics from MQTT topic(s)
[[inputs.mqtt_consumer]]
  name_override = "graqm_airquality"
  servers = ["localhost:1883"]
  qos = 0
  connection_timeout = 30
  topics = [
    "graqpublish/#",
  ]
  persistent_session = true
  client_id = "graqmdata-telegraf"

  data_format = "json"
  tag_keys = [
    "device",
    "geohash",
    "transport"
  ]

Output from systemctl status telegraf

Oct 01 11:57:35 graqmdata telegraf[12355]: 2017-10-01T15:57:35Z I! Starting Telegraf v1.4.1
Oct 01 11:57:35 graqmdata telegraf[12355]: 2017-10-01T15:57:35Z I! Loaded outputs: influxdb
Oct 01 11:57:35 graqmdata telegraf[12355]: 2017-10-01T15:57:35Z I! Loaded inputs: inputs.mqtt_consumer
Oct 01 11:57:35 graqmdata telegraf[12355]: 2017-10-01T15:57:35Z I! Tags enabled: host=graqmdata
Oct 01 11:57:35 graqmdata telegraf[12355]: 2017-10-01T15:57:35Z I! Agent Config: Interval:10s, Quiet:false, Hostname:"graqmdata", Flush Interval:10s
Oct 01 11:57:35 graqmdata telegraf[12355]: 2017-10-01T15:57:35Z I! MQTT Client Connected

Shortly after posting this I discovered a dumb typo in my mqtt subscription string (ugh). With that typo corrected Telegraf is finally picking up the messages, but puking on the contents:

Oct 1 12:10:52 graqmdata telegraf[13119]: 2017-10-01T16:10:52Z E! Error in plugin [inputs.mqtt_consumer]: E! MQTT Parse Error Oct 1 12:10:52 graqmdata telegraf[13119]: message: {"device":"graqm005","geohash":"dpe5eqr5","transport":"WiFi","PM1":"2","PM25":"2","PM10":"2","O3":"150","pressure":"29.46","humidity":"44.70","temperature":"22.22"}

Rubber ducky debug works again :smiley:

Issue was simple - I am a JSON dummy and had quotes on my floats and floats don’t need quotes. With the simple expedience of removing the quotes everything works as expected.

I’ll leave this post here as a testament to my foolishness and as a counter-example to others. Thanks!

1 Like