Monitoring a NetYS PE 1000VA UPS from FreeBSD

Back in July 2007 I purchased a NetYS PE 1000VA UPS to provide backup mains power for my main home FreeBSD server. In the past month I have (finally!) figured out how to remotely monitor this UPS over USB connection from my FreeBSD box (currently running 8.3-PRERELEASE). This post documents the steps required to get NUT running under FreeBSD and talking to my UPS.

The NetYS PE 1000VA UPS

This device is manufactured by Socomec, whose NetYS PE line can be found here. The pictures on their website in 2012 are a little different to the unit I purchased in 2007, but the basic technical details remain the same. The UPS provides both Serial port and USB connections for remote management.

In 2007/2008 Socomec provided a free tool called “UniVision 2.0″ to monitor and control the UPS via the USB or Serial ports. They supply Windows and Linux variants, neither of which was acceptable to me. (In 2008 I tried in vain to get their Linux version running under FreeBSD 7.0-RC1. Perhaps due to end-user inexperience this turned out to be a dead-end.)

Last month I revisited using UniVision 2.0 under FreeBSD. I cheated somewhat by mapping the UPSes USB connection into a WinXP virtual machine running under VirtualBox, and successfully ran UniVision inside the VM. But this wasn’t light-weight enough to be useful in the long run.

NUT — Network UPS Tools

The key to successfully monitoring my NetYS PE 1000VA UPS under FreeBSD is using NUT with the blazer_usb driver. I was inspired by this post from a person who figured out the correct pixie dust to let NUT (under Linux) monitor their NetYS PE 800VA UPS.  (This inspiration was important because the NUT documentation doesn’t make much reference to the NetYS PE line of UPSes.)

NUT contains three main components: Drivers specific to different brands of UPS (and connection method, Serial or USB), a background daemon that talks to the driver(s), and clients that talk to the daemon in order to query (or control) the attached UPS(es).  In my case the key was learning that the blazer_usb driver can talk (at least in some rudimentary fashion) to a NetYS PE 1000VA UPS over USB.

Installing and configuring NUT 2.6.1

Using portmaster I installed NUT version 2.6.1 from the FreeBSD Ports collection.

gjabkup2# portmaster -D --packages-build /usr/ports/sysutils/nut

===>>> Port directory: /usr/ports/sysutils/nut
  [...left Serial Support unchecked and USB Support checked...]
===>>> Launching 'make checksum' for sysutils/nut in background

  [...etc...]
===>>> The following actions were performed:
   Installation of net-mgmt/net-snmp (net-snmp-5.7.1_7)
   Installation of sysutils/nut (nut-2.6.1)

gjabkup2#

First configuration step is to create a ups.conf file that identifies the correct driver and interface method. Create an initial ups.conf from the supplied ups.conf.sample file:

gjabkup2# cp /usr/local/etc/nut/ups.conf.sample /usr/local/etc/nut/ups.conf

It is useful to include the UPS’s USB interface vendorid and productid. With the UPS plugged into my FreeBSD host I extract the details with usbconfig  (the UPS comes up as a “USB to Serial Cypress Semiconductor” device):

gjabkup2# usbconfig
 [..]
ugen5.2: <USB to Serial Cypress Semiconductor> at usbus5, cfg=0 md=HOST spd=LOW (1.5Mbps) pwr=ON
gjabkup2#
gjabkup2# usbconfig -d 5.2 dump_device_desc
ugen5.2: <USB to Serial Cypress Semiconductor> at usbus5, cfg=0 md=HOST spd=LOW (1.5Mbps) pwr=ON
 [..]
  idVendor = 0x0665 
  idProduct = 0x5161 
 [..]
gjabkup2#

Add the following entry to /usr/local/etc/nut/ups.conf

[home]
    driver = blazer_usb
    port = auto
    vendorid = 0665
    productid = 5161
    desc = "Home NetYS UPS for gjabkup2 via USB"

(The vendorid and productid details help point the blazer_usb driver at the right USB device.)

Create a upsd.conf file from the supplied upsd.conf.sample:

gjabkup2# cp /usr/local/etc/nut/upsd.conf.sample /usr/local/etc/nut/upsd.conf

Uncomment the following line in /usr/local/etc/nut/upsd.conf to ensure the daemon only tries to listen on a local port using IPv4

  # LISTEN 127.0.0.1 3493

Finally, create a default upsd.users file from the upsd.users.sample file (to stop the daemon startup script from complaining)

gjabkup2# cp /usr/local/etc/nut/upsd.users.sample /usr/local/etc/nut/upsd.users

Configuring devd to set correct permissions on the usb device

Normally the USB device is owned by root:operator, as seen here:

gjabkup2# ll /dev/usb/5.2*
	  [..]
