# HOWTO: MGE Ellipse 300 on gentoo

## nielchiano

I recently bought a UPS and wanted to take full advantage of this. I found some guidelines, but had to figure out a lot myself. Since I don't want this knowledge to void I'm writing my first howto.

Other related howto's:

Official MGE-opensource-site

HOW-TO: UPS MGE Protection Center 500

HOWTO: UPS with Gentoo Linux using NUT with MRTG Statistics

What is it about?

MGE pulsar ellipse 300 USBS (probabely other MGE's too)

Connected via USB, NOT serial.

hardened kernel, 2.6 series (currently 2.6.11-r15)

My computer: some drivers may differ

I chose MGE because they officialy support linux and have done a lot of work to get UPSes to work on linux!!

Step 1: Kernel

You need the following

```

Device Drivers  --->

  USB support  --->

    [*] Support for Host-side USB

    [?] EHCI HCD (USB 2.0) support

    [?] OHCI HCD support

    [?] UHCI HCD (most Intel and VIA) support

    [*] USB Human Interface Device (full HID) support

      [*]   /dev/hiddev raw HID device support

```

EHCI, OHCI, UHCI depends on your hardware, I need only UHCI. use lspci (from sys-apps/pciutils) to find out.

Recompile it and reboot. 

I use udev with hotplug. Arnaud Quette (from opensource.mgeups.com and nut and ...) noted that you NEED hotplug because the default permissions on /proc/bus/usb/XXX/YYY are not sufficient. How to setup udev is beyond the scope of this howto. Go here for more details: http://www.gentoo.org/doc/en/udev-guide.xml

Step 2: Patching and changing

I tried several packages, but they didn't work. So I looked for bugs relating and adapted some more things.

Related bugs:

www-apps/nut version 2.0.1 version bump required

www-apps/nut 2.0.0-r1 creates link to upsdrvctl in /usr/sbin, should be in /sbin

libusb dependency for www-apps/nut ebuild forgotten when using NUT_DRIVERS="newhidups"

UPS: libusb should be in /lib, not in /usr/lib

UPS-shutdown requires /proc/bus/usb to be mounted rw

Make a portage overlay by creating /usr/local/portage

```
# mkdir /usr/local/portage
```

and by editing /etc/make.conf to reflect this: uncomment (or add) this line

```
PORTDIR_OVERLAY="/usr/local/portage"
```

add the following files to the newly created portage overlay (create directories if necessary):

http://134.184.38.93/niels/mge/libusb-0.1.10a-r1.ebuild --> /usr/local/portage/dev-libs/libusb/libusb-0.1.10a-r1.ebuild

http://134.184.38.93/niels/mge/nut-2.0.1.ebuild --> /usr/local/portage/www-apps/nut/nut-2.0.1.ebuild

also copy over the start-up scripts:

```
cp /usr/portage/www-apps/nut/files/ups{mon,d,drv}.rc6 /usr/local/portage/www-apps/nut/files/.
```

and create their digest

```
# ebuild /usr/local/portage/dev-libs/libusb/libusb-0.1.10a-r1.ebuild digest

# ebuild /usr/local/portage/www-apps/nut/nut-2.0.1.ebuild digest
```

Step 3: instalation

To tell nut to build the newhidups-driver you need to add the line

```
NUT_DRIVERS="newhidups"
```

to your /etc/make.conf.

Since we want to use our newly added ebuilds, you need to tell emerge about this:

```
# mkdir /etc/portage

# echo "dev-libs/libusb ~x86" >> /etc/portage/package.keywords

# echo "www-apps/nut ~x86" >> /etc/portage/package.keywords
```

next, build nut

```
# emerge www-apps/nut
```

Step 4: Configuration

next we need to configure NUT to talk to our UPS. Make sure the UPS is connected by now.

add these lines to /etc/nut/ups.conf:

```
[mge]

        driver = newhidups

        port = auto

        desc = "MGE Pulsar Ellipse 300 USBS"
```

add these line to /etc/nut/upsd.users:

```
[monuser]

        password        = S0mePa55W0Rd

        allowfrom       = localhost

        upsmon          master
```

add (or uncomment and change) this line to upsmon.conf:

```
MONITOR mge@localhost 1 monuser S0mePa55W0Rd master
```

The values "mge", "MGE Pulsar Ellipse 300 USBS", "monuser" and "S0mePa55W0Rd" are arbitry and can be whatever, just make sure that they remain the same across files.

Step 5:Testing

If all went well, you can start testing.

load the driver

```
# /etc/init.d/upsdrv start

 * Starting UPS drivers ...

Network UPS Tools - UPS driver controller 2.0.1

Network UPS Tools: New HID UPS driver 0.12 (2.0.1)

Warning: This is an experimental driver.

Some features may not function correctly.

Detected an UPS: MGE/ELLIPSE

[ ok ]
```

start the server

```
# /etc/init.d/upsd start

 * Starting upsd ...

Network UPS Tools upsd 2.0.1

Connected to UPS [mge]: newhidups-auto

Synchronizing...done

[ ok ]
```

Test server

```
# upsc mge@localhost

battery.charge: 91

battery.charge.low: 30

battery.runtime: 1561

driver.name: newhidups

driver.parameter.port: auto

driver.version: 2.0.1

driver.version.data: MGE HID 0.6

driver.version.internal: 0.12

input.transfer.high: 264.0

input.transfer.low: 184.0

output.voltage: 230.0

ups.delay.shutdown: -1

ups.delay.start: -10

ups.load: 3

ups.mfr: MGE

ups.model: ellipse 300

ups.serial: unknown

ups.status: OL CHRG
```

start monitor

```
# /etc/init.d/upsmon start

 * Starting upsmon ...

Network UPS Tools upsmon 2.0.1

UPS: mge@localhost (master) (power value 1)

Using power down flag file /etc/killpower

[ ok ]
```

If everything goes well, tell gentoo to start them automaticaly

```
rc-update add upsd default

rc-update add upsmon default
```

Step 6: More hacks

when the UPS goes on low battery, upsmon will start the shutdown of the computer. the last command will signal the UPS that it may kill the power to us.

The problem is that the newhidups-driver needs /proc/bus/usb to be mounted read-write (see bug #103133).

The ugly workaround is to manualy edit /etc/init.d/halt.sh and add this line:

```
# This is a function because its used twice below

ups_kill_power() {

        local UPS_CTL UPS_POWERDOWN

        if [[ -f /etc/killpower ]] ; then

                UPS_CTL=/sbin/upsdrvctl

                UPS_POWERDOWN="${UPS_CTL} shutdown"

        elif [[ -f /etc/apcupsd/powerfail ]] ; then

                UPS_CTL=/etc/apcupsd/apccontrol

                UPS_POWERDOWN="${UPS_CTL} killpower"

        else

                return 0

        fi

        if [[ -x ${UPS_CTL} ]] ; then

                ewarn "Signalling ups driver(s) to kill the load!"

                mount -n -o remount,rw /proc/bus/usb                              <=========== add this

                ${UPS_POWERDOWN}

                ewarn "Halt system and wait for the UPS to kill our power"

                /sbin/halt -id

                while [ 1 ]; do sleep 60; done

        fi

}

```

Step 7: More tests

you can now pull the plug and wait until the battery runs empty to test the setup.

However, you can also fake this.

```
upsmon -c fsd
```

will have the same effect than a low-batt condition and initiate shutdown. My UPS waits about 10 seconds between receiving the command to kill the power, and actualy doing in. If the power comes back on, the power to the computer is restored.

Even if the power came back on in these 10 seconds, or didn't go off at all, the UPS will still kill power for approx 5 seconds.

Side-notes

I hope this guide is helpful to some people struggeling with the same problem I had. Let me know about any mistakes/omissions/...

yes, NUT is is www-apps, don't ask me why.... there are bug-reports that reqeust a change to sys-power, but they're not yet heard....

For people having trouble with hotplug: http://lists.alioth.debian.org/pipermail/nut-upsuser/2005-August/000108.html

----------

## PaRaNo

Thank you!

this Howto works great with my Ellipse 800 even with the ~amd64 use flag

----------

## BlackB1rd

Also works great with a Ellipse 500  :Cool:  But I emerged a newer version of libusb, which is currently in portage.

----------

## kdvgent

Worked like a charm.

Some comments:

I am working under ~AMD64

Step 2 "Patching and changing" is not needed anymore - I used libusb-0.1.11 and nut-2.0.1_pre4 that are both in portage (be it in the testing branch)

In Step 3, you no longer need to tell nut to build the newhidups driver (and of course, you no longer need to specify the overlays)

In Step 4, the user "monuser" (with the correct password) must of course be created.  I made this user member of the group "nut"

I also emerged ups-monitor (although the ~AMD64 keyword is not yet there, things work out fine)I had in the past several attempts to install the UPS driver but was always "blocked" by "data stale" problems.  Seems to have gone with my present combination of HW/SW

Thanks a lot for this HOWTO.

----------

