APC_MODBUS _apc_modbus_read_registers Timeouts
On an APC SMT1500C device using the rtu_usb version of libmodbus and a USB cable, reads fail with a timeout.
Since support for USB based APC Modbus is not mainlined, I am building the required RTU_USB version of libmodbus and compiling the main branch of NUT with usb and modbus support per the https://github.com/networkupstools/nut/wiki/APC-UPS-with-Modbus-protocol wiki page. The build appears to be successful but I am not able to at get the apc_modbus driver to communicate with the UPS.
I have attached build logs and included the apc_modbus output below. I have tested the connection using APC's PowerChute program (on a different system) and PowerChute is able to collect all of the ModBus only fields (like load and temperatures, etc). So I am fairly confident it is not a physical connection issue. Also when using the standard Debian bookworm build of NUT I am able to reliably communicate using the usbhid-ups driver but as it only provides a few fields, the Modbus driver is prefered.
Any pointers would be appreciated but I am not sure where to go from here.
NUT configuration indicating the new RTU USB features are included in the NUT build
checking for libmodbus version via pkg-config... 3.1.10 found
checking for libmodbus cflags... -I/usr/include/modbus
checking for libmodbus ldflags... -lmodbus
checking for modbus.h... yes
checking for modbus_new_rtu... yes
checking for modbus_new_tcp... yes
checking for modbus_set_byte_timeout... yes
checking for modbus_set_response_timeout... yes
checking for modbus_new_rtu_usb... yes
checking types of arguments for modbus_set_byte_timeout... sec_usec_uint32_cast_timeval_fields
Found types to use for modbus_set_byte_timeout: sec_usec_uint32_cast_timeval_fields
Using apc_modbus to probe the unit this is the output:
$ sudo ./apc_modbus -DDDDDD -s ups -x port=auto
0.000001 [D5] send_to_all: SETINFO driver.state "init.starting"
Network UPS Tools driver 2.8.2.989-989-g4bf05e115 (development iteration after 2.8.2) - NUT APC Modbus driver 0.10
0.000408 [D5] send_to_all: SETINFO driver.version.usb "libusb-1.0.26 (API: 0x1000109)"
0.000447 [D1] Using USB implementation: libusb-1.0.26 (API: 0x1000109)
0.000504 [D3] main_arg: var='port' val='auto'
0.000533 [D6] testinfo_reloadable: var=port, infoname=driver.parameter.port, newval=auto, reloadable=0, reload_flag=0
0.000561 [D6] testinfo_reloadable: verdict for (re)loading var=port value: 1
0.000604 [D5] send_to_all: SETINFO driver.parameter.port "auto"
0.000624 [D1] Network UPS Tools version 2.8.2.989-989-g4bf05e115 (development iteration after 2.8.2) built with gcc (Debian 12.2.0-14) 12.2.0 and configured with flags: --prefix=/usr --with-doc=no --with-drivers=apc_modbus,usbhid-ups --with-usb --with-modbus --sysconfdir=/etc/nut --includedir=/usr/include --mandir=/usr/share/man --libdir=/usr/lib/aarch64-linux-gnu --libexecdir=/usr/libexec --with-ssl --with-nss --with-cgi --with-dev --with-statepath=/run/nut --with-altpidpath=/run/nut --with-drvpath=/lib/nut --with-cgipath=/usr/lib/cgi-bin/nut --with-htmlpath=/usr/share/nut/www --with-pidpath=/run/nut --datadir=/usr/share/nut --with-pkgconfig-dir=/usr/lib/aarch64-linux-gnu/pkgconfig --with-user=nut --with-group=nut --with-udev-dir=/lib/udev --with-systemdsystemunitdir=/lib/systemd/system --with-systemdshutdowndir=/lib/systemd/system-shutdown --with-systemdtmpfilesdir=/usr/lib/tmpfiles.d
0.000695 [D1] debug level is '6'
0.000724 [D5] send_to_all: SETINFO driver.debug "6"
0.000754 [D5] send_to_all: SETFLAGS driver.debug RW NUMBER
0.001755 [D1] Succeeded to become_user(nut): now UID=106 GID=112
0.001830 [D1] Signalling UPS [ups]: driver.exit (quietly, no fuss if no driver is running or responding)
0.001900 Can't open /run/nut/apc_modbus-ups: No such file or directory
0.001938 [D1] Request for other driver to exit returned code -1
0.001967 [D1] Socket dialog with the other driver instance (may be absent) failed: No such file or directory
0.002003 [D5] send_to_all: SETINFO device.type "ups"
0.002034 [D5] send_to_all: SETINFO driver.state "init.device"
Number of USB devices: 5
Considering device #0 (051d:0003)
0.047244 [D2] _apc_modbus_usb_callback: Matched American Power Conversion Smart-UPS_1500 FW:UPS 15.5 / ID=1015 (USB VID/PID 051d:0003)
0.047332 [D2] _apc_modbus_usb_callback: Checking American Power Conversion Smart-UPS_1500 FW:UPS 15.5 / ID=1015 (USB VID/PID 051d:0003) report descriptors
0.048073 [D1] _apc_modbus_usb_callback: Found report ids RX=0x90 TX=0x89
0.048160 [D5] send_to_all: SETINFO ups.vendorid "051d"
0.048223 [D5] send_to_all: SETINFO ups.productid "0003"
Found Device 0 (Path 1-1.1.2):
Vendor ID: 0x051d
Product ID: 0x0003
Bytes flushed (0)
0.058556 [D5] send_to_all: SETINFO driver.state "init.quiet"
0.058602 [D5] send_to_all: SETINFO driver.version "2.8.2.989-989-g4bf05e115"
0.058623 [D5] send_to_all: SETINFO driver.version.internal "0.10"
0.058645 [D5] send_to_all: SETINFO driver.name "apc_modbus"
0.058663 [D5] send_to_all: SETINFO driver.state "init.info"
[01][03][02][04][00][78]
Waiting for a confirmation...
ERROR Connection timed out: select
0.567189 _apc_modbus_read_registers: Read of 516:636 failed: Connection timed out (auto)
Bytes flushed (0)
1.577519 Can't read inventory information from the UPS
1.577610 [D5] send_to_all: SETINFO driver.state "cleanup.upsdrv"
1.578214 [D5] send_to_all: SETINFO driver.state "cleanup.exit"
1.578280 upsnotify: notify about state 4 with libsystemd: was requested, but not running as a service unit now, will not spam more about it
1.578310 upsnotify: failed to notify about state 4: no notification tech defined, will not spam more about it
Host Details
* Hardware: Raspberry Pi 3B+
* OS: Raspberry Pi OS Lite (64-bit)
* Kernel version: 6.6
* Debian version: 12 (bookworm)
* uname: Linux rpi 6.6.31+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.31-1+rpt1 (2024-05-29) aarch64 GNU/Linux
ups.conf
[ups]
driver = "apc_modbus"
port = "auto"
upsd.conf
LISTEN 0.0.0.0 3493
nut.conf
MODE=netserver
Build command for libmodbus and NUT
build_libmodbus.sh
#!/bin/bash
if [ "$EUID" -ne 0 ]; then
echo -e "ERROR: Please run as root\n"
exit
fi
# Install dependencies
apt-get install -y \
autoconf libusb-1.0-0-dev libusb-dev git libtool gawk
# Build RTU USB Library
git clone -b rtu_usb https://github.com/networkupstools/libmodbus
cd libmodbus
./autogen.sh
export DEB_HOST_MULTIARCH=aarch64-linux-gnu
./configure \
--prefix=/usr \
--sysconfdir=/etc/nut \
--includedir=/usr/include \
--mandir=/usr/share/man \
--libdir=/usr/lib/${DEB_HOST_MULTIARCH} \
--libexecdir=/usr/libexec \
--with-libusb \
--enable-static \
--enable-shared \
--with-pkgconfig-dir=/usr/lib/${DEB_HOST_MULTIARCH}/pkgconfig
make -j4 && make install
build_nut.sh
#!/bin/bash
if [ "$EUID" -ne 0 ]; then
echo -e "ERROR: Please run as root\n"
exit
fi
# Install dependencies
apt-get install -y \
libssl-dev libnss3-dev libgd-dev augeas-tools \
libaugeas-dev augeas-lenses libcppunit-dev \
ccache time perl curl make autoconf automake \
libltdl-dev libtool cppcheck pkg-config gcc g++ \
clang valgrind libsystemd-dev
# Build NUT
git clone https://github.com/networkupstools/nut
cd nut
./autogen.sh
export DEB_HOST_MULTIARCH="aarch64-linux-gnu"
./configure \
--prefix=/usr \
--with-doc=no \
--with-drivers="apc_modbus,usbhid-ups" \
--with-usb \
--with-modbus \
--sysconfdir=/etc/nut \
--includedir=/usr/include \
--mandir=/usr/share/man \
--libdir=/usr/lib/${DEB_HOST_MULTIARCH} \
--libexecdir=/usr/libexec \
--with-ssl \
--with-nss \
--with-cgi \
--with-dev \
--with-statepath=/run/nut \
--with-altpidpath=/run/nut \
--with-drvpath=/lib/nut \
--with-cgipath=/usr/lib/cgi-bin/nut \
--with-htmlpath=/usr/share/nut/www \
--with-pidpath=/run/nut \
--datadir=/usr/share/nut \
--with-pkgconfig-dir=/usr/lib/${DEB_HOST_MULTIARCH}/pkgconfig \
--with-user=nut \
--with-group=nut \
--with-udev-dir=/lib/udev \
--with-systemdsystemunitdir=/lib/systemd/system \
--with-systemdshutdowndir=/lib/systemd/system-shutdown \
--with-systemdtmpfilesdir=/usr/lib/tmpfiles.d
make -j4
echo ""
read -p "Do you wish to continue? [Y/N] " yesno
case $yesno in
[Yy]* )
echo "Installing..."
;;
* )
echo "Exiting..."
exit
;;
esac
make install
CC @EchterAgo : does this ring any bells, please?
In an effort to rule out the RPi being a factor, I recreated the build on an x86 system with Ubuntu 24.04.1 which results in:
$ ./apc_modbus -DDDDDD -a ups -x port=auto
0.000001 [D5] send_to_all: SETINFO driver.state "init.starting"
Network UPS Tools driver 2.8.2.1004-1004-g38d8078ab (development iteration after 2.8.2) - NUT APC Modbus driver 0.10
0.000145 [D5] send_to_all: SETINFO driver.version.usb "libusb-1.0.27 (API: 0x100010a)"
0.000160 [D1] Using USB implementation: libusb-1.0.27 (API: 0x100010a)
0.000311 [D5] do_upsconf_args: confupsname=(null), var=maxretry, val=3
0.000316 [D5] do_upsconf_args: call do_global_args()
0.000319 [D3] do_global_args: var='maxretry' val='3'
0.000388 [D5] do_upsconf_args: confupsname=ups, var=driver, val=apc_modbus
0.000392 [D5] do_upsconf_args: call main_arg()
0.000396 [D3] main_arg: var='driver' val='apc_modbus'
0.000399 [D5] do_upsconf_args: not a main_arg()
0.000402 [D5] do_upsconf_args: this is a 'driver' setting, may we proceed?
0.000406 [D6] testval_reloadable: var=driver, oldval=apc_modbus, newval=apc_modbus, reloadable=0, reload_flag=0
0.000410 [D6] testval_reloadable: verdict for (re)loading var=driver value: -1
0.000413 [D5] do_upsconf_args: 'driver' setting already applied with this value
0.000417 [D5] do_upsconf_args: confupsname=ups, var=port, val=auto
0.000421 [D5] do_upsconf_args: call main_arg()
0.000424 [D3] main_arg: var='port' val='auto'
0.000428 [D6] testinfo_reloadable: var=port, infoname=driver.parameter.port, newval=auto, reloadable=0, reload_flag=0
0.000433 [D6] testinfo_reloadable: verdict for (re)loading var=port value: 1
0.000439 [D5] send_to_all: SETINFO driver.parameter.port "auto"
0.000449 [D3] main_arg: var='port' val='auto'
0.000453 [D6] testinfo_reloadable: var=port, infoname=driver.parameter.port, newval=auto, reloadable=0, reload_flag=0
0.000456 [D6] testinfo_reloadable: verdict for (re)loading var=port value: 1
0.000460 [D1] Network UPS Tools version 2.8.2.1004-1004-g38d8078ab (development iteration after 2.8.2) built with gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0 and configured with flags: --prefix=/usr --with-doc=no --with-drivers=apc_modbus,usbhid-ups --with-usb --with-modbus --sysconfdir=/etc/nut --includedir=/usr/include --mandir=/usr/share/man --libdir=/usr/lib/x86_64-linux-gnu --libexecdir=/usr/libexec --with-ssl --with-nss --with-cgi --with-dev --with-statepath=/run/nut --with-altpidpath=/run/nut --with-drvpath=/lib/nut --with-cgipath=/usr/lib/cgi-bin/nut --with-htmlpath=/usr/share/nut/www --with-pidpath=/run/nut --datadir=/usr/share/nut --with-pkgconfig-dir=/usr/lib/x86_64-linux-gnu/pkgconfig --with-user=nut --with-group=nut --with-udev-dir=/lib/udev --with-systemdsystemunitdir=/lib/systemd/system --with-systemdshutdowndir=/lib/systemd/system-shutdown --with-systemdtmpfilesdir=/usr/lib/tmpfiles.d
0.000484 [D1] debug level is '6'
0.000489 [D5] send_to_all: SETINFO driver.debug "6"
0.000495 [D5] send_to_all: SETFLAGS driver.debug RW NUMBER
0.001387 [D1] Succeeded to become_user(nut): now UID=110 GID=111
0.001413 [D1] Signalling UPS [ups]: driver.exit (quietly, no fuss if no driver is running or responding)
0.001425 Can't open /run/nut/apc_modbus-ups: No such file or directory
0.001430 [D1] Request for other driver to exit returned code -1
0.001434 [D1] Socket dialog with the other driver instance (may be absent) failed: No such file or directory
0.001440 [D5] send_to_all: SETINFO device.type "ups"
0.001444 [D5] send_to_all: SETINFO driver.state "init.device"
Number of USB devices: 3
Considering device #1 (051d:0003)
0.025093 [D2] _apc_modbus_usb_callback: Matched American Power Conversion Smart-UPS_1500 FW:UPS 15.5 / ID=1015 (USB VID/PID 051d:0003)
0.025120 [D2] _apc_modbus_usb_callback: Checking American Power Conversion Smart-UPS_1500 FW:UPS 15.5 / ID=1015 (USB VID/PID 051d:0003) report descriptors
0.025264 [D1] _apc_modbus_usb_callback: Found report ids RX=0x90 TX=0x89
0.025279 [D5] send_to_all: SETINFO ups.vendorid "051d"
0.025287 [D5] send_to_all: SETINFO ups.productid "0003"
Found Device 1 (Path 1-8):
Vendor ID: 0x051d
Product ID: 0x0003
Bytes flushed (63)
0.036922 [D5] send_to_all: SETINFO driver.state "init.quiet"
0.036947 [D5] send_to_all: SETINFO driver.version "2.8.2.1004-1004-g38d8078ab"
0.036966 [D5] send_to_all: SETINFO driver.version.internal "0.10"
0.036982 [D5] send_to_all: SETINFO driver.name "apc_modbus"
0.036995 [D5] send_to_all: SETINFO driver.state "init.info"
[01][03][02][04][00][78]
Waiting for a confirmation...
*** bit out of range 0 - FD_SETSIZE on fd_set ***: terminated
Aborted (core dumped)
$ ./upsdrvctl start
Network UPS Tools upsdrvctl - UPS driver controller 2.8.2.1004-1004-g38d8078ab (development iteration after 2.8.2)
Network UPS Tools driver 2.8.2.1004-1004-g38d8078ab (development iteration after 2.8.2) - NUT APC Modbus driver 0.10
*** bit out of range 0 - FD_SETSIZE on fd_set ***: terminated
Driver exited abnormally
Thanks for the diligence about multi-platform check. RPi's USB chips were also suspects a few times.
But the segfault was reported in several issues recently - so seeing it misbehave differently per platform is at least "most intriguing!" :)
CC @EchterAgo again
I might at best look at code in a couple of weeks or more, and have no similar APC device to check against.
@jimklimov Thanks for the reply. I will keep a look out for updates, let me know if there is anything you'd like me to try.
To add another device: I'm seeing a similar behavior using a Smart-UPS 750 running FW 9.3 on NUT 2.8.2 with libmodbus c02f62b58aa4ce7538e087ef46266d2a048b0bd6.
/lib64/nut/apc_modbus -DDDDDD -s ups -x port=auto
0.000000 [D5] send_to_all: SETINFO driver.state "init.starting"
Network UPS Tools - NUT APC Modbus driver 0.10 (2.8.2)
0.000105 [D5] send_to_all: SETINFO driver.version.usb "libusb-1.0.27 (API: 0x100010a)"
0.000114 [D1] Using USB implementation: libusb-1.0.27 (API: 0x100010a)
0.000128 [D3] main_arg: var='port' val='auto'
0.000135 [D6] testinfo_reloadable: var=port, infoname=driver.parameter.port, newval=auto, reloadable=0, reload_flag=0
0.000141 [D6] testinfo_reloadable: verdict for (re)loading var=port value: 1
0.000156 [D5] send_to_all: SETINFO driver.parameter.port "auto"
0.000162 [D1] Network UPS Tools version 2.8.2 (release/snapshot of 2.8.2) built with x86_64-pc-linux-gnu-gcc (Gentoo 13.3.1_p20240614 p17) 13.3.1 20240614 and configured with flags: --prefix=/usr --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc --localstatedir=/var/lib --datarootdir=/usr/share --disable-dependency-tracking --disable-silent-rules --disable-static --docdir=/usr/share/doc/nut-2.8.2-r1 --htmldir=/usr/share/doc/nut-2.8.2-r1/html --with-sysroot=/ --libdir=/usr/lib64 --datadir=/usr/share/nut --datarootdir=/usr/share/nut --disable-static --disable-strip --disable-Werror --sysconfdir=/etc/nut --with-dev --with-drvpath=/lib64/nut --with-group=nut --with-htmlpath=/usr/share/nut/html --with-logfacility=LOG_DAEMON --with-statepath=/var/lib/nut --with-systemdsystemunitdir=/lib/systemd/system --with-systemdtmpfilesdir=/usr/lib/tmpfiles.d --with-udev-dir=/lib/udev --with-user=nut --without-powerman --without-python --without-python2 --with-altpidpath=/run/nut --with-pidpath=/run/nut --with-usb --with-modbus --with-modbus-includes=-I/usr/local/include/modbus --with-modbus-libs='-L/usr/local/lib -lmodbus' --without-cgi --without-gpio --without-linux_i2c --without-freeipmi --without-ipmi --without-nut_monitor --without-pynut --without-serial --without-snmp --with-ssl --without-libsystemd --without-wrap --with-usb --without-neon --without-avahi --with-doc=man --without-python3
0.000197 [D1] debug level is '6'
0.000203 [D5] send_to_all: SETINFO driver.debug "6"
0.000210 [D5] send_to_all: SETFLAGS driver.debug RW NUMBER
0.000409 [D1] Succeeded to become_user(nut): now UID=84 GID=84
0.000433 [D5] send_to_all: SETINFO device.type "ups"
0.000440 [D5] send_to_all: SETINFO driver.state "init.device"
Number of USB devices: 25
Considering device #0 (9022:d483)
libusb_open for device #0 failed: Access denied (insufficient permissions)
Considering device #1 (1c4f:0002)
libusb_open for device #1 failed: Access denied (insufficient permissions)
Considering device #2 (10c4:ea60)
libusb_open for device #2 failed: Access denied (insufficient permissions)
Considering device #4 (10c4:ea60)
libusb_open for device #4 failed: Access denied (insufficient permissions)
Considering device #5 (1a40:0201)
libusb_open for device #5 failed: Access denied (insufficient permissions)
Considering device #6 (051d:0003)
0.026713 [D2] _apc_modbus_usb_callback: Matched American Power Conversion Smart-UPS 750 FW:UPS 09.3 / ID=18 (USB VID/PID 051d:0003)
0.026745 [D2] _apc_modbus_usb_callback: Checking American Power Conversion Smart-UPS 750 FW:UPS 09.3 / ID=18 (USB VID/PID 051d:0003) report descriptors
0.026906 [D1] _apc_modbus_usb_callback: Found report ids RX=0x90 TX=0x89
0.026926 [D5] send_to_all: SETINFO ups.vendorid "051d"
0.026945 [D5] send_to_all: SETINFO ups.productid "0003"
Found Device 6 (Path 12-1):
Vendor ID: 0x051d
Product ID: 0x0003
Bytes flushed (63)
0.047954 [D5] send_to_all: SETINFO driver.state "init.quiet"
0.047967 [D5] send_to_all: SETINFO driver.version "2.8.2"
0.047975 [D5] send_to_all: SETINFO driver.version.internal "0.10"
0.047981 [D5] send_to_all: SETINFO driver.name "apc_modbus"
0.047997 [D5] send_to_all: SETINFO driver.state "init.info"
[01][03][02][04][00][78]
Waiting for a confirmation...
*** bit out of range 0 - FD_SETSIZE on fd_set ***: terminated
UPDATE: Seems like a practical duplicate of #2289
To summarize current findings in one place, we see several similar patterns ending up in driver crash (typically with bit out of range 0 - FD_SETSIZE on fd_set or buffer overflow detected), or a graceful exit (with ERROR Connection timed out: select; not sure if _apc_modbus_read_registers ... timed out cases are all in the same bucket):
- https://github.com/networkupstools/nut/issues/2609#issue-2499677698 - on Raspberry Pi 3B+ 64-bit build (Pi-OS lite based on Debian 12 bookworm)
...
0.058663 [D5] send_to_all: SETINFO driver.state "init.info"
[01][03][02][04][00][78]
Waiting for a confirmation...
ERROR Connection timed out: select
0.567189 _apc_modbus_read_registers: Read of 516:636 failed: Connection timed out (auto)
Bytes flushed (0)
1.577519 Can't read inventory information from the UPS
1.577610 [D5] send_to_all: SETINFO driver.state "cleanup.upsdrv"
1.578214 [D5] send_to_all: SETINFO driver.state "cleanup.exit"
- https://github.com/networkupstools/nut/issues/2609#issuecomment-2323657557 - same device as above, on an x86 system with Ubuntu 24.04.1:
...
0.036995 [D5] send_to_all: SETINFO driver.state "init.info"
[01][03][02][04][00][78]
Waiting for a confirmation...
*** bit out of range 0 - FD_SETSIZE on fd_set ***: terminated
Aborted (core dumped)
- https://github.com/networkupstools/nut/pull/2063#issuecomment-1905299561
Network UPS Tools - UPS driver controller 2.8.1
Network UPS Tools - NUT APC Modbus driver 0.01 (2.8.1)
*** buffer overflow detected ***: terminated
Driver exited abnormally
** Notably, Jan 23 05:00:27 nut kernel: [ 250.593376] usb 2-1: usbfs: process 918 (apc_modbus) did not claim interface 0 before use
- https://github.com/networkupstools/nut/issues/2289#issue-2104336348
...
0.050384 [D5] send_to_all: SETINFO driver.state "init.info"
[01][03][02][04][00][58]
Waiting for a confirmation...
*** buffer overflow detected ***: terminated
Aborted
- https://github.com/networkupstools/nut/issues/2289#issuecomment-2310851725
...
0.040156 [D5] send_to_all: SETINFO driver.state "init.info"
[01][03][02][04][00][78]
Waiting for a confirmation...
*** bit out of range 0 - FD_SETSIZE on fd_set ***: terminated
Aborted (core dumped)
- https://github.com/networkupstools/nut/issues/2289#issuecomment-2313515279
...
5.438365 [D5] send_to_all: SETINFO driver.state "init.info"
[01][03][02][04][00][78]
Waiting for a confirmation...
***** buffer overflow detected *: terminated
Aborted
Separately from this (maybe... seems similar to first sample above), in the later after-party discussion of original PR #2063 there were at least occasional (fixed by cable re-plug) faults with:
Network UPS Tools - UPS driver controller 2.8.1
Network UPS Tools - NUT APC Modbus driver 0.01 (2.8.1)
_apc_modbus_read_registers: Read of 516:604 failed: Connection timed out (auto)
Can't read inventory information from the UPS
And also an strace log was posted at https://gist.github.com/ZerglingGo/1cc0d27ae30e26d4000d674b0f7da6ec with the end-game part looking like below, and notably exposing Resource temporarily unavailable which might be relevant (especially vs. the piece above about cable re-plugging helping for a while):
...
407494 18:43:17.850107 write(2, " 0.215807\t[D5] send_to_all: SE"..., 63) = 63 <0.000024>
407494 18:43:17.850202 write(1, "[01][03][02][04][00][78]\n", 25) = 25 <0.000026>
407494 18:43:17.850293 ioctl(8, USBDEVFS_SUBMITURB, 0x5ff638237f70) = 0 <0.000031>
407494 18:43:17.850382 poll([{fd=4, events=POLLIN}, {fd=5, events=POLLIN}, {fd=8, events=POLLOUT}], 3, 60000) = 1 ([{fd=8, revents=POLLOUT}]) <0.004183>
407494 18:43:17.854644 ioctl(8, USBDEVFS_REAPURBNDELAY, 0x7fffd7dcecd0) = 0 <0.000029>
407494 18:43:17.854738 ioctl(8, USBDEVFS_REAPURBNDELAY, 0x7fffd7dcecd0) = -1 EAGAIN (Resource temporarily unavailable) <0.000027>
407494 18:43:17.854834 write(1, "Waiting for a confirmation...\n", 30) = 30 <0.000033>
407494 18:43:17.854944 writev(2, [{iov_base="*** ", iov_len=4}, {iov_base="bit out of range 0 - FD_SETSIZE "..., iov_len=41}, {iov_base=" ***: terminated\n", iov_len=17}], 3) = 62 <0.000030>
407494 18:43:17.855054 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7771af1f4000 <0.000034>
407494 18:43:17.855161 rt_sigprocmask(SIG_UNBLOCK, [ABRT], NULL, 8) = 0 <0.000024>
...
The Waiting for a confirmation line and what I think are byte dumps after it come from libmodbus (if modbus_set_debug() was enabled), src/modbus.c::_modbus_receive_msg() which indeed does FD_SET soon after the message:
- https://github.com/networkupstools/libmodbus/blob/c02f62b58aa4ce7538e087ef46266d2a048b0bd6/src/modbus.c#L363-L380
I suppose a run with gdb or similar would be helpful to identify the line at which it actually crashes - is it in FD_SET or in some later loop? Note that FD_SET() is probably a macro, and probably defined differently depending on architecture, e.g. here are some hits from the systems I could look at quickly:
:; grep -rw FD_SET /usr/include/
...
/usr/include/aarch64-linux-gnu/sys/select.h:#define FD_SET(fd, fdsetp) __FD_SET (fd, fdsetp)
/usr/include/x86_64-linux-gnu/sys/select.h:#define FD_SET(fd, fdsetp) __FD_SET (fd, fdsetp)
...
:; grep -rw -A5 __FD_SET /usr/include/
...
usr/include/aarch64-linux-gnu/bits/select.h:#define __FD_SET(d, s) \
/usr/include/aarch64-linux-gnu/bits/select.h- ((void) (__FDS_BITS (s)[__FD_ELT(d)] |= __FD_MASK(d)))
...
/usr/include/x86_64-linux-gnu/bits/select.h:#define __FD_SET(d, s) \
/usr/include/x86_64-linux-gnu/bits/select.h- ((void) (__FDS_BITS (s)[__FD_ELT(d)] |= __FD_MASK(d)))
...
There are other FD macros nearby, all defined in terms of access to __FDS_BITS (s)[] array - hence the likely overflow if that array is too small for the offset number that lands into it as an index.
https://stackoverflow.com/questions/22827510/how-to-avoid-bad-fd-set-buffer-overflow-crash suggests there are problems with 1000+ socket/FD numbers, and also reminds to check if there are FD leaks (loops with a FD not closed so another number gets opened and issued for some next operation).
Another question is what ctx->s is in FD_SET(ctx->s, &rset); expression, my random guess is it might be mis-populated in the new code for libmodbus rtu_usb branch?..
CC @EchterAgo
I suppose ctx->s is initialized to -1 in _modbus_init_common() and remains that way. At least, I do not see any calls to modbus_set_socket() or direct access to the field in src/modbus-rtu-usb.c.
That's about all I can say for now, lacking a device to test against, time (gotta run in fact), etc.
But I really hope the data-dig above can get someone started!
@jimklimov I can provide you with system. If you want, Please send me a mail.
@ZerglingGo : thanks I will, but first...
@ all : were all those attempts done with the proper NUT setup, drivers running unprivileged by default?
That "Resource temporarily unavailable" clue above bothers me since I saw it yesterday. Can you please try running the driver as root (with -x root option if running on command line, or user=root in its ups.conf section)?
The hypothesis I'm trying to check here is if permissions for nut or ups etc. account to use the devfs node for that USB device did not get set up correctly, so the driver does not succeed (fully?) opening the device, does not abort either, and gets into some sort of undefined state (e.g. polling 0 open/responding file descriptors or something).
In the debug dumps posted earlier I see _apc_modbus_usb_callback lines with apparently device details, but maybe it is something cached by the OS USB handler (name/model/version) and not reliant on access to the actual device from the driver program.
I guess that should be -u root and not -x root? If so: Same output. https://gist.github.com/adlerweb/8803c7c4c088a62b4036f4179f0c246b
Sorry, yes. Thought about -x user=root then edited and lost a bit :D
https://gist.github.com/ZerglingGo/1cc0d27ae30e26d4000d674b0f7da6ec#file-strace_apc_modbus-log-2
Here it is running result with -u root
I was able to replicate the issue with the latest code in git. What can we do to push this forward?
Thanks
What can we do to push this forward?
Generally speaking, and ideally -- have someone with the device and the basic programming/debugging skills run the NUT driver through a debugger...
- I was earlier able to wrangle NetBeans and VSCode into wrapping GDB to step through drivers, etc.
- If there is a core dump produced by the failed program (creation of such files may be forbidden in modern OSes by default), you can try to load it into
gdband at least print out the call stack trace, to make sure which methods and lines are the problematic code path. Similarly if the program fails while running undergdb, may not be constrained by permissions to create a core file as such.
These clues can help a lot with the guesswork about what went wrong. My two primary suspect areas would be new code in the driver or in libmodbus, possibly their interactions with further libraries like libusb.
I haven't finished my read through the changes, but it seems there are two variants of modbus+usb init (in lib changes, and one of those is used by the driver): one way has libmodbus use the USB devfs path, and another gets a libusb context like NUT drivers do (so some USB codepath here might end up with a socket or not - still figuring out between other weekend chores).
I think I'll provisionally try to post a variant of libmodbus code that would check if "s" (socket) field is invalid and skip trying to select on it. If you'd be able to build NUT against that and see if it behaves better - that would be great.
@jimklimov, that is great. Yes, please do let us know when your variant is ready and I can test in in my setup.
For now I got stuck on this, wanted to reproduce the fault locally (without an APC UPS, just poking a random USB-Serial converter and faking successes in libmodbus), but it behaves sanely and does not segfault even though ctx->s==-1 :\
In any case, per https://stackoverflow.com/a/69786982/4715872 we should check for, and avoid, using -1 value here (gotta check how skipping this method in case of libusb backend plays with libmodbus native logic):
An fd_set is a fixed size buffer. Executing FD_CLR() or FD_SET() with a value of fd that is negative or is equal to or larger than FD_SETSIZE will result in undefined behavior. Moreover, POSIX requires fd to be a valid file descriptor.
Just in case, do your devices also present as a serial port (e.g. /dev/ttyUSB0)? That might work differently as a serial Modbus RTU.
An alternative experiment could be to hack around apc_modbus.c and use the second connection method from the library (usb but for paths).
Cheers all! I've got a moment to look at this again.
The "second connection method" won't help, they converge to same logic.
I've tried a couple of fixes in libmodbus fork:
- do not
select()onctx->sof it is invalid, but do all the rest of the receiving method - try to get polling file descriptors from libusb context, and if there's exactly one returned, use it as
ctx->s
As I have nowhere to actually test this change, can you please build that branch https://github.com/jimklimov/libmodbus/tree/issue-nut-2609 , and then NUT against the resulting library (instructions mentioned above)?
:; git clone https://github.com/jimklimov/libmodbus -b issue-nut-2609 libmodbus-issue-nut-2609
:; cd libmodbus-issue-nut-2609
:; ./autogen.sh
:; ./configure --enable-static --disable-shared ...
I'm getting this error:
./apc_modbus: symbol lookup error: ./apc_modbus: undefined symbol: modbus_new_rtu_usb
@moritzkraemer : That's odd. Seems your driver got built with the dynamic linking to libmodbus.so and finds the one in the OS first. Did you follow https://github.com/networkupstools/nut/wiki/APC-UPS-with-Modbus-protocol to use the static library specifically to avoid such mishaps?
Alternately, fudge your LD_LIBRARY_PATH when testing the built driver and list the location of custom libmodbus*.so first, e.g.:
:; LD_LIBRARY_PATH="/path/to/prefix/lib:$LD_LIBRARY_PATH" ./drivers/apc_modbus -DDDDDD -d1 -s test -x port=auto
it seems to work now:
0.000008 [D5] send_to_all: SETINFO driver.state "init.starting"
Network UPS Tools 2.8.2.1877-1877-ge7788b97d (development iteration after 2.8.2) - NUT APC Modbus driver with USB support 0.11
0.000110 [D5] send_to_all: SETINFO driver.version.usb "libusb-1.0.27 (API: 0x0100010A)"
0.000126 [D1] Using USB implementation: libusb-1.0.27 (API: 0x0100010A)
0.000139 [D1] This build of the driver is USB-capable; also Serial and TCP Modbus RTU are supported
0.000166 [D3] main_arg: var='port' val='auto'
0.000203 [D6] testinfo_reloadable: var=port, infoname=driver.parameter.port, newval=auto, reloadable=0, reload_flag=0
0.000225 [D6] testinfo_reloadable: verdict for (re)loading var=port value: 1
0.000242 [D5] send_to_all: SETINFO driver.parameter.port "auto"
0.000254 [D1] Network UPS Tools version 2.8.2.1877-1877-ge7788b97d (development iteration after 2.8.2) built with gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 and configured with flags: --prefix=/usr --with-doc=no --with-drivers=apc_modbus,usbhid-ups --with-usb --with-modbus --sysconfdir=/etc/nut --includedir=/usr/include --mandir=/usr/share/man --libdir=/usr/lib/aarch64-linux-gnu --libexecdir=/usr/libexec --with-ssl --with-nss --with-cgi --with-dev --with-statepath=/run/nut --with-altpidpath=/run/nut --with-drvpath=/lib/nut --with-cgipath=/usr/lib/cgi-bin/nut --with-htmlpath=/usr/share/nut/www --with-pidpath=/run/nut --datadir=/usr/share/nut --with-pkgconfig-dir=/usr/lib/aarch64-linux-gnu/pkgconfig --with-user=nut --with-group=nut --with-udev-dir=/lib/udev --with-systemdsystemunitdir=/lib/systemd/system --with-systemdshutdowndir=/lib/systemd/system-shutdown --with-systemdtmpfilesdir=/usr/lib/tmpfiles.d
0.000350 [D1] debug level is '6'
0.000366 [D5] send_to_all: SETINFO driver.debug "6"
0.000379 [D5] send_to_all: SETFLAGS driver.debug RW NUMBER
0.002457 [D1] Succeeded to become_user(nut): now UID=110 GID=111
0.002489 [D1] Signalling UPS [test]: driver.exit (quietly, no fuss if no driver is running or responding)
0.002518 Can't open /run/nut/apc_modbus-test: No such file or directory
0.002532 [D1] Request for other driver to exit returned code -1
0.002547 [D1] Socket dialog with the other driver instance (may be absent) failed: No such file or directory
0.002564 [D5] send_to_all: SETINFO device.type "ups"
0.002585 [D5] send_to_all: SETINFO driver.state "init.device"
Number of USB devices: 4
Considering device #1 (8087:0aaa)
libusb_open for device #1 failed: Access denied (insufficient permissions)
Considering device #2 (051d:0003)
0.044408 [D2] _apc_modbus_usb_callback: Matched American Power Conversion Smart-UPS_1500 FW:UPS 18.0 / ID=1027 (USB VID/PID 051d:0003)
0.044444 [D2] _apc_modbus_usb_callback: Checking American Power Conversion Smart-UPS_1500 FW:UPS 18.0 / ID=1027 (USB VID/PID 051d:0003) report descriptors
0.044671 [D1] _apc_modbus_usb_callback: Found report ids RX=0x90 TX=0x89
0.044693 [D5] send_to_all: SETINFO ups.vendorid "051d"
0.044708 [D5] send_to_all: SETINFO ups.productid "0003"
Found Device 2 (Path 1-4):
Vendor ID: 0x051d
Product ID: 0x0003
Got a list of 3 libusb file descriptors to pollBytes flushed (0)
0.054991 [D5] send_to_all: SETINFO driver.state "init.quiet"
0.055012 [D5] send_to_all: SETINFO driver.version "2.8.2.1877-1877-ge7788b97d"
0.055031 [D5] send_to_all: SETINFO driver.version.internal "0.11"
0.055049 [D5] send_to_all: SETINFO driver.name "apc_modbus"
0.055066 [D5] send_to_all: SETINFO driver.state "init.info"
[01][03][02][04][00][78]
Waiting for a confirmation...
Using a backend without a file descriptor, will not select() on it.
ERROR Connection timed out: select
<01><03><F0><55><50><53><20><31><38><2E><30><00><00><00><00><00><00><00><00><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><53><6D><61><72><74><2D><55><50><53><20><31><35><30><30><20><20><20><20><20><20><20><20><20><20><20><20><20><20><20><20><20><20><53><4D><54><31><35><30><30><52><4D><49><32><55><43><20><20><20><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><41><53><32><33><31><33><33><35><31><35><37><36><20><20><20><20><41><50><43><52><42><43><31><35><39><20><20><20><20><20><20><20><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><05><DC><03><E8><00><03><21><29><00><20><00><00><00><00><21><7A><41><50><43><20><55><50><53><20><20><20><20><20><20><20><20><20><55><6E><73><77><69><74><63><68><65><64><20><47><72><6F><75><70><4F><75><74><6C><65><74><20><47><72><6F><75><70><20><31><20><20><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00>
1.056350 [D5] send_to_all: SETINFO outlet.group.count "2"
1.056506 [D5] send_to_all: SETINFO ups.firmware "UPS 18.0"
1.056578 [D5] send_to_all: SETFLAGS ups.firmware STRING
1.056802 [D5] send_to_all: SETAUX ups.firmware 16
1.056840 [D5] send_to_all: SETINFO ups.model "Smart-UPS 1500"
1.056868 [D5] send_to_all: SETFLAGS ups.model STRING
1.056897 [D5] send_to_all: SETAUX ups.model 32
1.056931 [D5] send_to_all: SETINFO ups.serial "ASxxx"
1.056966 [D5] send_to_all: SETFLAGS ups.serial STRING
1.056999 [D5] send_to_all: SETAUX ups.serial 16
1.057038 [D5] send_to_all: SETINFO ups.power.nominal "1500"
1.057081 [D5] send_to_all: SETINFO ups.realpower.nominal "1000"
1.057282 [D5] send_to_all: SETINFO ups.mfr.date "2023-03-30"
1.057325 [D5] send_to_all: SETINFO battery.date "2023-06-19"
1.057354 [D5] send_to_all: SETFLAGS battery.date RW
1.057391 [D5] send_to_all: SETINFO ups.id "APC UPS"
1.057425 [D5] send_to_all: SETFLAGS ups.id RW STRING
1.057473 [D5] send_to_all: SETAUX ups.id 16
1.057511 [D5] send_to_all: SETINFO outlet.group.0.name "Unswitched Group"
1.057549 [D5] send_to_all: SETFLAGS outlet.group.0.name RW STRING
1.057583 [D5] send_to_all: SETAUX outlet.group.0.name 16
1.057645 [D5] send_to_all: SETINFO outlet.group.1.name "Outlet Group 1"
1.057680 [D5] send_to_all: SETFLAGS outlet.group.1.name RW STRING
1.057714 [D5] send_to_all: SETAUX outlet.group.1.name 16
1.057751 [D5] send_to_all: SETINFO outlet.group.2.name ""
1.057786 [D5] send_to_all: SETFLAGS outlet.group.2.name RW STRING
1.057817 [D5] send_to_all: SETAUX outlet.group.2.name 16
1.057849 [D5] send_to_all: SETINFO outlet.group.3.name ""
1.057887 [D5] send_to_all: SETFLAGS outlet.group.3.name RW STRING
1.057921 [D5] send_to_all: SETAUX outlet.group.3.name 16
1.057960 [D5] send_to_all: SETINFO ups.mfr "American Power Conversion"
1.057995 [D5] send_to_all: ADDCMD test.battery.start
1.058025 [D5] send_to_all: ADDCMD test.battery.stop
1.058060 [D5] send_to_all: ADDCMD test.panel.start
1.058094 [D5] send_to_all: ADDCMD calibrate.start
1.058127 [D5] send_to_all: ADDCMD calibrate.stop
1.058159 [D5] send_to_all: ADDCMD bypass.start
1.058192 [D5] send_to_all: ADDCMD bypass.stop
1.058226 [D5] send_to_all: ADDCMD beeper.mute
1.058255 [D5] send_to_all: ADDCMD load.off
1.058287 [D5] send_to_all: ADDCMD load.on
1.058334 [D5] send_to_all: ADDCMD load.off.delay
1.058371 [D5] send_to_all: ADDCMD load.on.delay
1.058405 [D5] send_to_all: ADDCMD shutdown.return
1.058439 [D5] send_to_all: ADDCMD shutdown.stayoff
1.058470 [D5] send_to_all: ADDCMD shutdown.reboot
1.058499 [D5] send_to_all: ADDCMD shutdown.reboot.graceful
1.058545 [D5] send_to_all: ADDCMD outlet.0.shutdown.return
1.058580 [D5] send_to_all: ADDCMD outlet.0.load.off
1.058634 [D5] send_to_all: ADDCMD outlet.0.load.on
1.058670 [D5] send_to_all: ADDCMD outlet.0.load.cycle
1.058704 [D5] send_to_all: ADDCMD outlet.1.shutdown.return
1.058737 [D5] send_to_all: ADDCMD outlet.1.load.off
1.058782 [D5] send_to_all: ADDCMD outlet.1.load.on
1.058818 [D5] send_to_all: ADDCMD outlet.1.load.cycle
1.058848 [D5] send_to_all: ADDCMD outlet.2.shutdown.return
1.058892 [D5] send_to_all: ADDCMD outlet.2.load.off
1.058926 [D5] send_to_all: ADDCMD outlet.2.load.on
1.058961 [D5] send_to_all: ADDCMD outlet.2.load.cycle
1.058995 [D5] send_to_all: ADDCMD outlet.3.shutdown.return
1.059029 [D5] send_to_all: ADDCMD outlet.3.load.off
1.059063 [D5] send_to_all: ADDCMD outlet.3.load.on
1.059097 [D5] send_to_all: ADDCMD outlet.3.load.cycle
1.059133 [D5] send_to_all: ADDCMD shutdown.default
1.059166 [D5] send_to_all: SETINFO driver.state "init.updateinfo"
[01][03][00][00][00][1B]
Waiting for a confirmation...
Using a backend without a file descriptor, will not select() on it.
ERROR Connection timed out: select
<01><03><36><00><00><20><02><00><08><00><00><00><01><00><02><00><00><00><01><00><02><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><84><00><00><00><01><00><00>
3.064250 [D5] send_to_all: SETINFO input.transfer.reason "AcceptableInput"
3.064330 [D5] send_to_all: SETINFO ups.test.result "Passed, Source: LocalUI"
[01][03][00][80][00][20]
Waiting for a confirmation...
Using a backend without a file descriptor, will not select() on it.
ERROR Connection timed out: select
<01><03><40><00><00><0B><C9><C8><00><03><39><FF><FF><26><A9><FF><FF><0F><24><1A><CC><FF><FF><1F><E5><FF><FF><00><42><FF><FF><3A><05><FF><FF><19><00><00><1E><AB><E3><00><00><FF><FF><FF><FF><00><01><3A><07><FF><FF><FF><FF><30><8E><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF>
4.064257 [D5] send_to_all: SETINFO battery.runtime "3017"
4.064407 [D5] send_to_all: SETINFO battery.charge "100.00"
4.064508 [D5] send_to_all: SETINFO battery.voltage "25.78"
4.064552 [D5] send_to_all: SETINFO battery.date.maintenance "2027-02-05"
4.064595 [D5] send_to_all: SETINFO battery.temperature "30.28"
4.064669 [D5] send_to_all: SETINFO ups.load "26.80"
4.064712 [D5] send_to_all: SETINFO ups.realpower "267.97"
4.064753 [D5] send_to_all: SETINFO ups.power "478.42"
4.064789 [D5] send_to_all: SETINFO output.current "2.06"
4.064830 [D5] send_to_all: SETINFO output.voltage "232.08"
4.064872 [D5] send_to_all: SETINFO output.frequency "50.00"
4.064911 [D5] send_to_all: SETINFO experimental.output.energy "2010083"
4.064953 [D5] send_to_all: SETINFO input.voltage "232.11"
4.064996 [D5] send_to_all: SETINFO ups.efficiency "97.1"
4.065032 [D5] send_to_all: SETINFO ups.timer.shutdown "-1"
4.065067 [D5] send_to_all: SETINFO ups.timer.start "-1"
4.065101 [D5] send_to_all: SETINFO ups.timer.reboot "-1"
[01][03][04][02][00][16]
Waiting for a confirmation...
Using a backend without a file descriptor, will not select() on it.
ERROR Connection timed out: select
<01><03><2C><00><FD><00><CF><00><01><00><00><00><00><00><00><00><08><00><00><00><5A><00><00><00><00><00><08><00><00><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF>
5.064248 [D5] send_to_all: SETINFO input.transfer.high "253"
5.064336 [D5] send_to_all: SETFLAGS input.transfer.high RW
5.064396 [D5] send_to_all: SETINFO input.transfer.low "207"
5.064449 [D5] send_to_all: SETFLAGS input.transfer.low RW
5.064487 [D5] send_to_all: SETINFO ups.delay.shutdown "0"
5.064521 [D5] send_to_all: SETFLAGS ups.delay.shutdown RW
5.064558 [D5] send_to_all: SETINFO ups.delay.start "0"
5.064592 [D5] send_to_all: SETFLAGS ups.delay.start RW
5.064673 [D5] send_to_all: SETINFO ups.delay.reboot "8"
5.064709 [D5] send_to_all: SETFLAGS ups.delay.reboot RW
5.064742 [D5] send_to_all: SETINFO outlet.group.0.delay.shutdown "0"
5.064776 [D5] send_to_all: SETFLAGS outlet.group.0.delay.shutdown RW
5.064823 [D5] send_to_all: SETINFO outlet.group.0.delay.start "0"
5.064854 [D5] send_to_all: SETFLAGS outlet.group.0.delay.start RW
5.064893 [D5] send_to_all: SETINFO outlet.group.0.delay.reboot "8"
5.064928 [D5] send_to_all: SETFLAGS outlet.group.0.delay.reboot RW
5.064966 [D5] send_to_all: SETINFO outlet.group.1.delay.shutdown "90"
5.065001 [D5] send_to_all: SETFLAGS outlet.group.1.delay.shutdown RW
5.065040 [D5] send_to_all: SETINFO outlet.group.1.delay.start "0"
5.065075 [D5] send_to_all: SETFLAGS outlet.group.1.delay.start RW
5.065113 [D5] send_to_all: SETINFO outlet.group.1.delay.reboot "8"
5.065146 [D5] send_to_all: SETFLAGS outlet.group.1.delay.reboot RW
5.065179 [D5] send_to_all: SETINFO outlet.group.2.delay.shutdown "-1"
5.065215 [D5] send_to_all: SETFLAGS outlet.group.2.delay.shutdown RW
5.065253 [D5] send_to_all: SETINFO outlet.group.2.delay.start "-1"
5.065290 [D5] send_to_all: SETFLAGS outlet.group.2.delay.start RW
5.065329 [D5] send_to_all: SETINFO outlet.group.2.delay.reboot "-1"
5.065359 [D5] send_to_all: SETFLAGS outlet.group.2.delay.reboot RW
5.065392 [D5] send_to_all: SETINFO outlet.group.3.delay.shutdown "-1"
5.065424 [D5] send_to_all: SETFLAGS outlet.group.3.delay.shutdown RW
5.065509 [D5] send_to_all: SETINFO outlet.group.3.delay.start "-1"
5.065546 [D5] send_to_all: SETFLAGS outlet.group.3.delay.start RW
5.065582 [D5] send_to_all: SETINFO outlet.group.3.delay.reboot "-1"
5.065639 [D5] send_to_all: SETFLAGS outlet.group.3.delay.reboot RW
5.065679 [D5] send_to_all: SETINFO ups.status "OL HE"
5.065711 [D5] send_to_all: DATAOK
5.065746 [D5] send_to_all: SETINFO driver.state "init.quiet"
5.065792 [D5] send_to_all: SETINFO driver.parameter.pollinterval "2"
5.065828 [D5] send_to_all: SETINFO driver.parameter.synchronous "auto"
5.065869 [D5] send_to_all: SETINFO device.mfr "American Power Conversion"
5.065908 [D5] send_to_all: SETINFO device.model "Smart-UPS 1500"
5.065947 [D5] send_to_all: SETINFO device.serial "ASxxx"
5.065977 Running as foreground process, not saving a PID file
5.066014 [D5] send_to_all: SETINFO driver.flag.allow_killpower "0"
5.066048 [D5] send_to_all: SETFLAGS driver.flag.allow_killpower RW NUMBER
5.066084 [D5] send_to_all: ADDCMD driver.killpower
5.066118 [D5] send_to_all: ADDCMD driver.reload
5.066153 [D5] send_to_all: ADDCMD driver.reload-or-exit
5.066187 [D5] send_to_all: ADDCMD driver.reload-or-error
5.066219 [D5] send_to_all: SETINFO driver.state "quiet"
5.066251 [D1] Driver initialization completed, beginning data dump (1 loops)
5.066286 [D5] send_to_all: SETINFO driver.state "updateinfo"
[01][03][00][00][00][1B]
Waiting for a confirmation...
Using a backend without a file descriptor, will not select() on it.
ERROR Connection timed out: select
<01><03><36><00><00><20><02><00><08><00><00><00><01><00><02><00><00><00><01><00><02><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><84><00><00><00><01><00><00>
[01][03][00][80][00][20]
Waiting for a confirmation...
Using a backend without a file descriptor, will not select() on it.
ERROR Connection timed out: select
<01><03><40><00><00><0B><C5><C8><00><03><39><FF><FF><26><A9><FF><FF><0F><25><1A><B7><FF><FF><1F><E1><FF><FF><00><41><FF><FF><3A><0C><FF><FF><19><00><00><1E><AB><E3><00><00><FF><FF><FF><FF><00><01><3A><0C><FF><FF><FF><FF><30><8F><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF>
7.072239 [D5] send_to_all: SETINFO battery.runtime "3013"
7.072332 [D5] send_to_all: SETINFO battery.temperature "30.29"
7.072418 [D5] send_to_all: SETINFO ups.load "26.71"
7.072478 [D5] send_to_all: SETINFO ups.realpower "267.15"
7.072571 [D5] send_to_all: SETINFO ups.power "478.18"
7.072696 [D5] send_to_all: SETINFO output.current "2.03"
7.072736 [D5] send_to_all: SETINFO output.voltage "232.19"
7.072779 [D5] send_to_all: SETINFO input.voltage "232.19"
[01][03][04][02][00][16]
Waiting for a confirmation...
Using a backend without a file descriptor, will not select() on it.
ERROR Connection timed out: select
<01><03><2C><00><FD><00><CF><00><01><00><00><00><00><00><00><00><08><00><00><00><5A><00><00><00><00><00><08><00><00><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF>
11.080303 [D5] send_to_all: SETINFO driver.state "quiet"
11.080376 [D5] send_to_all: SETINFO driver.state "updateinfo"
[01][03][00][00][00][1B]
Waiting for a confirmation...
Using a backend without a file descriptor, will not select() on it.
ERROR Connection timed out: select
<01><03><36><00><00><20><02><00><08><00><00><00><01><00><02><00><00><00><01><00><02><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><00><84><00><00><00><01><00><00>
[01][03][00][80][00][20]
Waiting for a confirmation...
Using a backend without a file descriptor, will not select() on it.
ERROR Connection timed out: select
<01><03><40><00><00><0B><CC><C8><00><03><39><FF><FF><26><A9><FF><FF><0F><28><1A><CA><FF><FF><1F><EA><FF><FF><00><41><FF><FF><3A><09><FF><FF><19><00><00><1E><AB><E3><00><00><FF><FF><FF><FF><00><01><3A><09><FF><FF><FF><FF><30><8D><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF>
13.080262 [D5] send_to_all: SETINFO battery.runtime "3020"
13.080371 [D5] send_to_all: SETINFO battery.temperature "30.31"
13.080431 [D5] send_to_all: SETINFO ups.load "26.79"
13.080468 [D5] send_to_all: SETINFO ups.realpower "267.89"
13.080528 [D5] send_to_all: SETINFO ups.power "478.71"
13.080676 [D5] send_to_all: SETINFO output.voltage "232.14"
13.080744 [D5] send_to_all: SETINFO input.voltage "232.14"
[01][03][04][02][00][16]
Waiting for a confirmation...
Using a backend without a file descriptor, will not select() on it.
ERROR Connection timed out: select
<01><03><2C><00><FD><00><CF><00><01><00><00><00><00><00><00><00><08><00><00><00><5A><00><00><00><00><00><08><00><00><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF>
14.088326 [D5] send_to_all: SETINFO driver.state "quiet"
14.088392 [D5] send_to_all: SETINFO driver.state "dumping"
14.088458 [D3] Entering dstate_dump
battery.charge: 100.00
battery.date: 2023-06-19
battery.date.maintenance: 2027-02-05
battery.runtime: 3020
battery.temperature: 30.31
battery.voltage: 25.78
device.mfr: American Power Conversion
device.model: Smart-UPS 1500
device.serial: ASxxxx
device.type: ups
driver.debug: 6
driver.flag.allow_killpower: 0
driver.name: apc_modbus
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.synchronous: auto
driver.state: dumping
driver.version: 2.8.2.1877-1877-ge7788b97d
driver.version.internal: 0.11
driver.version.usb: libusb-1.0.27 (API: 0x0100010A)
experimental.output.energy: 2010083
input.transfer.high: 253
input.transfer.low: 207
input.transfer.reason: AcceptableInput
input.voltage: 232.14
outlet.group.0.delay.reboot: 8
outlet.group.0.delay.shutdown: 0
outlet.group.0.delay.start: 0
outlet.group.0.name: Unswitched Group
outlet.group.1.delay.reboot: 8
outlet.group.1.delay.shutdown: 90
outlet.group.1.delay.start: 0
outlet.group.1.name: Outlet Group 1
outlet.group.2.delay.reboot: -1
outlet.group.2.delay.shutdown: -1
outlet.group.2.delay.start: -1
outlet.group.2.name:
outlet.group.3.delay.reboot: -1
outlet.group.3.delay.shutdown: -1
outlet.group.3.delay.start: -1
outlet.group.3.name:
outlet.group.count: 2
output.current: 2.03
output.frequency: 50.00
output.voltage: 232.14
ups.delay.reboot: 8
ups.delay.shutdown: 0
ups.delay.start: 0
ups.efficiency: 97.1
ups.firmware: UPS 18.0
ups.id: APC UPS
ups.load: 26.79
ups.mfr: American Power Conversion
ups.mfr.date: 2023-03-30
ups.model: Smart-UPS 1500
ups.power: 478.71
ups.power.nominal: 1500
ups.productid: 0003
ups.realpower: 267.89
ups.realpower.nominal: 1000
ups.serial: ASxxx
ups.status: OL HE
ups.test.result: Passed, Source: LocalUI
ups.timer.reboot: -1
ups.timer.shutdown: -1
ups.timer.start: -1
ups.vendorid: 051d
14.089881 [D5] send_to_all: SETINFO driver.state "cleanup.upsdrv"
14.090455 [D5] send_to_all: SETINFO driver.state "cleanup.exit"
Looks great, thanks for testing!
@moritzkraemer : hello again, may I ask you to also check if bringing in the newer upstream code per https://github.com/jimklimov/libmodbus/tree/bump-libmodbus-3.1.11 also still works for our RTU USB devices?
:; git clone https://github.com/jimklimov/libmodbus -b bump-libmodbus-3.1.11 libmodbus-rtu_usb-3.1.11
:; cd libmodbus-rtu_usb-3.1.11
:; ./autogen.sh
:; ./configure --with-libusb --prefix=/path/to/prefix --enable-static --disable-shared
:; make -j 4 && make install
Looks good!
@moritzkraemer : meaning, also passed and collected the info and did not crash? Thanks :)
@moritzkraemer : I believe you've also had a use-case for Modbus TCP with APC in #2757? Does the updated library+driver work for that setup as well?
@moritzkraemer : meaning, also passed and collected the info and did not crash? Thanks :)
Yes, one information thats missing for my usecase is the last time the selftest passed but i guess that information isnt available by the ups?
@moritzkraemer : I believe you've also had a use-case for Modbus TCP with APC in #2757? Does the updated library+driver work for that setup as well?
Yes