Search Array for name, SSID or MAC

How or where do I search a array? Using the Unifi Node looking for RogueAPs mac and signal strength.

Use a function node and the filter function

Example: javascript - Filter array of objects with another array of objects - Stack Overflow

Or an equivalent using a change node and JSONata :grinning:

thanks how do I find the name of the array? In the example its myArray , my output not sure suspect I need to put this into x to name it?

The name of the array, according to your screenshot is msg.payload

There’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

https://nodered.org/docs/user-guide/messages

Thanks and yes got that and can filter with a change node. What I want to figure out is searching the combined output for new bssid or oui for example from the combined output of the array (msg.payload). Looking for new bssid or oui not seen before. So this means I want to search the array for new unknown devices? Hopefully this makes sense.

So from what you say you want to identify any device not yet seen. The example Steve-Mcl pointed at provides the answer. You have to keep an array of known devices and compare the two arrays. From Stack Overflow (plus a bit),

const filterObjectArray = (arr, filterArr, filterProperty) => (
    arr.filter(el =>
        filterArr.every(f =>
            f[filterProperty] !== el[filterProperty]
        )
    )
)

Then

let knownDevices = context.get('knownDevices', 'file') || []
let deviceArray = msg.payload

let unknownDevices =  filterObjectArray(deviceArray, knownDevices, 'bssid')

.... do what ever you want with array of unknown devices

// Add unknown devices to known devices
knownDevices.push(...unknownDevices)

context.set('knownDevices', knownDevices, 'file')

The bssid should be unique so this should cover new oui properties also, but if you want to identify new oui properties as a separate check, rinse and repeat above using 'oui' as the filterProperty

You can do something similar to find non optimum signal strength

const minSignal = -40
const maxSignal = 30

const result = deviceArray.filter(device => device.signal < minSignal || device.signal > maxSignal)

Google is your friend but check the nodered docs for Node-RED and something like MDN Docs for javascript

Thanks Buckskin so I have added to a function node on message.

So this adds the knowdevices to unknown and does it compare?

knownDevices.push(...unknownDevices)

context.set('knownDevices', knownDevices, 'file')

Tried to review each portion of the code added // expressions/operators

So this should only return results between 30 to -40

device.signal less than minSignal || device.signal more than maxSignal
const minSignal = -40
const maxSignal = 30

So the out out looks the same prior to the function node / javascript, what am I misunderstanding?

The use of the functions were examples and provide different results. You haven't added the results to the msg.

If you are after both unknown devices and bad signals then try

let msg.unknownDevices = unknownDevices

to get an array of unknownDevices, and after

const result = deviceArray.filter(device => device.signal < minSignal || device.signal > maxSignal)`

use

let msg.badSignal = result

return msg

You will then have to monitor msg.unknownDevices and msg.badSignal instead of msg.payload. Use a debug node set to 'complete message object'

If you just want devices with a bad signal just use

let msg.payload = deviceArray.filter(device => device.signal < minSignal || device.signal > maxSignal)

Note: change minSignal & maxSignal values to whatever values you are actually defining as bad

Thanks but still not understanding, could you give me a complete example of any device with its bssid, a signal of say 30 max, -40 min to then give a msg output (will use (MQTT). What I am trying to do is detect any device not on the wireless ie not connected and beaconing that has a signal between 30-40 with its BSSID to say that there is a unknown device close by? TIA.

Thanks Buckskin

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