I'm using a sql statement msg.topic='SELECT HOUR(Time) as Htime, Temperature FROM `temp-at-interrupt` where minute(Time)= "00" order by Date DESC, Time DESC LIMIT 20';
which returns the following structure: array[20]
[0 … 9]
0: object
Htime: 19
Temperature: 83.33
1: object
Htime: 18
Temperature: 83.09
2: object
Htime: 17
Temperature: 82.79
The function node is:
// Create a data variable
//
var series = ["temp F"];
var labels = ["Data Values"];
var data = "[[";
for (var i=0; i < msg.payload.length; i++) {
//var myHour = msg.payload[i].Htime;
data += '{ "x":' + msg.payload[i].Htime + ', "y":' + msg.payload[i].Temparature + '}';
//data += '{ "x":' + msg.payload[i].thetime + ', "y":' + msg.payload[i].thetemp + '}';
if (i < (msg.payload.length - 1)) {
data += ","
} else {
data += "]]"
}
}
var jsondata = JSON.parse(data);
msg.payload = [{"series": series, "data": jsondata, "labels": labels}];
return msg;
The debug errors are:
"
4/2/2020, 7:21:45 PMnode: sql-lite-functionfunction : (error)
"SyntaxError: Unexpected token u in JSON at position 16"
"
Seems pretty easy by I'm missing something. I've been working on this all week and need your expertise. Appreciate your expertise as I'm really, really new.
I wish I has a line-by-line error checking app instead of a debug-node. There's just not enough information for me to troubleshoot.