Reading from an MQTT array

Hi, I am very new to Telegraf and would like some suggestions about how to ingest JSON arrays of seismic data into Influxdb 2.0.

This sensor data arrives every second from an accelerometer that buffers 32 samples per second for all 3 axis (x, y and z). It registers the timestamp device_t when it grabs the last of those samples, then sends the JSON msg via MQTT, which would be then received by Telegraf using the following topic:

accel/VEHIGE9820/data, where VEHIGE9820 is the device_id (tag for influxdb). Perhaps we could a wildcard to catch all the devices with accel/*/data ?

Here is a sample msg:


Using node-red I am able to convert this into individual messages, by looping on the array of each axis, and adding a timestamp which is uses 1/32 of the last second in epoch time. However I would prefer to have this done via Telegraf as I feel it would be more efficient.

Here is the node-red function code I use to make the individual timestamped messages for influxdb (works fine):

var deviceid = msg.payload.device_id;
var timestamp = msg.payload.device_t;

for (var i = 0; i < msg.payload.x.length; i++) {
    var newMsg = {};
    var accelx = (msg.payload.x[i]) / 1000;
    var accely = (msg.payload.y[i]) / 1000;
    var accelz = (msg.payload.z[i]) / 1000;
    var time = timestamp - 1000 + (i/125 * 1000);
    newMsg.payload = [{ time: time, x: accelx, y: accely, z: accelz }, { tag: deviceid }];
return null;

any help on how to do this in Telegraf (if its even possible!) would be very appreciated !

Hello @seismicdatalogger,
Yes! You can use the Telegraf file plugin.

And the following:

Then you could also use the execd processor plugin to process that data.

Or you could just use the execd input plugin and just use your script.

On second thought I’d probably go with the second option. I think from a UX perspective that would be the easiest.