[Nut-upsdev] What is the arduino sub-driver intended to be used for?

Kelly Byrd kbyrd at memcpy.com
Sun Nov 12 21:45:53 GMT 2023


I posted earlier on this list about getting an Arduino Pro Micro using
https://github.com/abratchik/HIDPowerDevice in a simple sketch to monitor a
DIY UPS I have built. With the changes from that thread (I had a PR
merged), I was able to get usbhid-ups to recognize my device and could
setup NUT the rest of the way. My intended configuration is to run NUT on a
Raspberry Pi, have that device be master and then have clients of that NUT
install take action when ACPresent goes from true to false.

The problem I ran into is  `upsc diyups at locahost` was always showing
ups.status as "OB". I ran tests and confirmed the raw reports
included "UPS.PowerSummary.PresentStatus.ACPresent correctly showing 1 and
0 as appropriate as well as correctly reporting the
UPS.PowerSummary.PresentStatus.Charging
and UPS.PowerSummary.PresentStatus.Discharging bitfields.

I traced the problem down to drivers/arduino.c. Apparently the Arduino
subdriver doesn't have an entry
for "UPS.PowerSummary.PresentStatus.ACPresent" in it's arduino_hid2nut[]
definition. The only sections present are commented as:
/* USB HID PDC defaults */

I my local source tree, I made changes to these entries copied from another
USB HID-based subdriver, to add:
        /* USB HID UPS Status*/
        {"BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Charging", NULL,
NULL, HU_FLAG_QUICK_POLL, charging_info},
        {"BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Discharging", NULL,
NULL, HU_FLAG_QUICK_POLL, discharging_info},
        {"BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.NeedReplacement",
NULL, NULL, 0, replacebatt_info},
        {"BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ACPresent", NULL,
NULL, HU_FLAG_QUICK_POLL, online_info},

and now everything works as expected! My question for this list is why
there were not included in the Arduino subdriver already? AFAICT, the
author of the HIDPowerDevice Arduino library added the Arduino subdriver
via a PR a few years ago along with basic support for the common Arduino
VID:PID combinations in other parts of the code. But, that same library
definitely reports more than
UPS.PowerSummary.DelayBeforeShutdown, UPS.PowerSummary.DelayBeforeStartup,
etc.
and the example code he gives primarily  demonstrates how to report
ACPresent, Charging, and also remaining run time.

Am I missing something? Is there a runtime config based way to instruct NUT
how to map ACPresent, Charging, etc HID statuses to NUT's specific
structure? Over on the GitHub for the other project, others have reported
success with NUT and Arduinos using that library, but I don't know what
"success" means to them. I can't see how it's actually useful without the
addition of the above lines. I'm probably missing the original intent.

Any insight or advice is appreciated. If I'm on the right track, I'll do
another PR to add the above status flags (and others you all think are
important) to Arduino.c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/nut-upsdev/attachments/20231112/0cbf4c34/attachment.htm>


More information about the Nut-upsdev mailing list