Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communicating with NUCUPS, but voltages and currents reported as zero #1

Open
adamcandy opened this issue Oct 21, 2020 · 13 comments
Open

Comments

@adamcandy
Copy link

Hi @nicupavel and @mini-box,
Fantastic to have a Linux tool to talk with the mini-box UPSs - good job! I have built and tested. It looks to be communicating with the UPS fine, but has a few issues reading some of the data, such as voltage and current (see logs below). This is possibly connected to the hid_interrupt_read failed with return code -110 error reported but the usb library.
Have tried running with root user and also made sure to stop NUT and processes that might have locked access to the USB interface. (in fact this cleared the error interface 0 already claimed by driver "usbfs", attempting to detach it I saw initially.)
Is there anything you can suggest we try to correct this?
Thank you for your help.
Cheers,
Adam

$ openups -t nucups -s
Device selected: nucups
Selected device nucups: DC-DC NUC UPS
Found and initialized hid device:
Product: DCDC-NUC UPS, Manufacturer: MINI-BOX.COM, Firmware Version: (null)
hid_interrupt_read failed with return code -110
Read error: -110
hid_interrupt_read failed with return code -110
Read error: -110
 Input: 0
 Output: 0
 Charger Flags: 11521
 State Flags: 0
 Shutdown Flags: 0
 VIn: 0.000000
 IOut: 0.000000
 VOut:0.000000
 VIgnition: 0.000000
 POut: 0.000000
 Temperature1: 0.000000
 Temperature2: 0.000000
 Temperature3: 0.000000
 Temperature4: 0.000000
 BatVoltage1: 3.851000
  BatVoltage2: 3.850000
 BatVoltage3: 3.852000
 BatVoltage4: 3.850000
 CellBalanceOn1: 0
 CellBalanceOn2: 0
 CellBalanceOn3: 0
 CellBalanceOn4: 0
 CellDetected1: 1
 CellDetected2: 1
 CellDetected3: 1
 CellDetected4: 1
 BatOverallVoltage: 15.404000
 BatPack: 18.174999
 IChgDchg: 0.000000
 VerMajor: 0
 VerMinor: 0
 State: 0
 ChargeEndedCondition: 3
 BatteryLevel: 99
 Mode: 0
 CPUUsage: 0
Read configuration
failed to release interface: 0

$ lsusb
...
Bus 001 Device 008: ID 04d8:d007 Microchip Technology, Inc. 
...

@adamcandy
Copy link
Author

The above is on a NUCUPS. I have tried the same on an OpenUPS and see the same zero voltage and current reported.
On the same machine, running the Windows version of the software in a virtual machine reports the voltages and currents correctly. (this also reports fine when the nut drivers are also access the data from the usb interface.)

@nicupavel
Copy link
Collaborator

nicupavel commented Oct 22, 2020

Did you run the command with sudo ? Are you using a 3.0 or 2.0 port ? Also you can try to replug in the USB port and rerun command with sudo.
Also you should check system log/dmesg maybe apparmor/selinux blocks the access ?
Try sudo snap connect openups:raw-usb

@adamcandy
Copy link
Author

Hi @nicupavel, thank you very much for the quick reply with suggestions. Sorry it has taken a while to test and get back to you. On all the systems tested, USB 2 ports are used and I had been trying with sudo and the root account in the above.

I have made progress through following your suggestions:
After:

  • Disabling all nut daemons running (that could be attempting to access the same USB device)
  • Disconnecting and reconnecting the USB port
    Running
    sudo ./openups -s -t openups
    I see:
Device selected: openups
Selected device openups: Open UPS
interface 0 already claimed by driver "usbhid", attempting to detach it
usb_detach_kernel_driver_np returned 0
Found and initialized hid device:
Product: OPEN-UPS, Manufacturer: Mini-Box.Com, Firmware Version: PBSO4-LiFePO
VIN: 19.497499
 VBat: 23.147570
 VOut: 19.873831 
 CCharge: 0.000000
Temperature: 40.000000
 VCell1: 3.865070
 VCell2: 3.856500
 VCell3: 3.865070
CDischarge: 0.000000
 VerMajor: 1
 VerMinor: 4
