Skip to content

nut on Raspberry PI keeps giving stale data after USB disconnect (usbhid-ups driver) #2742

@slavatarsyurimi

Description

@slavatarsyurimi

Greetings. I've got a single Smart-UPS X 1500 connected via USB to a Raspberry PI with nut installed with fairly basic configuration. Aside from locally getting data via the upsc command I also have nut-http set up to provide the same data via a HTTP API (end usecase is making a bitfocus companion module that is going to query that data). Nut is talking to the UPS via the usbhid-ups driver.

If I disconnect the usb cable - nut keeps reporting last known data, seemly unaware of the disconnect (both when asked via upsc or the http api). Expected behaviour after a usb disconnect would be seeing a "Driver not connected" error. I've tinkered with a bunch of settings, googled issues and chatgpt suggestions for a few hours now, but whatever I do it doesn't change this behavior. Here's some stuff I tried:

  • pollonly = "enabled" in the ups.conf UPS setting
  • playing around with pollinterval and pollfreq in the same config
  • playing around with MAXAGE in upsd.conf
  • manual UPS port selection in ups.conf

The curious thing is that it keeps returning stale data even after restarting the nut server (sudo systemctl resart nut-server). The only 'soft' way I've found for it to figure out it's gone was either making an adjustment in ups.conf or doing a hard usb driver restart for this UPS (/bin/systemctl restart nut-driver@[upsname].service).
To poke it around some more I installed nut on my macbook, and plugged the UPS right in. It looks like it doesn't automatically keep the usb driver running after configuring the ups on mac like it does on linux. When running the usb driver manually and disconnecting the usb cable I see instantly see a nut_libusb_get_report: No such device (it may have been disconnected) error, and the driver crashing shortly after - which is nice.

To explore some more I discovered you can tail the usb driver logs like so sudo journalctl -u nut-driver@[upsname].service -f.
What I observe there is that the driver is infact well aware of the fact that a disconnect took place. Only in this case it keeps repeating the following:

  96.184957     [D1] Can't retrieve Report 0f: No such device
  96.184996     nut_libusb_get_report: No such device (it may have been disconnected)

Meanwhile the driver is still running, and both upsc and nut-http keep dumping old data. I haven't let it take quite a lot of time to see if it realizes eventually, but it definitely lasts for 5+ minutes which is unaccetable for my use case. Also, logically the MAXAGE setting should tell nut to declare data as stale as quickly as after 15 seconds.
Anyone any clue what's going on here and what else I can try? Many thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    APCConnection stability issuesIssues about driver<->device and/or networked connections (upsd<->upsmon...) going AWOL over timeIncorrect or missing readingsOn some devices driver-reported values are systemically off (e.g. x10, x0.1, const+Value, etc.)USBmacOSraspberry

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions