problem with node-red influxdb node

1,587 views
Skip to first unread message

Thomas Rockenbauer

unread,
Jan 21, 2016, 3:41:02 PM1/21/16
to Node-RED
Hey everybody!

I am a node-red beginner but I was able to set up a small Ubuntu 15.10 server with node-red and Influxdb at home. 

Node-RED version: v0.13.0
Node.js  version: v5.4.1
Influxdb version: 9.6.1

My aim is to receive sensor data with node-red and send it to influxdb. Therefor I have added node-red-contrib-influxdb and node-red-contrib-particle to node-red. 
Receiving the data works and I can also send it to my database, but it is inserted in the wrong way.

I am publishing my sensor values via: 
Particle.publish("Event", String::format("data,name=testname t=%.2f,p=%.2f", temp, pressure));

My debug node receives my published data as: 

msg.payload : string [35]

data,name=testname t=25.34,p=966.46

My flow:




In my database it looks like this: 

Only the last line is correct because I inserted it manually into the database.
I think the problem is that the influxdb node receives everything as one string. I would be really grateful if you could help me to get my data into the correct format for the influxdb node.
Kind regards,Tom



Dave C-J

unread,
Jan 21, 2016, 4:19:04 PM1/21/16
to node...@googlegroups.com
You need to the get the data to be a javascript object... 
The easiest way is to parse a JSON object which would be converted from a string like
{"name":"testname", "t":25.34, "p":966.46}
and passing that through the JSON node to create an object.
So you can either change your arduino to send a string like that - or write a function node to slice apart your existing string and create a proper object...

Thomas Rockenbauer

unread,
Jan 21, 2016, 5:49:50 PM1/21/16
to Node-RED
Thank you very much, I used a json node and now it works :)
There is only one litte problem. JSON will be removed in future versions of Influxdb: see here
Is there also a way to get it work with the influxdb line protocol? line protocol

Mark Setrem

unread,
Jan 21, 2016, 6:45:43 PM1/21/16
to Node-RED
Well the first thing is you don't have to update if everything you want is working.

But if you do want to get better at using node-red, as Dave said it will be quite easy for you to take the object and reformat it into what ever format you want.

I'm guessing that if you configure the debug node to display msg.payload.p it now displays the pressure value? 
so you should be now able to define a variable for each piece of data you want

eg

var p = msg.payload.p;

if you want to create a string that joins variables together or adds other text you use  + 
so for example 
var textString = "The pressure is "+p;

would create a variable called textString that adds the current pressure on to the the text "The pressure is "

so have a go and if you get stuck post your function code here and people will help you.

Dave C-J

unread,
Jan 21, 2016, 7:10:53 PM1/21/16
to node...@googlegroups.com
Thomas,

you may want to raise this as an issue on the influxdb node projetct maintainer ?

Thomas Rockenbauer

unread,
Jan 24, 2016, 6:25:08 PM1/24/16
to Node-RED
Hi Mark,

I have tried your suggestion but it is not working as expected.

My flow:

My first debug node shows:

msg.payload : array [2][ { "t": 24.39, "p": 969.62, "h": 47.14, "v": 4.06, "c": 97 }, { "Name": "Max", "Location": "Garden" } ]


My function node:
var p = msg.payload.p;

var textString = "The pressure is "+p;
return textString;

The output of the function node is:
function : (error)TypeError: Cannot assign to read only property '_msgid' of The pressure is undefined

I think it has to do with the array. I have googled it but I could not find a solution.Any help would be greatly appreciated!

Nicholas O'Leary

unread,
Jan 24, 2016, 6:27:01 PM1/24/16
to Node-RED Mailing List
You function is returning a string, not a message object.

Try:
    msg.payload = "The pressure is "+msg.payload.p;
    return msg;

--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas Rockenbauer

unread,
Jan 24, 2016, 6:27:12 PM1/24/16
to Node-RED
Hi Dave,

I have contacted the influxdb node projetct maintainer and if I understood everything correctly the node converts the JSON data to the line protocol :)

Thomas Rockenbauer

unread,
Jan 25, 2016, 6:25:01 PM1/25/16
to Node-RED
Hi Nick,

I have tried your suggestion but it did not work. My debug node returned:

msg.payload : string [25]
The pressure is undefined

Nicholas O'Leary

unread,
Jan 25, 2016, 6:27:51 PM1/25/16
to Node-RED Mailing List
Hi,

sorry, didn't look too closely at your whole post.

The first debug node indicates msg.payload is an array of two elements. The first element is the object with the 'p' property - I assume that's the one your after. So rather than msg.payload.p, you need msg.payload[0].p :

    msg.payload = "The pressure is "+msg.payload[0].p;
    return msg;
Reply all
Reply to author
Forward
0 new messages