crw-rw----  1 root  operator    0, 159 Sep 30 16:56 5.2.0
crw-rw----  1 root  operator    0, 162 Sep 30 16:56 5.2.1
	  [..]
gjabkup2#

Since NUT’s background daemon runs as the user uucp, we need to ensure that the associated USB device is owned by uucp:uucp once plugged in. This is achieved using devd — we add a new rule matching the UPS USB device which chown’s the USB device’s /dev entry whenever the UPS is detected being connected (plugged in).

Create a new file /etc/devd/usb-for-ups.conf containing the following:

  notify 0 {
	  match "subsystem" "DEVICE";
	  match "type" "ATTACH";
	  match "cdev" "ugen[0-9]+.[0-9]+";

	  match "vendor" "0x0665";
	  match "product" "0x5161";

	  action "chown owner:group /dev/$cdev && logger UPS detected: vendor $vendor product $product bus $bus";

  };

Restart devd to begin taking account of the new rule:

gjabkup2# /etc/rc.d/devd restart
Stopping devd.
Starting devd.
gjabkup2#

Unplug and re-plug the UPS, and confirm the event is logged and the usb device ownership is correctly changed:

gjabkup2# tail /var/log/messages
	  [..]
Sep 30 16:57:28 gjabkup2 root: UPS detected: vendor 0x0665 product 0x5161 bus
Sep 30 16:57:28 gjabkup2 kernel: ugen5.2: <Cypress Semiconductor> at usbus5
	  [..]
gjabkup2#
gjabkup2# ll /dev/usb/5.2*
	  [..]
crw-rw----  1 uucp  uucp        0, 159 Sep 30 16:57 5.2.0
crw-rw----  1 root  operator    0, 162 Sep 30 16:57 5.2.1
	  [..]
gjabkup2#

(I am unclear what role is played by /dev/usb/5.2.1, but it comes and goes in sync with /dev/usb/5.2.0 when the UPS is plugged in or unplugged.)

Starting the NUT daemon and confirming operation

Add the following lines to /etc/rc.conf to ensure the daemon can be started whenever the system reboots.

# Enable UPS monitoring 
nut_enable="YES"
#

Manually start NUT

gjabkup2# /usr/local/etc/rc.d/nut start
Network UPS Tools - UPS driver controller 2.6.1-Unversioned directory
Network UPS Tools - Megatec/Q1 protocol USB driver 0.03 (2.6.1-Unversioned directory)
Supported UPS detected with megatec protocol

Vendor information unavailable
Battery runtime will not be calculated (runtimecal not set)
Starting nut.
Network UPS Tools upsd 2.6.1-Unversioned directory
/usr/local/etc/nut/upsd.conf is world readable
listening on 127.0.0.1 port 3493
Connected to UPS [home]: blazer_usb-home
/usr/local/etc/nut/upsd.users is world readable
gjabkup2#

Now that the daemon is running, and appears happy, I can use the upsc client to query the UPS as follows:

gjabkup2# upsc home@localhost
battery.voltage: 27.70
battery.voltage.nominal: 24.0
beeper.status: enabled
device.type: ups
driver.name: blazer_usb
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.productid: 5161
driver.parameter.vendorid: 0665
driver.version: 2.6.1-Unversioned directory
driver.version.internal: 0.03
input.current.nominal: 4.0
input.frequency: 50.0
input.frequency.nominal: 50
input.voltage: 247.8
input.voltage.fault: 247.3
input.voltage.nominal: 230
output.voltage: 209.5
ups.delay.shutdown: 30
ups.delay.start: 180
ups.load: 29
ups.productid: 5161
ups.status: OL TRIM
ups.temperature: 25.0
ups.type: offline / line interactive
ups.vendorid: 0665
gjabkup2#

NOTE: The UPS is online (OL) but is regulating the output voltage (TRIM), presumably because it believes the input voltage is too high to simply pass through ‘as-is’. Although the output looks pretty low, I confirmed it was within a few volts of actual using a digital multimeter.

So, yay! Next steps…. automated monitoring of the UPS, and triggering graceful shutdown of my FreeBSD machine(s) if the UPS ends up on batteries for too long.

Advertisements

2 comments

  1. Rick Masters · ·

    Hi,

    Thanks for the post. I have a question that you may be able to answer. I am not an expert in the UPS so my question may seems stupid to you. I want to use a similar UPS, connected to a Windows XP or 7 machine which is connected to network and send fault messages to a central system (preferably HPOV). Is this possible?

    Thanks
    Rick

  2. Glad this was helpful. Unfortunately I’m not sure of a specific answer to your question. In general, yes, it is possible to have notifications sent to an entirely different machine. Most UPSes that have management software (and NUT for UPS-independent monitoring) have mechanisms for remote alerts. But the details….. depends entirely on the particular brand/model of UPS and the manufacturer’s software.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: