Beginner question: MQTT > Transform > Influx with TICK stack?

Hi there,

Quick question - I have an existing system that collects sensor data, it looks like this:
Sensor > MQTT > Processor > Postgres
I now want to hook in the TICK stack by connecting it to the MQTT as a subscriber in parallel.

The problem is that the sensor data is basically a json map with various sensor values.
Those are persisted in Postgres as JSONB fields.
This means that a single entry contains multiple sensor readings, e.g. {temp: 50.0, humidity: 30,…} etc
The content varies per sensor.

This probably means - if I’m correct - that I need to transform/dissect the message content before persisting to Influx - how would I do that?

Thanks a lot,

Hi @Christoph,

It’s actually a lot easier than you think. I was, like you, over-thinking the whole thing the first time I tried to set up an Influx/MQTT connection. The way to do it is Sensor–>MQTT–>Telegraf–>InfluxDB.

I wrote a blog post about doing this with TheThingsNetwork a month or so ago which might be helpful: But essentially, all you need to do is configure the Telegraf HQTT plugin:

servers = ["tcp://"]
qos = 0
connection_timeout = "30s"
topics = [ "+/devices/+/up" ]
client_id = ""
username = “username"
password = “password"
data_format = "json"

And let Telegraf do the rest. It will automatically pull out and numeric or boolean values and insert them into InfluxDB for you.

Hope that helps!

1 Like

Thanks a lot @davidgs, I’ll try that.

Just out of curiosity, is there a possibility to use is it as a transformation component between two MQTT queues as well? Or parts of the TICK stack?

I guess it’s possible. I also use Kapacitor with the MQTT output configured so I can write data from Kapacitor to an MQTT broker, so I guess it would be possible to read from a broker, use Kapacitor to transform the data, and then write it back to an MQTT broker as well.

Interesting idea.