Get data from APCUPSD

The APCACCESS is a little bit broken and reports network errors the whole time. I started to play arround with the apcaccess output on the console and build a flow to extract the information and turn them into objects with a function node. Hope i helped somebody with that.

[{"id":"9943bf81dd01ebe6","type":"exec","z":"97f8641c.552078","command":"sudo apcaccess status -u","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":1650,"y":160,"wires":[["c5e21d8231c01359"],[],[]]},{"id":"05b154bbf98b3ae5","type":"inject","z":"97f8641c.552078","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":1420,"y":160,"wires":[["9943bf81dd01ebe6"]]},{"id":"c5e21d8231c01359","type":"function","z":"97f8641c.552078","name":"","func":"const lines = msg.payload.split(\"\\n\");\nlet result = {};\n\nfor (let i = 0; i < lines.length ; i++) {\n    const line = lines[i].trim();\n    if(!line) continue;\n    let parts = line.split(\":\");\n    if(parts.length != 2) continue;\n    let key = parts[0].trim();\n    let val = parts[1].trim();\n    if(key != \"SER\" && isNumeric(val)) val = Number(val)\n    result[key] = val;\n}\n\nmsg.payload = result;\nreturn msg;\n\nfunction isNumeric(n) {\n  return !isNaN(parseFloat(n)) && isFinite(n);\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1880,"y":140,"wires":[["26f9cb02d64e46be"]]},{"id":"26f9cb02d64e46be","type":"debug","z":"97f8641c.552078","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":2050,"y":140,"wires":[]}]

Flow Info

Created 3 years, 1 month ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • exec (x1)
  • function (x1)
  • inject (x1)

Tags

  • APCUPSD
  • APC
  • USV
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option