Background
This article provides a guide for installing a USB UPS attached to a Raspberry Pi. In my case I had purchased a GreenCell 600 360W USB UPS. Integrating the USB UPS requires using NUT (Network UPS Tools). This UPS uses the blazer_usb driver.
Installation NUT
Plug-In the UPS USB-Connection to the host. My device showed up as Device 006 below:
# lsusb
Bus 001 Device 006: ID 0001:0000 Fry's Electronics MEC0003Bus 001 Device 005: ID 0bda:0309 Realtek Semiconductor Corp. USB3.0-CRWBus 001 Device 004: ID 0658:0200 Sigma Designs, Inc. Aeotec Z-Stick Gen5 (ZW090) - UZBBus 001 Device 003: ID 0424:ec00 Microchip Technology, Inc. (formerly SMSC) SMSC9512/9514 Fast Ethernet AdapterBus 001 Device 002: ID 0424:9514 Microchip Technology, Inc. (formerly SMSC) SMC9514 Hub
Install the NUT package with the apt package manager:
sudo apt-get install nut
Make some configurations and changes in the nut directory /etc/nut:
# cd /etc/nut
drwxr-xr-x 2 root nut 4096 Jan 11 00:49 .drwxr-xr-x 94 root root 4096 Jan 10 23:54 ..-rw-r----- 1 root nut 1543 Jan 11 00:01 nut.conf-rw-r----- 1 root nut 5571 Jan 11 00:12 ups.conf-rw-r----- 1 root nut 4595 Jan 11 00:01 upsd.conf-rw-r----- 1 root nut 2177 Jan 11 00:03 upsd.users-rw-r----- 1 root nut 15362 Jan 11 00:16 upsmon.conf-rw-r----- 1 root nut 3887 Jun 1 2018 upssched.conf
In the nut.conf file we change the MODE to netserver:
# nano /etc/nut/nut.confMODE=netserver
In the ups.conf we need to configure the right drivers for the UPS. You can get a compatibility list from the NUT-Server on https://networkupstools.org/stable-hcl.html
We make a new section for the UPS like in this example. As my UPS is connected via usb the port configuration can be set to auto. If you connect the UPS via a serial cable you need to configure it differently:
[greencell]driver = "blazer_usb"port = "auto"desc = "Green Cell UPS"
After setting up the right drivers we can make sure that the NUT-Server detects the UPS:
upsdrvctl start
The output should look like this:
Network UPS Tools - UPS driver controller 2.7.4Network UPS Tools - Generic HID driver 0.41 (2.7.4)USB communication driver 0.33
The upsd.conf has a LISTEN section. We need to configure it with the server ip-address so we can connect to the NUT-Server from other clients:
# nano /etc/nut/upsd.confLISTEN 192.168.x.x // Openhab server ip addressLISTEN 127.0.0.1 3493LISTEN ::1 3493
In my example I’ve added the first ip-address (192.168.178.79). There is no need to write the port behind the address (3493) unless you want to change the default port.
After that we need to make a new user in the upsd.users file:
# /etc/nut/upsd.users
[admin]
password = ****
actions = SET
instcmds = ALL
[monmaster]
password = xxxxx
upsmon master
[lamppi]
password = xxxxx
upsmon slave
[nextcloudpi]
password = xxxxx
upsmon = slave
You should add multiple users for the server and clients. See the manual page for upsd.users for more information.
Now we configure the upsmon.conf there we need to add a MONITOR master
# /etc/nut/upsmon.conf
MONITOR greencell@192.168.x.x 1 monmaster upsmon0 masterPOWERDOWNFLAG /etc/killpowerSHUTDOWNCMD "/sbin/shutdown -h now"
As the system name uses the value in the brackets you made in the ups.conf the user and password was configured in the upsd.user file.
Since we don’t want that other users can read this secret files we fix the permissions for our needs.
$ sudo chown root:nut /etc/nut/*$ sudo chmod 640 /etc/nut/*
At the end whe should reload both services upsd and upsmon. This can be done like this:
sudo systemctl restart nut-server
Use the admin user to do this, you will be requested to enter username and password as above.
Testing a local Client request
Now we can test if the NUT-Server works locally. I’ll make client request to this the instance name greencell:
upsc greencell
If everything works fine we get an output similar to this:
Init SSL without certificate databasebattery.charge: 100battery.voltage: 14.00battery.voltage.high: 13.00battery.voltage.low: 10.40battery.voltage.nominal: 12.0device.type: upsdriver.name: blazer_usbdriver.parameter.pollinterval: 2driver.parameter.port: autodriver.parameter.synchronous: nodriver.version: 2.7.4driver.version.internal: 0.12input.current.nominal: 2.0input.frequency: 50.1input.frequency.nominal: 50input.voltage: 238.3input.voltage.fault: 238.3input.voltage.nominal: 230output.voltage: 238.3ups.beeper.status: enabledups.delay.shutdown: 30ups.delay.start: 180ups.load: 3ups.productid: 0000ups.status: OLups.type: offline / line interactiveups.vendorid: 0001
Set up clients/slaves
First, the necessary packages must be installed on a client:
sudo apt-get install nut-client
This time we only have to edit two files. In /etc/nut/nut.conf we set the mode:
MODE=netclient
Then we need to tell upsmon which UPS to monitor (in /etc/nut/upsmon.conf):
MONITOR greencell@192.168.178.79 1 lamppi upsmon1 slave
The IP and password must be adjusted. Please also note the slave at the end!
Finally, restart the corresponding service and check that everything is running:
$ sudo systemctl restart nut-client
Congratulations! Now everything should be set up.
Check monitoring is working by issuing the following command on the nut server (openhabpi):
$ upsc -c greencell
The following information should be returned:
Init SSL without certificate database192.168.178.93192.168.178.79
but how can you test that it really works?
Testing shutdown
The following command triggers the shutdown signal (as it would be in the event of a power failure) and shutdown all servers:
$ sudo upsmon -c fsd
All servers should shutdown (so be careful about using this command)!
Comments
Post a Comment