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.