Yes. You can populate the graph one of two ways. You can send an array of data points and the graph will fill itself with those. Or you can send individual points one at a time, and the graph will fill itself with those. You can use either method. In the method I showed, I'm sending individual data points, which eliminates the need for making an array to send at the end. If you want to use that method, then all you need to do is put a return null; at the end of the function. If you want to return a full array, then all you really need to do is create an array and then push the object into it, something like this:
var myKeys = Object.keys(msg.payload[0]);
delete myKeys[0];
var arrToSend = [];
for(let x of msg.payload){
for(let y of myKeys){
arrToSend.push({topic:y, payload:x[y], timestamp:x.Tijdstip});
}
}
Then you just return your array. Either way will work. It's up to you on which method you choose.
Interesting. From your debug, it looks like you're getting an every other message pattern. It also looks like your debug node is only configured to show msg.payload instead of the complete msg object. You'll want to change it to that so you can see the whole object coming through. The other thing you can do is to send out a copy of msg.payload and a copy of myKeys before it processes them. If you're using the code example I posted above, put this line after delete myKeys[]0];.
node.send({"myKeys":myKeys, "data":msg.payload});
This will pop out myKeys and msg.payload the the debug node so we can identify where it might be capturing the erroneous entries. Let me know what comes across on the debug and we'll be able to figure it out from there.
I have tried the following to remove the null of the array:
var myKeys = Object.keys(msg.payload[0]);
myKeys.shift();
//delete myKeys[0];
node.send({"myKeys":myKeys, "data":msg.payload});
var arrToSend = [];
for(let x of msg.payload){
for(let y of myKeys){
node.send({topic:y, timestamp:x.Tijdstip, payload:x[y]});
}
}
return null
And now I get the data I want to see on the graph only the graph doesn't show anything.
Only I have still one question. The time that is saved in the CSV file is from 10:50 and with the debug node I see that the flow is sending also 10:50 but the graph transfer the data to 11:50. How can I change that to the right time?
What format do the timestamps show now ? If the ISO8601 timestamp includes a 'Z', with the offset after that, or if there is no offset, it will assume UTC. You can add -1 after the Z to force the offset.
The inject node gives the UTC time 10:35 I change that with the Date/Time formatter node to 11:35 because the time in the CSV is correct with our local time.
When I ask for a graph the flow get the data from the CSV node and get 11:35 ("Z") and gives it trough to the graph node, and the graph node change the UTC time to the local time with +1 hour and then I see 12:35 on the graph.
I think the best solution for me: Not using the Date/Time formatter node and work only with UTC time, and the graph node transfers it to the right local time.
Most things that allow for time selection in Node-Red will utilize the standard format. When you select a time, the node will pass out the ISO time format that you're currently using, so you should just be able to add an if statement where the time to be checked is greater than the start time variable and less than the end time variable.