[Nut-upsdev] [PATCH 0/3] OpenUPS updates
rmk at armlinux.org.uk
Sun Feb 4 00:17:56 UTC 2018
I've been checking out NUT with an OpenUPS board over the last couple
of weekends, and have noticed that it doesn't seem to report sensible
values. This lead me to investigate usbhid-ups and delve into various
As mentioned in a github issue, one of the problems is with the report
descriptor - dumping this from the usbhid-ups debug output and picking
through it reveals that global items that are supposed to be attached
to main items appear after the corresponding main item, in violation of
the HID standard. This violation also means that the parser fails to
associate (eg) the correct logical min/max with the proper usages.
For instance, this means that the signed current value reported through
UPS.PowerSummary.Current is interpreted as unsigned.
Some other issues include no logical max/min before the first few
usages, which mean various items describing strings are clamped to zero,
causing the strings to be directed to string 0 rather than their
Also, the input current appeared to fall to zero when the battery was
fully charged, despite the UPS taking power from the input supply, and
the output current would change depending on whether the UPS was taking
power from the battery or from the input supply.
Being experienced with switch mode power supplies (to the point of
designing and building them) has allowed me to investigate what is
going on, and resolve these issues.
There is another issue which I haven't addressed yet, which is that
some of the current and voltage values appear to have a zero offset
error - the output voltage, for example, reads 80mV higher than it
actually is (as measured on the capacitors themselves) equivalent to
an error of 5. The effect of these errors, when combined, is to
inflate the power by about 5 to 10%. I've chosen not to fix this so
far as the coulomb counter is likely subject to the same error when
calculating the runtime.
The patches attached to this message:
1. Avoid reading non-feature usages. usbhid-ups does not request
input or output reports, it always uses the feature type for all
report requests. Asking for a report ID for an input or output
report (which is supposed to be done over the interrupt endpoints)
with a feature type may be responsible for the growing list of
driver specific workarounds...
2. Implement a generic method to replace the HID report descriptor.
3. Fix the reporting of input/output currents with openups.
I haven't supplied my replacement HID report descriptor with this set
of patches - my current way of editing this is as assembly, eg:
.byte 0x05, 0x84 // UsagePage(0x0084)
.byte 0x09, 0x04 // Usage(UPS)
.byte 0xa1, 0x01 // Collection(0x01)
.byte 0x09, 0x24 // Usage(PowerSummary)
.byte 0xa1, 0x00 // Collection(0x00)
assembling that, and the converting the result to binary:
gcc -c -o openups-hid.o openups-hid.S
objcopy -O binary openups-hid.o openups-hid.bin
and then using:
hid_descriptor = /etc/nut/openups-hid.bin
in the /etc/nut/ups.conf section. Thoughts on how to include this
More information about the Nut-upsdev