State: 2
 Capacity: 100
RTE: 65535
Read configuration

So the new code has successfully read the current state, reporting input and output voltages -- great news!

A few points:

  • Repeating the command gives the old error though:
sudo ./openups -s -t openups
Device selected: openups
Selected device openups: Open UPS
Found and initialized hid device:
Product: OPEN-UPS, Manufacturer: Mini-Box.Com, Firmware Version: PBSO4-LiFePO
hid_interrupt_read failed with return code -110
Read error: -110
hid_interrupt_read failed with return code -110
Read error: -110
VIN: 0.000000
 VBat: 0.000000
 VOut: 0.000000 
 CCharge: 0.000000
Temperature: 0.000000
 VCell1: 0.000000
 VCell2: 0.000000
 VCell3: 0.000000
CDischarge: 0.000000
 VerMajor: 0
 VerMinor: 0
State: 0
 Capacity: 100
RTE: 65535
Read configuration
failed to release interface: 0

Is the code -- after the first run -- not releasing the interface? I checked that the nut daemons and ups drives had not been started up in the background. Any further attempts to run after the first give the same errors.

Here's the dmesg:

[6683043.982907] ... old messages ...
[6948113.004580] usb 1-3.2.1: usbfs: process 16357 (usbhid-ups) did not claim interface 0 before use
[6948121.010486] usb 1-3.2.1: usbfs: process 16357 (usbhid-ups) did not claim interface 0 before use
[6948206.210886] usb 1-3.2.1: USB disconnect, device number 7
[6948225.122652] usb 1-3.2.1: new full-speed USB device number 10 using xhci_hcd
[6948225.225809] usb 1-3.2.1: New USB device found, idVendor=04d8, idProduct=d004
[6948225.225816] usb 1-3.2.1: New USB device strings: Mfr=1, Product=2, SerialNumber=4
[6948225.225820] usb 1-3.2.1: Product: OPEN-UPS
[6948225.225824] usb 1-3.2.1: Manufacturer: Mini-Box.Com
[6948225.225828] usb 1-3.2.1: SerialNumber: PBSO4-LiFePO
[6948225.235425] hid (null): invalid report_size 248
[6948225.238877] hid (null): invalid report_size 248
[6948225.242216] hid (null): invalid report_size 248
[6948225.245547] hid (null): invalid report_size 248
[6948225.248843] hid (null): invalid report_size 248
[6948225.252093] hid (null): invalid report_size 248
[6948225.255294] hid (null): invalid report_size 248
[6948225.258106] hid (null): invalid report_size 248
[6948225.260899] hid (null): invalid report_size 248
[6948225.263654] hid (null): invalid report_size 248
[6948225.266377] hid (null): invalid report_size 248
[6948225.269110] hid (null): invalid report_size 248
[6948225.272118] hid (null): invalid report_size 248
[6948225.275073] hid (null): invalid report_size 248
[6948225.277938] hid (null): invalid report_size 248
[6948225.280805] hid (null): invalid report_size 248
[6948225.284764] hid-generic 0003:04D8:D004.0004: invalid report_size 248
[6948225.287548] hid-generic 0003:04D8:D004.0004: item 0 1 1 7 parsing failed
[6948225.290301] hid-generic: probe of 0003:04D8:D004.0004 failed with error -22

Nothing is reported to syslog during these attempts.

It also only reports voltages from 3 of the 6 cells -- is this correct behaviour?
This is a full output of the configuration:

sudo ./openups -t openups
Device selected: openups
Selected device openups: Open UPS
Found and initialized hid device:
Product: OPEN-UPS, Manufacturer: Mini-Box.Com, Firmware Version: PBSO4-LiFePO
hid_interrupt_read failed with return code -110
Read error: -110
hid_interrupt_read failed with return code -110
Read error: -110
VIN: 0.000000
 VBat: 0.000000
 VOut: 0.000000 
 CCharge: 0.000000
Temperature: 0.000000
 VCell1: 0.000000
 VCell2: 0.000000
 VCell3: 0.000000
CDischarge: 0.000000
 VerMajor: 0
 VerMinor: 0
