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

Duplicate USB devices don't connect in 2.8.0 #1414

Open
ProjectInitiative opened this issue May 4, 2022 · 10 comments
Open

Duplicate USB devices don't connect in 2.8.0 #1414

ProjectInitiative opened this issue May 4, 2022 · 10 comments
Labels
USB USB-duplicate-devices Track bugs and issues about monitoring several devices that seem identical to NUT or libusb

Comments

@ProjectInitiative
Copy link

ProjectInitiative commented May 4, 2022

OS: Fresh installed raspberry pi OS 64 bit
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye

Build commands used

Built from source with provided instructions. All commands used below:

sudo apt-get install -y make g++ gcc build-essential autoconf gettext m4 libtool libudev-dev automake pkg-config libusb-0.1-4 libusb-1.0-0-dev libsnmp-dev libgd-dev

groupadd nut
useradd -ms /bin/bash ups
usermod -aG nut ups
usermod -aG nut root

mkdir -p /var/run/nut
chown root:nut /var/run/nut
mkdir -p /var/state/ups
chown root:nut /var/state/ups
chmod 0770 /var/state/ups

git clone https://github.com/networkupstools/nut.git
/nut
./autogen.sh
./configure --with-user=ups --with-group=nut --with-usb --with-snmp --with-cgi
make -j $(nproc)
make install

nut-scanner output

sudo /usr/local/ups/bin/nut-scanner
Scanning USB bus.
No start IP, skipping SNMP
No start IP, skipping NUT bus (old connect method)
[nutdev1]
        driver = "usbhid-ups"
        port = "auto"
        vendorid = "0764"
        productid = "0601"
        product = "OR1500LCDRM1U"
        vendor = "CPS"
        bus = "001"
[nutdev2]
        driver = "usbhid-ups"
        port = "auto"
        vendorid = "0764"
        productid = "0601"
        product = "OR1500LCDRM1U"
        vendor = "CPS"
        bus = "001"

Adding this info to /usr/local/ups/etc/ups.conf and running sudo /usr/local/ups/sbin/upsdrvctl -u root start worked in previous versions, connected to both devices.

Presently upsdrvctl returns the following:

Network UPS Tools - UPS driver controller 2.8.0-18-gaaa72bebd
Network UPS Tools - Generic HID driver 0.47 (2.8.0-18-gaaa72bebd)
USB communication driver (libusb 1.0) 0.43
Using subdriver: CyberPower HID 0.6
Network UPS Tools - Generic HID driver 0.47 (2.8.0-18-gaaa72bebd)
USB communication driver (libusb 1.0) 0.43
Can't claim USB device [0764:0601]@0/0: Entity not found
Driver failed to start (exit status=1)

NOTE: only having one UPS plugged in works just fine, the problem only comes up when 2 or more are connected.

@ProjectInitiative
Copy link
Author

I would like to also note that I have tried this in a x86 installation of Debian as well. Same behavior.

@jimklimov
Copy link
Member

jimklimov commented May 4, 2022 via email

@ProjectInitiative
Copy link
Author

ProjectInitiative commented May 4, 2022

So I went down the rabbit hole a bit. There are no unique identifying bits of meta data for these two devices (the ups does not return a serial number).

I have found two ways to differentiate the two: using the devnum outputted by lsusb, or by the physical bus port.

Making the problem worse: the upses (cyberpower) constantly disconnect and reconnect themselves until a driver binds to them. Therefore the devnum gets increased frequently.

I wrote a python script to read /sys/bus/usb/devices/1-1.1/devnum for instance, and add that to ups.conf as "device=000", and restart the driver's if the cables were ever unplugged or the kernel re-numbered things.

The problem is, the "device=000" parameter seems to be ignored by upsdrvctl and usbhid-ups.

@ProjectInitiative
Copy link
Author

I was poking through the code, and trying to figure out where to add a new ups.conf parameter to use a dev path or bus port to the usbhid-ups driver.

@jimklimov
Copy link
Member

jimklimov commented May 5, 2022 via email

@jimklimov
Copy link
Member

UPDATES:

@jimklimov jimklimov added the USB label May 10, 2022
@ProjectInitiative
Copy link
Author

The cross referenced issue is the same issue, different UPS. I'm still looking at libusb functions that could help bind to the correct HID device

@jimklimov
Copy link
Member

Someone mentioned on the mailing list recently that libusb-0.1 API did not allow to connect to devices by path; however libusb-1.0 should have a way to do so (and this honor the port setting which is now ignored) => #1565

@jimklimov jimklimov added the USB-duplicate-devices Track bugs and issues about monitoring several devices that seem identical to NUT or libusb label Jan 2, 2023
@jimklimov
Copy link
Member

jimklimov commented Jan 2, 2023

Interesting, I don't remember seeing Can't claim USB device [0764:0601]@0/0: Entity not found earlier. Googling points "Entity not found" to possibly "not claiming an interface first".

@jimklimov
Copy link
Member

jimklimov commented Jan 2, 2023

Regarding "device=000": how is it reported by OS? In a Linux system I have, there are no 000s in lsusb output, seems it is 001 based for each bus.

Note that the argument is a regex (in trivial case a fixed string), not a numeric comparison.

If you run the driver with debug verbosity 2 (or higher) it should report the mismatches in detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
USB USB-duplicate-devices Track bugs and issues about monitoring several devices that seem identical to NUT or libusb
Projects
None yet
Development

No branches or pull requests

2 participants