Skip to content

Instantly share code, notes, and snippets.

@clungzta
Last active March 10, 2021 14:43
Show Gist options
  • Save clungzta/2b5f737f006e1530cc59 to your computer and use it in GitHub Desktop.
Save clungzta/2b5f737f006e1530cc59 to your computer and use it in GitHub Desktop.
Overview of how to install OpenUPS2 using Linux, using the usbhid-ups driver for NUT (Network UPS Tools), allows you to view ups status, battery voltage and temperature etc.

OpenUPS2 Install Linux

alt text

Step 1

Plug the device in, check the device connection

$ lsusb | grep "d005"
Bus 001 Device 002: ID 04d8:d005 Microchip Technology, Inc.

If no Microchip Technology device shows up, check the usb conection and try again

Step 2

Install NUT using your prefered package manager

e.g on Ubuntu:

$ sudo apt-get install nut

#Step 3 Stop the upsdrvctl service

$ sudo upsdrvctl stop

Step 4

Configure the driver for the openups2

$ sudo /lib/nut/usbhid-ups -u root -x productid=d005 -a openups2

If you get the error "Can’t chdir to /var/run/nut: No such file or directory"

$ sudo mkdir /var/run/nut
$ sudo chown root:nut /var/run/nut
$ chmod 770 /var/run/nut

Step 5

Change the permissions for the USB port

a) Find the bus number and device number for the UPS

$ lsusb | grep "d005"
Bus 001 Device 002: ID 04d8:d005 Microchip Technology, Inc.

b)

$ sudo chmod 0666 /dev/bus/usb/[bus number]/[device number]

NOTE: these permissions will need to be reset everytime you restart the computer or unplug the device

OPTIONAL: a UDEV rule can be added to avoid this

$ sudo touch /etc/udev/rules.d/50-usb-openups2.conf
$ echo 'SUBSYSTEM=="usb", ATTR{idProduct}=="d005", MODE="0666"' | sudo tee --append /etc/udev/rules.d/50-usb-openups2.conf

Step 6

Start the driver service

$ sudo upsdrvctl start

Step 7

Start UPSD

$ sudo upsd

Step 8

You can now view the live UPS data using your preffered UPSD Client

e.g with the built in UPSC client

$ upsc openups2@localhost
battery.capacity: 100
battery.charge: 100
battery.charge.low: 5
battery.charge.warning: 20
battery.current: 0.000
battery.mfr.date: ?
battery.runtime: 3932100
battery.temperature: 34.22
battery.type: ?
battery.voltage: 10.22
device.mfr: Mini-Box.Com
device.model: OPEN-UPS2
device.serial: LI-ION
device.type: ups
driver.name: usbhid-ups
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.productid: d005
driver.version: 2.7.1
driver.version.data: openUPS HID 0.1
driver.version.internal: 0.38
input.current: 0.000
input.voltage: 533.95
output.current: 0.000
output.voltage: 488.36
ups.mfr: Mini-Box.Com
ups.model: OPEN-UPS2
ups.productid: d005
ups.serial: LI-ION
ups.status: OL
ups.vendorid: 04d8
@Nurgak
Copy link

Nurgak commented Nov 8, 2016

I tried to follow this procedure, but it did not work properly.

lsusb reports

Bus 001 Device 005: ID 04d8:d005 Microchip Technology, Inc.

NUT install goes properly, then sudo upsdrvctl stop says

Can't open /var/run/nut/usbhid-ups-auto.pid: No such file or directory

Fair enough, maybe there's nothing to stop...

/etc/nut/ups.conf contains the following:

[openups2]
    driver = usbhid-ups
    port = auto
    vendorid = 04d8
    pollfreq = 30
    desc = "Mini-Box OpenUPS2"

In Step 4 the command chmod 770 /var/run/nut needs sudo. /var/run/nut belongs to root:nut as expected.

ls -la /dev/bus/usb/001/005 reports

crw-rw-rw- 1 root root 189, 4 nov  8 17:33 /dev/bus/usb/001/005

Not of the nut group so I put it there myself with sudo chown root:nut /dev/bus/usb/001/005.

Then sudo /lib/nut/usbhid-ups -u root -x productid=d005 -a openups2 is successful.

Finally the command sudo upsdrvctl start reports:

Network UPS Tools - UPS driver controller 2.7.1
Network UPS Tools - Generic HID driver 0.38 (2.7.1)
USB communication driver 0.32
This openUPS device (04d8:d005) is not (or perhaps not yet) supported
by usbhid-ups. Please make sure you have an up-to-date version of NUT. If
this does not fix the problem, try running the driver with the
'-x productid=d005' option. Please report your results to the NUT user's
mailing list <nut-upsuser@lists.alioth.debian.org>.

No matching HID UPS found
Driver failed to start (exit status=1)

@SebReuter
Copy link

SebReuter commented Jun 3, 2017

To start upsdrvctl I hat to add the productid to /etc/nut/ups.conf

[openups2]
    driver = usbhid-ups
    port = auto
    vendorid = 04d8
    productid = d005
    pollfreq = 30
    desc = "Mini-Box OpenUPS2"

To run upsd I hat to set mode to standalone in /etc/nut/nut.conf
MODE=standalone

Parameters can be viewed by:
sudo upsc openups2@localhost

@cabled
Copy link

cabled commented Aug 1, 2017

Having exactly the same issues as Nurgak. i.e. no matching HID UPS found... anyone managed to solve this?

@clepple
Copy link

clepple commented Aug 2, 2017

Hi all, a couple of clarifications:

  • The first version of NUT to support the original openUPS was 2.7.1. You can make an OpenUPS2 work with NUT 2.7.1 using the procedure that Nurgak mentioned, but some of the voltages will be off. NUT 2.7.3+ supports the OpenUPS2 out of the box, with proper voltage scaling.
  • @Nurgak: it looks like -x productid=d005 worked on the driver command line, so you can add productid=d005 to ups.conf to make upsdrvctl start work properly.

Feel free to raise any other NUT issues at https://github.com/networkupstools/nut/issues or on the nut-upsuser mailing list.

@clungzta, thanks for writing this up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment