Here is an example flow that reads data from an APC UPS (Uninterruptible Power Supply). These are commonly used to keep PC's and servers powered up during short power outages and to allow them to gracefully shut down.
In this case, I have a low-cost APC UPS connected via a USB cable to the Raspberry Pi that is running Node-RED and a Mosquitto MQTT broker.
To get the latest data from the UPS, we are using a command-line Linux tool called apcaccess
. This is part of apcupsd which you should be able to install directly from your distribution's software library.
There are 2 function nodes included in the flow. One that isn't wired in, that converts the text output from the tool into an object on the payload containing properties for everything returned by the query. The second one, that is in use, is very similar but throws out a new message for each property using topics that correspond roughly to the homie MQTT topic structure. Homie is similar to a revised topic structure I'd come up with myself so it seemed to make sense to use it. However, I find the full convention rather restrictive and overly complex - so I keep it close rather than fully compliant.
We also create two additional outputs. One tells MQTT whether we consider the UPS to be online (it is talking to the Pi), the other provides an updated timestamp.
The RBE node is used to minimise the number of messages being sent to MQTT - only values that have changed (by topic) will actually be sent.
The output from the flow should be sent to your MQTT broker using an MQTT-Out node.