I am seeing this error:
{"_msgid":"772966b40bfa3282","_event":"node:eafdfa87.79d67","error":{"message":"TypeError: Cannot read property 'colour' of undefined","source":{"id":"fed40e07.141c68","type":"function","name":"Ack event *","count":1}},"_error":{},"settings":{"input":"2022-09-20T00:37:11.134Z","input_format":"","input_tz":"Australia/Sydney","output_format":"YYYY-MM-DD HH:mm:ss","output_locale":"en_AU","output_tz":"Australia/Sydney"},"time":"2022-09-20 10:37:11","payload":{"message":"TypeError: Cannot read property 'colour' of undefined","source":{"id":"fed40e07.141c68","type":"function","name":"Ack event *","count":1}},"topic":"ERROR_REPORT/TelePi/Local Readings"}
Important part:
TypeError: Cannot read property 'colour' of undefined
So looking at the sauce (sorry)
Function node with code:
// 2022 07 16 To fix undefined errors.
if (msg.payload.colour == undefined)
msg.payload.colour = "red";
var x = msg.payload.colour;
var who = msg.payload.device;
var led_msg = msg.payload.led;
var event = msg.payload.event; // 2022 02 04 Added.
var more = flow.get("more_messages") || 0;
var msg2 = {};
// 2022 01 30 Still giving errors.
// 2022 02 04 Looking good.
var led = led_msg ? parseInt(led_msg.substring(4,5)) : 0
// See top of code
//// 2022 02 25 Fixing problem is msg.payload.colour is not set. (Probably at boot)
//if (x == undefined)
// x = "red";
node.warn("X " + x);
node.warn("Who " + who);
node.warn("led " + led_msg);
if (more > 0)
{
// x = "orange";
//
msg2.payload = {"background":"red","color":"black","label":"MORE"};
// msg2 = {"background":"red","color":"black","label":"MORE"};
}
if (more == 0)
{
//
node.warn("MORE = 0");
// msg2.payload = {"background":"darkgreen","color":"white","who":"ACK"};
msg2.payload = {"background":"darkgreen","color":"white","label":"ACK"};
led = context.get("old_led") || 0;
}
if (who == "All clear")
{
//
node.warn("ALL CLEAR");
msg = {
"payload": "rgb," + led + ",0,0,0", // Needed to handle varying led numbers
"who":"All clear", // Depricated 2021 12 04
"wipe":"CLEAR"
};
msg1 = {payload: '<font color = '+x+'><i class="fa fa-bullseye fa-2x"></i></font>',"who": "All Clr "}; // Should be `event`?
//msg1 = {payload: '<font color = '+x+'><i class="fa fa-bullseye fa-2x"></i></font>',"who": event};
//
}
else
{
//
msg.payload = led_msg;
msg1 = {payload: '<font color = '+x+'><i class="fa fa-bullseye fa-2x"></i></font>',"who": who};
//msg1 = {payload: '<font color = '+x+'><i class="fa fa-bullseye fa-2x"></i></font>',"who": event};
// node.warn("Colour " + x);
// node.warn("Who " + who);
// node.warn("Led " + led);
// node.warn("More " + more);
context.set("old_led",led);
}
return [msg,msg1,msg2];
Forgive all the comments.
But looking at the top bit of it:
// 2022 07 16 To fix undefined errors.
if (msg.payload.colour == undefined)
msg.payload.colour = "red";
var x = msg.payload.colour;
Unless colour
is from somewhere else.
But those lines should stop the problem for x
getting msg.payload.colour
if it not defined.
Thoughts?