Filtering JSON WiFi data

Hello,

I am new to Node-Red and I am struggling to find a way to filter JSON data - lets break it down.
My WiFi Data looks like:

{"id_external":"*3103B","mac":"58:XX:25:XX:52:XX","eap":"","interface":"2.4GHz-XXX11-4np-BD-1-2",
"ssid":"XXXiot2","uptime":"12s260ms","packets":"172,172","bytes":"11220,40525","tx_rate":"21.6Mbps-20MHz/1S/SGI",
"rx_rate":"13Mbps-20MHz/1S","tx_rate_set":"OFDM:6-54 BW:1x SGI:1x HT:0-7"}"

I want to retain only data which contains/equals to list of specific mac adresses.

Even better solution would be similar to this node from pallete: node-red-contrib-filter. This node allows for filtering specific values to separate outputs. But this node is not working for JSON as far as I can tell.

Any suggestions? I found some topics about but it has not worked for me. Thanks!

You can do something like this, which will only pass messages where mac is in the list-

let list = ["58:XX:25:XX:52:XX","XX:XX:XX:XX:XX:XX"]
let index = list.indexOf(msg.payload.mac)

if (index != -1) {
    return msg;
}
[{"id":"4a338a4e4a03e0d0","type":"debug","z":"e881895e805989dc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":970,"y":540,"wires":[]},{"id":"fda42ac906f399c1","type":"function","z":"e881895e805989dc","name":"","func":"let list = [\"58:XX:25:XX:52:XX\",\"XX:XX:XX:XX:XX:XX\"]\nlet index = list.indexOf(msg.payload.mac)\n\nif (index != -1) {\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":820,"y":540,"wires":[["4a338a4e4a03e0d0"]]},{"id":"c5fa6e88615664a5","type":"inject","z":"e881895e805989dc","name":"In List","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id_external\":\"*3103B\",\"mac\":\"58:XX:25:XX:52:XX\",\"eap\":\"\",\"interface\":\"2.4GHz-XXX11-4np-BD-1-2\",\"ssid\":\"XXXiot2\",\"uptime\":\"12s260ms\",\"packets\":\"172,172\",\"bytes\":\"11220,40525\",\"tx_rate\":\"21.6Mbps-20MHz/1S/SGI\",\"rx_rate\":\"13Mbps-20MHz/1S\",\"tx_rate_set\":\"OFDM:6-54 BW:1x SGI:1x HT:0-7\"}","payloadType":"json","x":610,"y":500,"wires":[["fda42ac906f399c1"]]},{"id":"e9bdf8589a2887e1","type":"inject","z":"e881895e805989dc","name":"In List","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id_external\":\"*3103B\",\"mac\":\"XX:XX:XX:XX:XX:XX\",\"eap\":\"\",\"interface\":\"2.4GHz-XXX11-4np-BD-1-2\",\"ssid\":\"XXXiot2\",\"uptime\":\"12s260ms\",\"packets\":\"172,172\",\"bytes\":\"11220,40525\",\"tx_rate\":\"21.6Mbps-20MHz/1S/SGI\",\"rx_rate\":\"13Mbps-20MHz/1S\",\"tx_rate_set\":\"OFDM:6-54 BW:1x SGI:1x HT:0-7\"}","payloadType":"json","x":610,"y":560,"wires":[["fda42ac906f399c1"]]},{"id":"77abe898e8132cee","type":"inject","z":"e881895e805989dc","name":"Not In List","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id_external\":\"*3103B\",\"mac\":\"YY:XX:XX:XX:XX:XX\",\"eap\":\"\",\"interface\":\"2.4GHz-XXX11-4np-BD-1-2\",\"ssid\":\"XXXiot2\",\"uptime\":\"12s260ms\",\"packets\":\"172,172\",\"bytes\":\"11220,40525\",\"tx_rate\":\"21.6Mbps-20MHz/1S/SGI\",\"rx_rate\":\"13Mbps-20MHz/1S\",\"tx_rate_set\":\"OFDM:6-54 BW:1x SGI:1x HT:0-7\"}","payloadType":"json","x":620,"y":620,"wires":[["fda42ac906f399c1"]]}]
1 Like