Node red output to CSV

275 views
Skip to first unread message

Ventsislav Gyondrov

unread,
Oct 10, 2017, 4:03:12 PM10/10/17
to Node-RED

Julian Knight

unread,
Oct 12, 2017, 4:03:33 AM10/12/17
to Node-RED
Hmm, you have really jumped into the deep end there!

There are a few things you are going to have to learn so I hope you are sitting down.

The first thing you need to learn is some JavaScript basics. In particular, how to split a string using a token. So, for example:

var splitted = msg.payload.split(',')

var mydate = splitted[0]
var topic = splitted[1]
var temperature = splitted[2]

var topicSplit = topic.split('/')
var camera = topicSplit[1]

Would split the incoming MQTT message into 3 parts as an array. Then further splits the MQTT topic and extracts the camera device name.

The next issue is how to group up the data. This is called pivoting. Your data is coming in with a timestamp, and you want to pivot that to have 1 record per day. There are a number of issues there and I don't really have time to go through them all now. But let me at least start by asking whether you can be sure that you will always get the same number of temperature values per day? Because if you can't do that, I wouldn't recommend the format you are asking for since your CSV won't always have the same number of columns and the trailing camera name column won't always be in the same place.

So maybe another question would be - what do you intend to do with the CSV file?

Ventsislav Gyondrov

unread,
Oct 14, 2017, 8:42:00 AM10/14/17
to Node-RED
Thanks for the reply Julian,

I will take you advice on board and will get to know the basic of Javascript a bit before asking stupid questions :)
I guess i'm trying to build a house from the roof down...





Julian Knight

unread,
Oct 14, 2017, 8:51:56 AM10/14/17
to Node-RED
No problem. There's no such thing as a stupid question though ;-)

Good news is that there are plenty of websites out there to help learn a few basics and some nifty Googling will generally see you through.

More good news - there are lots of people in this group who are willing and happy to help.

Even more good news - Node-RED makes it REALLY easy to get going with using JavaScript because it does a lot of "heavy lifting" for you. So do start to experiment by loading in your data and playing with the various tools to reshape the data.

So have a play and by all means continue to ask questions. Also, feel free to describe what you want to achieve because there is a lot of experience in the group and you may well get a number of alternatives you can try.
Reply all
Reply to author
Forward
0 new messages