Nodes global variables

Great work man! Absolutely great...now i know how it works!

Thanks a lot!!

Hi @Steve-Mcl

One last question about the flow, i want to have one final message with the devices that are not updated (comparing them in the previous nodes), is it possible with a Switch node?.

Thanks a lot!

In the message is already a list (array) of devices that don't have up to date firmware already. I don't understand what you are asking.

ok, i mean, what about to filter somehow the devices that have key/value match:false, that tells me what are the devices that are not updated.

I don't understand. The array in msg.payload.old is already a filtered list of all devices that don't match the web version (match: false). What exactly do you require? What is it you are trying to achieve?

Ok, i want to send via Telegram (i already use this), only the devices that are not updated. Maybe i should filter somehow only the OLD array in order to obtain what i want.

image

Maybe i misundertood something o im confused...

there is no need to filter - just use msg.payload.old - all items in that list (array) will be the NON matching versions. You already have this!


However, as you are sending to telegram then you likely want a string so try this...

add function node ("after compare version" function)

var oldDevices = msg.payload.old;
if(oldDevices && oldDevices.length) {
  msg.payload = `Found ${oldDevices.length} devices with wrong version...\n` + msg.payload.old.map(e => `NAME: ${e.name}, IP: ${ipAddress}, VER: ${e.version}`).join("\n")
  return msg;
}

Uh ok, great approach...

There is something wrong or missing with the IpAddress key...

I have this inside the function node, i've added the telegram options so i can send the message.
image

Was missing the e. (code was untested)

var oldDevices = msg.payload.old;
if(oldDevices && oldDevices.length) {
  msg.payload = `Found ${oldDevices.length} devices with wrong version...\n` + msg.payload.old.map(e => `NAME: ${e.name}, IP: ${e.ipAddress}, VER: ${e.version}`).join("\n")
  return msg;
}

Thanks it works great!!

Regards!

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