Hello! Newbie here, starting to learn Node-Red.
I've been wrestling with this for more than 2 weeks, being on and off, when time allows.
I have a database, in which I make a query, and get results for temperature and humidity.
These came from sensors with MQTT.
Example of my query results:
{"timestamp":"2020-06-08T21:32:59.000Z","data":"22.60","topic":"abrigo/temp"},{"timestamp":"2020-06-08T21:32:59.000Z","data":"63.00","topic":"abrigo/humi"}
I tried several ways to make this data good for a 2 line char, one for "abrigo/temp", one for "abrigo/humi".
I feel I'm close with my new approach but I cannot advance so I am asking for help.
This is my actual setup in a function to get the data prepared:
var msg1 = {};
let dataH =[];
let dataT =[];
msg1.topic = "Temp/Humi";
for (let X in msg.payload)
{
if (msg.payload[X].topic == "abrigo/humi")
{
dataH.push({"x":msg.payload[X].timestamp, "y":msg.payload[X].data});
}
else
{
dataT.push({"x":msg.payload[X].timestamp, "y":msg.payload[X].data});
}
}
msg1.payload = [{"series":["Humidade", "Temperatura"], "data":[[dataH],[dataT]],"labels": ["Humidade","Temperatura"]}];
return (msg1);
The result from this function is this:
{
"series":[
"Humidade",
"Temperatura"
],
"data":[
[
[
{
"x":"2020-06-08T21:32:59.000Z",
"y":"63.00"
},
{
"x":"2020-06-08T21:33:59.000Z",
"y":"56.00"
},
{
"x":"2020-06-08T21:47:08.000Z",
"y":"49.00"
},
{
"x":"2020-06-08T21:57:08.000Z",
"y":"53.00"
},
{
"x":"2020-06-08T22:07:08.000Z",
"y":"53.00"
}
]
],
[
[
{
"x":"2020-06-08T21:32:59.000Z",
"y":"22.60"
},
{
"x":"2020-06-08T21:33:59.000Z",
"y":"24.70"
},
{
"x":"2020-06-08T21:47:08.000Z",
"y":"25.20"
},
{
"x":"2020-06-08T21:57:08.000Z",
"y":"23.20"
},
{
"x":"2020-06-08T22:07:08.000Z",
"y":"23.20"
},
{
"x":"2020-06-08T22:17:08.000Z",
"y":"23.10"
}
]
]
],
"labels":[
"Humidade",
"Temperatura"
]
}
But his does not get me a 2 line graphic.
Can someone help me to understand what is wrong here?
Thank you in advance!