WrtPresence 2023.11.0 Openwrt tracker (Openwrt->MQTT) Work in progress

Use Node-RED ‘read file’ node (one message per line), join to an array, then it just requires a bit of processing using JSONata.

[{"id":"b62e61a6723e0b82","type":"file in","z":"8b2aaf4879a370dd","name":"Read File","filename":"/config/user_data/test.txt","filenameType":"str","format":"lines","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":300,"y":660,"wires":[["0201364da18f2d88"]]},{"id":"bf4f1c07a90fd806","type":"inject","z":"8b2aaf4879a370dd","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":660,"wires":[["b62e61a6723e0b82"]]},{"id":"5fc14fd48a494f74","type":"debug","z":"8b2aaf4879a370dd","name":"debug 227","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":660,"wires":[]},{"id":"0201364da18f2d88","type":"join","z":"8b2aaf4879a370dd","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"3","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":450,"y":660,"wires":[["83c026ec43823fc0"]]},{"id":"83c026ec43823fc0","type":"change","z":"8b2aaf4879a370dd","name":"Extract","rules":[{"t":"set","p":"payload","pt":"msg","to":"(\t    $table:={\t        \"WifiAP-01_phy0-ap0\" : \"Router IOT\",\t        \"WifiAP-01_phy2-ap0\" : \"Router 2.4ghz\",\t        \"WifiAP-01_phy1-ap0\" : \"Router 5ghz\",\t        \"WifiAP-02_phy0-ap0\" : \"Mesh IOT\",\t        \"WifiAP-02_phy2-ap0\" : \"Mesh 2.4ghz\",\t        \"WifiAP-02_phy1-ap0\" : \"Mesh 5ghz\"\t        };\t        \t    payload#$i.(\t        $front:=$substringBefore($,\"=\");\t        $back:=$substringAfter($,\"=\");\t        $mac:=$substringBefore($back,\"=\");\t        $pwr:=$substringAfter($back,\"=\")~>$substringBefore(\" \")~>$number();\t        $ishome:=$pwr<5;\t        {\t            \"count\": $i+1,\t            \"device\": $lookup($table,$front),\t            \"mac\": $mac,\t            \"pwr\": $pwr,\t            \"home\": $ishome}\t    )\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":660,"wires":[["5fc14fd48a494f74"]]}]

The above assumes that the lines are formatted as given in your post so I can parse out the parts.

Change the file pathname as required.

Result - array of objects for each line with wifi device, mac address, power level, and Boolean for home or not.

Who needs scripts?

1 Like