Hi, I would like to chart following example data which I read from a Python file, transmit it by means of JSON an MQTT to my Node-red Dashboard and chart it.
nodedata = [{"datum": 1500049458014,"tempc": 15.7}, {"datum": 1500049459014,"tempc": 25.9},
{"datum": 1500049459114,"tempc": 23.4}, {"datum": 1500049469214,"tempc": 15.1},
{"datum": 1500049470114,"tempc": 23.8}, {"datum": 1500049480214,"tempc": 17.1}]
I send it by means of MQTT to my dashboard:
js_nd = json.dumps(nodedata)
client.publish("datatoplotter"), js_nd)
In the dashboard I receive the data by means of a mqtt-in node, transfer it to a function node coded like this:
var newMsg = {};
newMsg.payload = [{
key: "temp",
values: , label: "Temp"
}];
for (i = 0; i < msg.payload.length; i++) {
newMsg.payload[0].values.push (
msg.payload[i].datum, msg.payload[i].tempc);
}
msg = newMsg;
return msg;
The output of the function node feeds the chart node.. but it doesn't work.
The debug window shows this:
23.3.2022, 21:11:56node: 46e676c23f9c6725msg : string[15]
"Bad data inject"
23.3.2022, 21:11:56node: 69fe935de3ecf2edmsg.payload : array[1]
array[1]
0: object
key: "temp"
values: array[12]
[0 … 9]
[10 … 11]
10: 1500049480214
11: 17.1
label: "Temp"
Someone can help me?
Thanks in advance,
Alf