APC UPS with Modbus protocol - networkupstools/nut GitHub Wiki
Since about 2010, many APC devices have largely deprecated the use of standard USB HID protocol in favor of a ModBus based one, which they can use over other media (Serial, TCP/IP) as well. Lack of support for the new protocol in NUT was a sore point for years, see issue #139 and generally the labelled issues and PRs via https://github.com/networkupstools/nut/issues?q=label%3AAPC+label%3Amodbus query.
But as of PR #2063 with initial read-only handling support (and some linked issues and PRs before and after it) such support did appear in NUT release v2.8.1 and is still expanding (e.g. for commands and writable variables with PR #2184 added to NUT v2.8.2 or later releases).
One caveat here is that the work with modbus from NUT relies on libmodbus
, and the upstream project currently lacks the USB layer support. The author of PR #2063 linked above did implement it in https://github.com/EchterAgo/libmodbus/commits/rtu_usb (PR pending CLA acceptance in upstream) with instructions to build the custom libmodbus
and then build NUT against it detailed in the PR #2063. A replica is retained in https://github.com/networkupstools/libmodbus/tree/rtu_usb fork.
Adapting the instructions from that PR and the later issue #2348:
To install the patched
libmodbus
, you need to get the code and install it into a prefix somewhere (e.g./usr/local
to not overlap with possible system-provided packages under/usr
):cd ~/ git clone -b rtu_usb https://github.com/networkupstools/libmodbus cd libmodbus ./autogen.sh ./configure --with-libusb --prefix=/path/to/prefix make install
NOTES:
- you may need to
make && sudo make install
if you want to place this library variant into a system path; perhaps/usr/local/ups
to match NUT isolated defaults, not in your home directory).- conversely, you may want to
./configure --with-libusb --enable-static --disable-shared --prefix=/path/to/prefix
and only build and install a staticlibmodbus.a
(can well be into/tmp
or similar location) so the custom modbus logic gets built directly intoapc_modbus
binary and there would be no conflict with a dynamic library file available elsewhere in the systemTo compile NUT you need something like this:
cd ~/ git clone https://github.com/networkupstools/nut cd nut ./autogen.sh ./configure --with-drivers=apc_modbus --with-usb --with-modbus \ --with-modbus-includes=-I/path/to/prefix/include/modbus \ --with-modbus-libs="-L/path/to/prefix/lib -lmodbus" make
- See also Building NUT for in‐place upgrades or non‐disruptive tests page for general suggestions on custom NUT builds (and links to prerequisites for different platforms), and how to test if the custom driver works for you without installing it first into your system.
With an "out of the box" libmodbus
(without that rtu_usb
change), the APC devices using the protocol over Serial and TCP/IP links should "just work" with the new apc_modbus
NUT driver.