State: 0
 Capacity: 100
RTE: 65535
Read configuration
OPENUPSMODE=0
CAPACITY=6000
CELLS=6
MOB_ONOFF_TOUT=500
UPS_CONFIG=11111111
UPS_CONFIG2=00000000
UPS_INIT_DELAY_TOUT=1
UPS_VIN_MAX_SHUTDOWN=34.989151
UPS_VIN_MIN_START=10.989500
UPS_VIN_MIN_STOP=20
UPS_VCELL_MIN_START=3.402290
UPS_VCELL_MIN_STOP=3.102340
UPS_VBAT_UVP_OFF_TOUT=5
UPS_HARDOFF_TOUT=5
UPS_VBAT_SLEEP_TOUT=Never
UPS_SWITCHOVER_VBAT_TOUT=1000
UPS_SWITCHOVER_VIN_TOUT=1
DCHG_IMAX=9990.059570
CHG_ICOND=397.152008
CHG_VCOND=3.196610
CHG_TCOND=30
CHG_IBULK=1005.291016
CHG_BULK_STOP_VOLTAGE=4.096460
CHG_HYSTERESIS=0.102840
CHG_IMIN=248.220001
CHG_GLOBAL_TOUT=1080
CHG_IFLOAT=99.288002
CHG_TOPPING_TIMER=1800
CHG_START_VOLTAGE=3.702240
CHG_BAT_TYPE=2
CHG_TEMP_PCB=60
CHG_TEMP_PCB_LOW=125
CHG_ILIMIT_TEMP_PCB=49.644001
CHG_FREQUENCY=35
BAL_VCELL_MIN=3.496560
BAL_VCELL_DIFF_START=0.068560
BAL_VCELL_DIFF_STOP=0.034280
OUT_VOLTAGE=20.140000
OUT_FREQUENCY=39
OUT_MAX_REGULATOR_STEP=100
POUT_LO=2.00
POUT_HI=6.00
OCV_SOC0=3.599400
OCV_SOC10=3.650820
OCV_SOC25=3.770800
OCV_SOC50=3.899350
OCV_SOC75=4.002190
OCV_SOC100=4.199300
WRITE COUNT=3
failed to release interface: 0

It would be great to be able to use this to change the config (which I currently do through a virtual machine running the windows software). The main use right now is to monitor power, voltage and current. It is reporting CCharge and CDischarge. Is it possible to report input and/or output current (to the UPS and out to the powered device)?
Thanks again for your help with this. It is exciting to see linux development and support for these great modules.
Thanks,
Adam

@nicupavel
Copy link
Collaborator

I'm investigating this, it's related to a shorter than expected (for some devices) timeout value.

@nicupavel
Copy link
Collaborator

Please check latest version (0.6) from master.

@adamcandy
Copy link
Author

Hi @nicupavel, thanks for taking a look at this. I have just quickly pulled the update and rebuilt.
Trying this off the bat:

$ sudo ./openups -t openups -s
Device selected: openups
Selected device openups: Open UPS
interface 0 already claimed by driver "usbfs", attempting to detach it
usb_detach_kernel_driver_np returned 0
Product: OPEN-UPS, Manufacturer: Mini-Box.Com, Firmware Version: PBSO4-LiFePO
hid_interrupt_read failed with return code -110
Read error [0x70]: -110
hid_interrupt_read failed with return code -110
Read error [0x70]: -110
VIN: 0.000000
 VBat: 0.000000
 VOut: 0.000000 
 CCharge: 0.000000
Temperature: 0.000000
 VCell1: 0.000000
 VCell2: 0.000000
 VCell3: 0.000000
CDischarge: 0.000000
 VerMajor: 0
 VerMinor: 0
State: 0
 Capacity: 100
RTE: 65535

Then after stopping all nut daemons running:

$ sudo ./openups -t openups -s
Device selected: openups
Selected device openups: Open UPS
Product: OPEN-UPS, Manufacturer: Mini-Box.Com, Firmware Version: PBSO4-LiFePO
hid_interrupt_read failed with return code -110
Read error [0x70]: -110
hid_interrupt_read failed with return code -110
Read error [0x70]: -110
VIN: 0.000000
 VBat: 0.000000
 VOut: 0.000000 
 CCharge: 0.000000
