Updated to NR 3, now getting errors

Hey gang,
I recently updated to NR v3 and now one of my function nodes is throwing the error "TypeError: msg.payload[0].filter is not a function"

This is processing the output of the Unifi node which is generating a list of connected client devices. This code is filtering them and sending to separate outputs on the function node.

const lastSeenSeconds = 20;

let presenceCutoff = (Date.now() - (lastSeenSeconds * 1000)) / 1000; 
const people = {
    "presence/phone1": "redacted_MAC",
    "presence/phone2": "redacted_MAC",
    "presence/phone3": "redacted_MAC"
};

return Object.keys(people).map(function(topic) {
    let devices = msg.payload[0].filter(device => device.mac === people[topic]);
//    let devices = msg.payload[0].filter(device => device.mac === people[topic]) && (device.last_seen > presenceCutoff);
    return {
        topic: topic,
        //retain: true,
        payload: devices.length > 0
    };
});

Anyone have any idea how to fix this?

Thanks in advance,
Dax.

What is msg.payload[0] when the error is thrown

Hey @E1cid, honestly, I have no idea. The script was taken from an example about 4 years ago and has worked perfectly since then.

Oh, wait, are you asking to see an example payload? I can provide that if you like. :slight_smile:

The use a debug node prior to the function, then you can see the value of msg.payload.
or use node.warn(typof msg.payload[0]) prior to the let devices line.

1 Like

This is now solved, though I'm still not sure what changed in order to break this. Either the way NR 3 treats data from the Unifi node or the format of the data outputted by the Unifi node.

Details are here: Node-Red UniFi Presence.md · GitHub

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.