Re: [Nut-upsuser] There is no voltage information

2024-03-25 Thread Jim Klimov via Nut-upsuser
Hello all,

  I think I've found the "regression" in Belkin/Liebert USB HID support
which worked for NUT v2.7.4 and reports zero voltages in 2.8.0 -- it was
actually caused by a bug fix: practically the only functional difference
per `git diff v2.7.4..v2.8.0 drivers/belkin-hid.c` is a change from `abs()`
to `fabs()` in order-of-magnitude comparisons like `if( abs(value - 1e-7) <
1e-9 ) {...}` which feel odd on their own, discussed in
https://github.com/networkupstools/nut/issues/2370

  The old code worked because `abs()` is for `int` numbers, and the
miniscule argument became an always-zero after casting (which is less than
`10^-9`), and for existing devices it just happened to be the correct
codepath to pick an exponent for USB readings. The new code made the
comparisons mathematically correct, to work on `double` precision numbers
using `fabs()` (to not confuse with `fabsf()` for `float` types, go
figure). And boom! Something no longer clicks for `1.39e-06 => 13.9V` and
`2.206e-05 => 220V` (with correction factor `1e7`).

  Obligatory inspiring motivator : https://xkcd.com/1172/

  Thanks to Mr. Fischer for the right logs (and version-dissection
findings) at the right time :)

Jim Klimov


On Mon, Mar 25, 2024 at 7:41 AM Juan Carlos Fischer <
juancarlos.fisc...@gmail.com> wrote:

> Hello Jim!
> First of all, allow me to thank you for your time and invaluable help.
> Exactly arm v7l  are 32 bit. I will conduct several tests and keep you
> informed.
>
> On the other hand this is what I got
> pi@raspberrypi:~ $ sudo /lib/nut/usbhid-ups -DD -a Liebert
>0.00 [D3] do_global_args: var='maxretry' val='3'
>0.001309 [D3] do_global_args: var='user' val='nut'
>0.001604 [D1] Overriding previously specified user 'nut' with 'nut'
> specified in global section
>0.002196 [D3] main_arg: var='driver' val='usbhid-ups'
>0.002280 [D3] main_arg: var='port' val='auto'
>0.002360 [D5] send_to_all: SETINFO driver.parameter.port "auto"
>0.006042 [D3] main_arg: var='vendorid' val='10AF'
>0.006172 [D5] send_to_all: SETINFO driver.parameter.vendorid "10AF"
>0.006402 [D3] main_arg: var='productid' val='0001'
>0.006490 [D5] send_to_all: SETINFO driver.parameter.productid "0001"
>0.006563 [D3] main_arg: var='bus' val='001'
>0.006646 [D5] send_to_all: SETINFO driver.parameter.bus "001"
>0.006720 [D3] main_arg: var='desc' val='PSA UPS'
>0.006792 [D3] main_arg: var='pollinterval' val='15'
>0.006980 [D1] debug level is '6'
>0.009706 [D5] send_to_all: SETINFO device.type "ups"
>0.009873 [D2] Initializing an USB-connected UPS with library
> libusb-1.0.26 (API: 0x1000109) (NUT subdriver name='USB communication
> driver (libusb 1.0)' ver='0.43')
>0.009942 [D1] upsdrv_initups (non-SHUT)...
>0.064656 [D2] Checking device 1 of 12 (2109/0813)
>0.064792 [D1] Failed to open device (2109/0813), skipping: Access
> denied (insufficient permissions)
>0.064851 [D2] Checking device 2 of 12 (1058/2620)
>0.064956 [D1] Failed to open device (1058/2620), skipping: Access
> denied (insufficient permissions)
>0.065018 [D2] Checking device 3 of 12 (2109/0813)
>0.065074 [D1] Failed to open device (2109/0813), skipping: Access
> denied (insufficient permissions)
>0.065122 [D2] Checking device 4 of 12 (1D6B/0003)
>0.065171 [D1] Failed to open device (1D6B/0003), skipping: Access
> denied (insufficient permissions)
>0.065240 [D2] Checking device 5 of 12 (045E/00F5)
>0.065275 [D1] Failed to open device (045E/00F5), skipping: Access
> denied (insufficient permissions)
>0.065308 [D2] Checking device 6 of 12 (10AF/0001)
>0.077166 [D2] - VendorID: 10af
>0.077216 [D2] - ProductID: 0001
>0.077277 [D2] - Manufacturer: Emerson Network Power
>0.077332 [D2] - Product: LiebertPSA
>0.077372 [D2] - Serial Number:
>0.077391 [D2] - Bus: 001
>0.077427 [D2] - Device: unknown
>0.077481 [D2] - Device release number: 0014
>0.077560 [D2] Trying to match device
>0.077600 [D2] match_function_subdriver (non-SHUT mode): matching a
> device...
>0.077664 [D3] match_function_regex: matching a device...
>0.077905 [D2] Device matches
>0.077972 [D2] Reading first configuration descriptor
>0.078055 [D3] libusb_kernel_driver_active() returned 0
>0.078099 [D2] failed to claim USB device: Resource busy
>0.078159 [D2] Kernel driver already detached
>0.078199 [D2] failed to claim USB device: Resource busy
>0.078260 [D2] Kernel driver already detached
>0.078317 [D2] failed to claim USB device: Resource busy
>0.078379 [D2] Kernel driver already detached
>0.078439 [D2] failed to claim USB device: Resource busy
>0.078496 [D2] Kernel driver already detached
>0.078534 Can't claim USB device [10af:0001]@0/0: Entity not found
>
> The same for 2.74. has an endless output.
> I rescue the following
>0.278176 Path: UPS.Input.Voltage, Type: Feature, ReportID: 0x20,
> Offset: 0, Size: 16, Value: 2.201e

Re: [Nut-upsuser] There is no voltage information

2024-03-25 Thread Jim Klimov via Nut-upsuser
Hi,

  FYI: I'll be away from computers (and possibly internet) for a couple of
weeks.

  As for the logs, they are not "the same": the first one (with NUT 2.8.x)
failed to connect to the device it liked -- "failed to claim USB device:
Resource busy" (probably another program holds it, maybe a copy of the
driver wrapped by a systemd unit - see
https://github.com/networkupstools/nut/wiki/nut%E2%80%90driver%E2%80%90enumerator-(NDE)
for probable-cause details).

  The "endless output" makes sense as the driver is running in an infinite
loop (until an exit signal) to collect and publish device information :)

  Logged strings like "assuming correction factor" in the latter (2.7.4)
indicate it goes through drivers/belkin-hid.c which had some attention for
a newly seen strain of Liebert devices just recently with:
* https://github.com/networkupstools/nut/pull/2369
* https://github.com/networkupstools/nut/issues/2271
* https://github.com/networkupstools/nut/issues/2370 - thanks for the log,
it would be helpful here specifically

  You might want to give a shot to a custom master-branch build to see if
it works better with these changes, see
https://github.com/networkupstools/nut/wiki/Building-NUT-for-in%E2%80%90place-upgrades-or-non%E2%80%90disruptive-tests
- or wait for eventual release and some time later packaging of NUT 2.8.2...

Hope this helps,
Jim Klimov



On Mon, Mar 25, 2024 at 7:41 AM Juan Carlos Fischer <
juancarlos.fisc...@gmail.com> wrote:

> Hello Jim!
> First of all, allow me to thank you for your time and invaluable help.
> Exactly arm v7l  are 32 bit. I will conduct several tests and keep you
> informed.
>
> On the other hand this is what I got
> pi@raspberrypi:~ $ sudo /lib/nut/usbhid-ups -DD -a Liebert
>0.00 [D3] do_global_args: var='maxretry' val='3'
>0.001309 [D3] do_global_args: var='user' val='nut'
>0.001604 [D1] Overriding previously specified user 'nut' with 'nut'
> specified in global section
>0.002196 [D3] main_arg: var='driver' val='usbhid-ups'
>0.002280 [D3] main_arg: var='port' val='auto'
>0.002360 [D5] send_to_all: SETINFO driver.parameter.port "auto"
>0.006042 [D3] main_arg: var='vendorid' val='10AF'
>0.006172 [D5] send_to_all: SETINFO driver.parameter.vendorid "10AF"
>0.006402 [D3] main_arg: var='productid' val='0001'
>0.006490 [D5] send_to_all: SETINFO driver.parameter.productid "0001"
>0.006563 [D3] main_arg: var='bus' val='001'
>0.006646 [D5] send_to_all: SETINFO driver.parameter.bus "001"
>0.006720 [D3] main_arg: var='desc' val='PSA UPS'
>0.006792 [D3] main_arg: var='pollinterval' val='15'
>0.006980 [D1] debug level is '6'
>0.009706 [D5] send_to_all: SETINFO device.type "ups"
>0.009873 [D2] Initializing an USB-connected UPS with library
> libusb-1.0.26 (API: 0x1000109) (NUT subdriver name='USB communication
> driver (libusb 1.0)' ver='0.43')
>0.009942 [D1] upsdrv_initups (non-SHUT)...
>0.064656 [D2] Checking device 1 of 12 (2109/0813)
>0.064792 [D1] Failed to open device (2109/0813), skipping: Access
> denied (insufficient permissions)
>0.064851 [D2] Checking device 2 of 12 (1058/2620)
>0.064956 [D1] Failed to open device (1058/2620), skipping: Access
> denied (insufficient permissions)
>0.065018 [D2] Checking device 3 of 12 (2109/0813)
>0.065074 [D1] Failed to open device (2109/0813), skipping: Access
> denied (insufficient permissions)
>0.065122 [D2] Checking device 4 of 12 (1D6B/0003)
>0.065171 [D1] Failed to open device (1D6B/0003), skipping: Access
> denied (insufficient permissions)
>0.065240 [D2] Checking device 5 of 12 (045E/00F5)
>0.065275 [D1] Failed to open device (045E/00F5), skipping: Access
> denied (insufficient permissions)
>0.065308 [D2] Checking device 6 of 12 (10AF/0001)
>0.077166 [D2] - VendorID: 10af
>0.077216 [D2] - ProductID: 0001
>0.077277 [D2] - Manufacturer: Emerson Network Power
>0.077332 [D2] - Product: LiebertPSA
>0.077372 [D2] - Serial Number:
>0.077391 [D2] - Bus: 001
>0.077427 [D2] - Device: unknown
>0.077481 [D2] - Device release number: 0014
>0.077560 [D2] Trying to match device
>0.077600 [D2] match_function_subdriver (non-SHUT mode): matching a
> device...
>0.077664 [D3] match_function_regex: matching a device...
>0.077905 [D2] Device matches
>0.077972 [D2] Reading first configuration descriptor
>0.078055 [D3] libusb_kernel_driver_active() returned 0
>0.078099 [D2] failed to claim USB device: Resource busy
>0.078159 [D2] Kernel driver already detached
>0.078199 [D2] failed to claim USB device: Resource busy
>0.078260 [D2] Kernel driver already detached
>0.078317 [D2] failed to claim USB device: Resource busy
>0.078379 [D2] Kernel driver already detached
>0.078439 [D2] failed to claim USB device: Resource busy
>0.078496 [D2] Kernel driver already detached
>0.078534 Can't claim USB device [10af:0001]@0/0: Entity not found
>
> The s