Temperature: 0.000000
 VCell1: 0.000000
 VCell2: 0.000000
 VCell3: 0.000000
CDischarge: 0.000000
 VerMajor: 0
 VerMinor: 0
State: 0
 Capacity: 100
RTE: 65535

Note we lose the error message about interface 0 being claimed by usbfs -- progress!

Disconnecting and then reconnecting the usb cable to the OpenUPS and we see:

$ sudo ./openups -t openups -s
Device selected: openups
Selected device openups: Open UPS
interface 0 already claimed by driver "usbhid", attempting to detach it
usb_detach_kernel_driver_np returned 0
Product: OPEN-UPS, Manufacturer: Mini-Box.Com, Firmware Version: PBSO4-LiFePO
VIN: 19.603849
 VBat: 23.019020
 VOut: 19.873831 
 CCharge: 0.000000
Temperature: 42.000000
 VCell1: 3.847930
 VCell2: 3.839360
 VCell3: 3.839360
CDischarge: 0.000000
 VerMajor: 1
 VerMinor: 4
State: 2
 Capacity: 100
RTE: 65535

Great!

Trying again:

$ sudo ./openups -t openups -s
Device selected: openups
Selected device openups: Open UPS
Product: OPEN-UPS, Manufacturer: Mini-Box.Com, Firmware Version: PBSO4-LiFePO
hid_interrupt_read failed with return code -110
Read error [0x70]: -110
hid_interrupt_read failed with return code -110
Read error [0x70]: -110
VIN: 0.000000
 VBat: 0.000000
 VOut: 0.000000 
 CCharge: 0.000000
Temperature: 0.000000
 VCell1: 0.000000
 VCell2: 0.000000
 VCell3: 0.000000
CDischarge: 0.000000
 VerMajor: 0
 VerMinor: 0
State: 0
 Capacity: 100
RTE: 65535

Humpf!
(and this continues in subsequent calls)
So it looks like the 'interface 0 already claimed by driver "usbhid", attempting to detach it' error persists.
Is there a closing command needed to release claims by the driver usbhid as the command completes?

Or behaviour differs depending on the version of the usbhid driver or Linux kernel?

$ uname -a
Linux ... 4.15.0-43-generic #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Although it'd be better not to be messing with the underlying linux system if possible...

Double checking this code is version 0.6:

$ grep -R 0.6 *
...
src/version.h:#define VERSION "0.6"
...

I'd build with a make clean, then make - and run from the local folder.
Scrolling back I see:

$ git pull
remote: Enumerating objects: 30, done.
remote: Counting objects: 100% (30/30), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 17 (delta 11), reused 16 (delta 10), pack-reused 0
Unpacking objects: 100% (17/17), done.
From github.com:mini-box/ups
   02ce5ad..5d5644e  master     -> origin/master
Updating 02ce5ad..5d5644e
Fast-forward
 CMakeLists.txt           |   6 +
 src/devices.h            |  46 ++++++
 src/lib/HIDDCDCUSB.cpp   | 807 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/lib/HIDDCDCUSB.h     | 149 +++++++++++++++++++
 src/lib/HIDInterface.cpp |  31 ++--
 src/lib/HIDInterface.h   |   1 +
 src/lib/HIDNUCUPS.cpp    |   2 -
 src/lib/HIDOpenUPS.cpp   |   2 -
 src/lib/HIDOpenUPS2.cpp  |   2 -
 src/lib/usbhid.cpp       |  56 +++++--
 src/lib/usbhid.h         |  10 +-
 src/main.cpp             |  68 +++------
 src/version.h            |   2 +-
 13 files changed, 1099 insertions(+), 83 deletions(-)
 create mode 100644 src/devices.h
 create mode 100644 src/lib/HIDDCDCUSB.cpp
 create mode 100644 src/lib/HIDDCDCUSB.h
$ make clean
$ cmake .
$ make clean
$ make
Scanning dependencies of target openups
[ 10%] Building CXX object CMakeFiles/openups.dir/src/main.cpp.o
[ 20%] Building CXX object CMakeFiles/openups.dir/src/lib/usbhid.cpp.o
[ 30%] Building CXX object CMakeFiles/openups.dir/src/lib/HIDOpenUPS.cpp.o
[ 40%] Building CXX object CMakeFiles/openups.dir/src/lib/HIDOpenUPS2.cpp.o
[ 50%] Building CXX object CMakeFiles/openups.dir/src/lib/HIDNUCUPS.cpp.o
[ 60%] Building CXX object CMakeFiles/openups.dir/src/lib/HIDDCDCUSB.cpp.o
[ 70%] Building CXX object CMakeFiles/openups.dir/src/lib/HIDInterface.cpp.o
[ 80%] Linking CXX executable openups
[100%] Built target openups

@nicupavel
Copy link
Collaborator

I disabled CLOCK_OUT in e3e0e7b. Let me know if it works better.

@adamcandy
Copy link
Author

Looking good! Thanks for the quick update. Without any nut services running, it now runs error-free every time -- which is fantastic! Nice work! More details below.
Have a nice weekend!
Cheers,
Adam

Without any nut services running, it runs error-free every time:

$ sudo ./openups -t openups -s
openups version 0.7. Device selected: openups
Selected device openups: Open UPS
Product: OPEN-UPS, Manufacturer: Mini-Box.Com, Firmware Version: PBSO4-LiFePO
VIN: 19.320250
 VBat: 23.019020
 VOut: 19.822411 
 CCharge: 0.000000
Temperature: 48.000000
 VCell1: 3.839360
 VCell2: 3.839360
 VCell3: 3.847930
CDischarge: 0.000000
 VerMajor: 1
 VerMinor: 4
State: 2
 Capacity: 0
RTE: 0

Also on this system, no need for sudo/root privileges -- same output.
Note it did fail the first time - with the hid_interrupt_read error seen before, but I expect this is just a hang up from the previous runs.

With nut services running, it also gives the above most of the time, just falling over every now-and-then (with a claim failed error), when possibly nut is communicating with the device. Just for completeness, this is the output:

$ sudo ./openups -t openups -s
openups version 0.7. Device selected: openups
Selected device openups: Open UPS
interface 0 already claimed by driver "usbfs", attempting to detach it
usb_detach_kernel_driver_np returned 0
claim failed with error -16
Failed to open USB device

@lioreshai
Copy link

lioreshai commented Jan 5, 2021

Thanks for this. I am running into a similar issue on Debian - I tried the update in e3e0e7b but didn't work out (nor did a build from master branch).

Here is the error I am seeing, after a system reboot the first run of the command works without error, then I get:

openups version 0.7. Device selected: nucups
Selected device nucups: DC-DC NUC UPS
Product: DCDC-NUC UPS, Manufacturer: MINI-BOX.COM, Firmware Version: (null)
hid_interrupt_read failed with return code -110
Read error [0x80]: -110
hid_interrupt_read failed with return code -110
Read error [0x80]: -110

Is there something else I'm missing? Not sure how you were able to get it to work @adamcandy

If anyone is looking for a temporary solution, I am doing the following:

  1. Compile usbreset.c per instructions here: https://itectec.com/ubuntu/ubuntu-how-do-you-reset-a-usb-device-from-the-command-line/
  2. Find the bus and port of the device connection
  3. Set an alias in .bashrc to reset usb & run your command, like:
    alias nucups='/root/usbreset /dev/bus/usb/001/001 && openups -t nucups'

Thanks, so far this is a really impressive product!

@mini-box
Copy link
Owner

mini-box commented Jan 5, 2021

Thanks for feedback, anything interesting shows in kernel log (dmesg) beside -110 errors ?
We'll take a look.

@lioreshai
Copy link

@mini-box unfortunately no, nothing showing up in dmesg when I get the error.

@mini-box
Copy link
Owner

mini-box commented Jan 7, 2021

I pushed a new commit disabling a IO_DATA5 usb message which leads to these timeouts. There is also a 1.0 snap available for you to try.

@lioreshai
Copy link

Just re-built it and it works great - thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants