Inserting multiple columns at once in InfluxDB

Hi.

I'm kind of new to NodeRed, so pardon me if this question seems obvious.

I'm pushing datas from a BMP085 sensor to a MQTT broker. This data is then retrieved and processed into NodeRed and stored into InfluxDB.

This is the data straight from MQTT:

Then, the data is formatted using a function node:

var tokens = msg.topic.split("/");
var payload = (
    {
        measurement: tokens[2]+tokens[3],
        fields: {
            "temp": msg.payload.temp,
            "press": msg.payload.press,
            "alt": msg.payload.alt,
            "SLP": msg.payload.SLP,
            "RA": msg.payload.RA
        },
        tags: {
            tag1: "i'm a tag",
            tag2: "hello"
        },
        timestamp: new Date()
    }
);
node.send({payload});

Then it passes through a JSON node, and finally to an InfluxDB node. The data is written info the database, but clearly not the way I'd like to.

My goal here is to have a table (er, I mean "a measurement"), with:

  • the name of the measurement being the room name + the sensor name (here "workshopBMP085")
  • each value ("temp", "press"...) representing a column.

But I can't get it right.

First, the measurement name is "workshop", no matter how I format. At the beginning I wanted it to be "tokens[2]+"-"+tokens[3]", but I couldn't make it work.

Next, and this is the worst part, the measurement only contains 2 columns: timestamp and the whole JSON object stuffed into a single column (snapshot from Chronograf) :

Can someone tell me what am I doing wrong?

If it can help, here is the whole flow:

[{"id":"92bba980.922ad8","type":"function","z":"821ed147.a04a9","name":"Formatting","func":"var tokens = msg.topic.split(\"/\");\nvar payload = (\n    {\n        measurement: tokens[2]+tokens[3],\n        fields: {\n            \"temp\": msg.payload.temp,\n            \"press\": msg.payload.press,\n            \"alt\": msg.payload.alt,\n            \"SLP\": msg.payload.SLP,\n            \"RA\": msg.payload.RA\n        },\n        tags: {\n            tag1: \"i'm a tag\",\n            tag2: \"hello\"\n        },\n        timestamp: new Date()\n    }\n);\nnode.send({payload});","outputs":1,"noerr":0,"x":210,"y":240,"wires":[["79459d7d.584724"]]}]

Thanks a lot in advance.

I found the solution, finally. RTFM they said...

Anyway, here is the flow code:

[{"id":"821ed147.a04a9","type":"tab","label":"Sensors","disabled":false,"info":""},{"id":"3d43f4f9.77f9cc","type":"mqtt in","z":"821ed147.a04a9","name":"sensors/home/workshop/BMP085","topic":"sensors/home/workshop/BMP085","qos":"2","datatype":"json","broker":"544a35ca.82bdbc","x":160,"y":140,"wires":[["92bba980.922ad8","2c7681a0.8eccde"]]},{"id":"2c7681a0.8eccde","type":"debug","z":"821ed147.a04a9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":570,"y":140,"wires":[]},{"id":"2d0c5747.04bf28","type":"influxdb out","z":"821ed147.a04a9","influxdb":"f0fe03f1.28cb6","name":"workshop-BMP085","measurement":"workshop-BMP085","precision":"s","retentionPolicy":"","x":570,"y":240,"wires":[]},{"id":"92bba980.922ad8","type":"function","z":"821ed147.a04a9","name":"Formatting","func":"var data = {\n    temp: msg.payload.temp,\n    press: msg.payload.press,\n    alt: msg.payload.alt,\n    SLP: msg.payload.SLP,\n    RA: msg.payload.RA\n}\nmsg.payload = data\nreturn msg","outputs":1,"noerr":0,"x":210,"y":240,"wires":[["2d0c5747.04bf28","c3b1779b.ea8c38"]]},{"id":"c3b1779b.ea8c38","type":"debug","z":"821ed147.a04a9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":590,"y":360,"wires":[]},{"id":"64c2e370.049afc","type":"inject","z":"821ed147.a04a9","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":180,"y":660,"wires":[["6c6bf02d.8ac09"]]},{"id":"6c6bf02d.8ac09","type":"function","z":"821ed147.a04a9","name":"Fields","func":"msg.payload = {\n    numValue: 123.0,\n    strValue: \"message\",\n    randomValue: Math.random()*10\n}\nreturn msg;","outputs":1,"noerr":0,"x":328,"y":660,"wires":[["54de52b9.99ad0c"]]},{"id":"54de52b9.99ad0c","type":"influxdb out","z":"821ed147.a04a9","influxdb":"1ed2b814.fe29c8","name":"","measurement":"test","x":498,"y":660,"wires":[]},{"id":"544a35ca.82bdbc","type":"mqtt-broker","z":"","name":"broker.x99.fr","broker":"172.18.0.14","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"f0fe03f1.28cb6","type":"influxdb","z":"","hostname":"influxdb","port":"8086","protocol":"http","database":"nodered","name":"","usetls":false,"tls":""},{"id":"1ed2b814.fe29c8","type":"influxdb","z":"821ed147.a04a9","hostname":"127.0.0.1","port":"8086","database":"aTimeSeries","name":"aTimeSeries"}]