Send csv file to influxdb using node-red

you need to build the the array of objects. I will give you an example of what I do. I have data coming into the function node that looks like this:

{
  "_event" : "node:9a8228ea.126e",
  "_msgid" : "f6d98534.55ecd8",
  "device" : "bme280",
  "location" : "geodome",
  "measurement" : "humidity",
  "mqtt" : "local",
  "node" : "node44",
  "payload" : 78.54,
  "qos" : 0,
  "retain" : false,
  "timestamp" : 1593010032187,
  "topic" : "wsremote/data/node44/bme280/humidity",
  "type" : "data"
}

I run it thru my function node which is this:

// create object and populate with Influx tags
var tags = {}
tags.node = msg.node
tags.device = msg.device
tags.location = msg.location

// create object for measurement values
var v = {}
v.value = msg.payload // the measurement value

// create and fill array for the payload
var arr = [] 
arr[0] = v            // the measurement value
arr[1] = tags

// put the array into msg.payload and send it off
msg.payload = arr
return msg;

And this is what comes out (and I feed this to the influx node):

{
  "_event" : "node:9a8228ea.126e",
  "_msgid" : "f6d98534.55ecd8",
  "device" : "bme280",
  "location" : "geodome",
  "measurement" : "humidity",
  "mqtt" : "local",
  "node" : "node44",
  "payload" : [
    {
      "value" : 78.54
    },
    {
      "device" : "bme280",
      "location" : "geodome",
      "node" : "node44"
    }
  ],
  "qos" : 0,
  "retain" : false,
  "timestamp" : 1593010032187,
  "topic" : "wsremote/data/node44/bme280/humidity",
  "type" : "data"
}
1 Like