I'm looking for a suggestion on the easiest way to try and filter out objects I receive from a web site.
Background is mountain top amateur radio and getting info from a web site of who is currently atop a mountain (or hill). The program is called Summits on the Air.
I poll the sota site periodically and get back an array of objects where each object is a SPOT in SOTA terminology representing someone on a mountain.
I'd like to potentially toss some of the SPOTs out the window and display a subset in a UI Table. I have a prototype working and can get SPOTS, send to a UI table and then drill into detail and "tune" my radio to the shortwave frequency in the SPOT (see Node-Red Calling Summit to Summit – Paul Gacek if interested in my screens etc).
The guidance I'm seeking is how do I filter out some of the spots?
I thought about manipulating the .parts section and decrementing count/index etc. I also thought about creating my own array of objects after the SPLIT and forgo the JOIN and then send my array of objects into the TABLE via an addRow but this has drawbacks and it wasn't obvious how to get it working.
Anyway any suggestions are welcome.
Here is my code that grabs the SPOTS from the external SOTA site.
{
"id": "67d10e61ca893b41",
"type": "inject",
"z": "463ef4b793ac2a48",
"name": "Poll SOTA every 60 seconds",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "30",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 200,
"y": 80,
"wires": [
[
"900a285c4466b32a"
]
]
},
{
"id": "900a285c4466b32a",
"type": "http request",
"z": "463ef4b793ac2a48",
"name": "Get last 20SPOTS from SOTA",
"method": "GET",
"ret": "obj",
"paytoqs": "body",
"url": "https://api2.sota.org.uk/api/spots/20/all",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 250,
"y": 160,
"wires": [
[
"9e7d538c37b4bcae"
]
]
},
{
"id": "a059249fd9a72560",
"type": "split",
"z": "463ef4b793ac2a48",
"name": "",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "",
"x": 390,
"y": 340,
"wires": [
[
"9d8057e31ab49074"
]
]
},
{
"id": "911ef50047c21738",
"type": "function",
"z": "463ef4b793ac2a48",
"name": "Format SPOT Time",
"func": "var spotTime = (new Date(msg.payload.timeStamp));\n\n\nmsg.payload.spotHM = spotTime.getHours().toString() + \":\";\n\n//if (spotTime.getMinutes().toString().length == 1) {msg.payload.spotMM += \"0\"};\n\nmsg.payload.spotHM += spotTime.getMinutes().toString();\n\nreturn msg;\n",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 530,
"y": 100,
"wires": [
[
"355727610ffc08be"
]
]
},
{
"id": "07f438a2621b922e",
"type": "join",
"z": "463ef4b793ac2a48",
"name": "",
"mode": "custom",
"build": "array",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 690,
"y": 280,
"wires": [
[
"2e42056c913fb023",
"dcf1a5fc267a4c2f",
"9f6a4ea5ad194642",
"537197a46fc60131"
]
]
},
{
"id": "9d8057e31ab49074",
"type": "function",
"z": "463ef4b793ac2a48",
"name": "Mode to Upper",
"func": "let mode = msg.payload.mode;\n\nmsg.payload.mode = mode.toUpperCase();\n\n//if (msg.payload.mode == \"CW\") {\n// delete msg.payload;\n// return 0;\n//} else \n\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 460,
"y": 240,
"wires": [
[
"911ef50047c21738"
]
]
},
{
"id": "355727610ffc08be",
"type": "function",
"z": "463ef4b793ac2a48",
"name": "SPOT Age -> LED color",
"func": "let s = msg.payload.timeStamp + 'Z';\n\nmsg.SOTAUTC = s;\n\nconst d = new Date(s);\nmsg.SOTAUTCmsec = d.getTime();\n\nmsg.spotAge = (global.get('timeNowInUTC') - d.getTime()) / (1000*60);\n\n// current time and spot time compare\n// if less than green/yellow boundary = green, \n// else if less than yellow/red boundary = yellow etc\n// LED colum = 0-99 number and its format is a traffic light\n\nlet ageInMin = Math.floor(msg.spotAge);\n\nif (ageInMin <= 5) {\n // Green\n flow.set('greenLedOff', false);\n msg.payload.LED = \"95\";\n} else if (ageInMin <= 10) {\n // Yellow\n flow.set('yellowLedOff', false);\n msg.payload.LED = \"40\";\n} else {\n // red\n flow.set('redLedOff', false);\n msg.payload.LED = \"5\";\n} \n\n//msg.payload.LED = msg.payload.LED.toString();\n\nmsg.payload.ageInMin = ageInMin;\n\nreturn msg;\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 750,
"y": 60,
"wires": [
[
"07f438a2621b922e",
"5daf8f992284930c"
]
]
},
{
"id": "9e7d538c37b4bcae",
"type": "change",
"z": "463ef4b793ac2a48",
"name": "LEDs off potentially",
"rules": [
{
"t": "set",
"p": "greenLedOff",
"pt": "flow",
"to": "true",
"tot": "bool"
},
{
"t": "set",
"p": "yellowLedOff",
"pt": "flow",
"to": "true",
"tot": "bool"
},
{
"t": "set",
"p": "redLedOff",
"pt": "flow",
"to": "true",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 210,
"y": 260,
"wires": [
[
"a059249fd9a72560"
]
]
}
]
Paul