My first NAS: Custom solution for Power outage detection

Status
Not open for further replies.

wblock

Documentation Engineer
Joined
Nov 14, 2014
Messages
1,506
For fun, let's say that a non-communicating UPS is worth making the development effort to add communication. An additional microcontroller would have to watch line voltage to determine when there is an outage. It's line voltage, so think electrical isolation. There is no easy way to get the state of charge of the battery or the load, so it will be difficult to tell remaining runtime. Then you have to emulate a UPS protocol, and debugging that is going to be fun.

Replacing the UPS with one that already has all these features will cost less and be more reliable.
 
Joined
Feb 2, 2016
Messages
574
This is a really interesting thought experiment. Once I stopped being horrified of designing a custom power detection system and started thinking outside the box, fun began. Instead of engineering a device myself, I'd take an existing device and adapt it to power notification. Here's what I came up with just using cheap stuff around my home and shop...

Put a second network card in the FreeNAS server (if it doesn't already have a free NIC). Get the cheapest four-port network switch you can find if you don't already have one. Plug the FreeNAS server into that switch which is plugged into house power. When you see the network port go inactive, you'll know the power is out. You don't even need to assign an IP address, link state is enough to see if there is power.

Do you have an old USB hard drive that gets power from the wall instead of the USB port? Plug it into house power and mount the drive to your FreeNAS server. When power goes out and that partition starts throwing errors to the log, you'll know power is out.

Do you have a cheap desk lamp and a FreeBSD-compatible USB web cam? There is a lot of code floating around that uses web cams as light sensors or security motion sensors. Point the cam directly at the light. The brightness change between powered and unpowered should be easily detectable and would indicate a power failure.

Is the place where your server located air conditioned? Is the air conditioner on a UPS? If not, you could easily get a USB Thermometer and some code that will tell you when the room is warming. A warming room would indicate a power failure. Want quicker notification than ambient room temperature? Duct-tape the temperature sensor to a burning light bulb plugged into house power. As soon as the power - and light light - goes off, you'll see a quick temperature drop.

Cheers,
Matt
 

Prasant J

Dabbler
Joined
Nov 7, 2016
Messages
11
@wblock
Of course: its easy and more reliable to buy the APC UPS with serial/USB. If you start equating time/effort/brain-space with money, then the cost of buying is cheaper than making some custom solution yourself.

I am seeing this opportunity to learn something. I have already learnt a few things just by throwing this idea to the community. :)
Thanks to everyone who is contributing to this discussion.

After, @joeschmuck pointed out, only then I realised that my solution will in no way be able to point out how much battery is remaining so I should plan something for cases of frequent power disruptions. I know it may not be the perfect one but a little less perfect that keeps my data safe would be good enough for me.


Btw, my UPS model no. is APC Back-UPS 600.
 
Last edited:

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
my solution will in no way be able to point out how much battery is remaining
Sure it will--an Arduino has analog inputs, doesn't it? Set up a voltage divider with a pair of resistors, and measure it. With a reasonably well-characterized battery (and the discharge curves of lead-acid batteries are pretty well-known), you can determine remaining battery capacity (of a discharging battery) pretty well that way. Not sure off the top of my head how you'd test capacity while it's charging (probably will depend on whether it does constant-current or constant-voltage charging, or a mix of the two), but that's got to be feasible as well.
 
Joined
Feb 2, 2016
Messages
574
If you know how long it takes for the UPS to fully discharge, you could simply time the outage and shutdown based on a expected runtime. You'd also need to know how much charge is replaced when powered so, if power is restored before the server is shutdown, you can further calculate how much capacity has been restored in case of an additional power outage.

The APC Back-UPS 600 has a rated runtime of ten minutes at 50% capacity, 180 watts. My experience with power outages are they either last under ten seconds (car hits power pole, momentary short, grid reconfigures) or more than ten minutes (car hits pole, line snaps). So, I wouldn't worry too much about the logic calculating how much power is replaced but instead focus on the timer function that says 'if power has been off more than two minutes, begin shutdown procedures'.

Is power typically reliable at your location?

(In the last year, our server UPS has supplied battery power a total of four minutes and 31 seconds. The longest outage was 18 seconds during Hurricane Matthew. There were 22 blackouts and 17 electrical noise events.)

Cheers,
Matt
 

Ericloewe

Server Wrangler
Moderator
Joined
Feb 15, 2014
Messages
20,194
Put a second network card in the FreeNAS server (if it doesn't already have a free NIC). Get the cheapest four-port network switch you can find if you don't already have one. Plug the FreeNAS server into that switch which is plugged into house power. When you see the network port go inactive, you'll know the power is out. You don't even need to assign an IP address, link state is enough to see if there is power.
Well, that'll at least take care of the isolation part of the problem, with whatever the switch does on its PSU plus two 1kV isolation transformer sets on the cable.
Do you have an old USB hard drive that gets power from the wall instead of the USB port? Plug it into house power and mount the drive to your FreeNAS server. When power goes out and that partition starts throwing errors to the log, you'll know power is out.
I guess...
Do you have a cheap desk lamp and a FreeBSD-compatible USB web cam? There is a lot of code floating around that uses web cams as light sensors or security motion sensors. Point the cam directly at the light. The brightness change between powered and unpowered should be easily detectable and would indicate a power failure.
Oh my...
Is the place where your server located air conditioned? Is the air conditioner on a UPS? If not, you could easily get a USB Thermometer and some code that will tell you when the room is warming. A warming room would indicate a power failure. Want quicker notification than ambient room temperature? Duct-tape the temperature sensor to a burning light bulb plugged into house power. As soon as the power - and light light - goes off, you'll see a quick temperature drop.
http://xkcd.com/1172/
Sure it will--an Arduino has analog inputs, doesn't it? Set up a voltage divider with a pair of resistors, and measure it. With a reasonably well-characterized battery (and the discharge curves of lead-acid batteries are pretty well-known), you can determine remaining battery capacity (of a discharging battery) pretty well that way. Not sure off the top of my head how you'd test capacity while it's charging (probably will depend on whether it does constant-current or constant-voltage charging, or a mix of the two), but that's got to be feasible as well.
That has the potential to fry things, depending on the UPS topology. Even if that's not a problem, one of the resistors failing short would expose the host to +12V (or even +24V) on the USB controller, which can ruin your day. Ideally, you'd want opto-isolated serial...
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
That has the potential to fry things, depending on the UPS topology. Even if that's not a problem, one of the resistors failing short would expose the host to +12V (or even +24V) on the USB controller, which can ruin your day. Ideally, you'd want opto-isolated serial...

Use a capacitive dropper to power the LED of an optocoupler and connect your arduino to the other end of the opto, and it uses only 5 really cheap components :)

Edit: oh, I didn't saw you were talking about the battery voltage, not the line voltage. Now my post is more or useless...
 

anodos

Sambassador
iXsystems
Joined
Mar 6, 2014
Messages
9,554
Use a capacitive dropper to power the LED of an optocoupler and connect your arduino to the other end of the opto, and it uses only 5 really cheap components :)

Edit: oh, I didn't saw you were talking about the battery voltage, not the line voltage. Now my post is more or useless...

Perhaps a large electo-magnet is called for. Have it suspending a weight over a pressure switch connected to the power header on your motherboard. Power cuts, weight drops, power switch flipped, server turns off.

If you need to have a delay, connect the magnet to a lower-capacity UPS.

It's simpler than my first thought, which was to use thermite.
 
Joined
Feb 2, 2016
Messages
574
Perhaps a large electo-magnet is called for.

I like where you're going, @anodos, but your solution is inelegant.

What you need is a USB compass and your electromagnet. Plug the electromagnet into house power and orient the USB compas such that it is 180 degrees out of phase with the Earth's magnetic field when the magnet is active. When power fails, the magnet will swap orientation and the server will know power has been lost.

The only downside I see to this plan is the server could fail to initiate shutdown procedures upon power loss if the Earth's magnetic field reverses on its own to match the initial out of phase setup.

Cheers,
Matt
 
Status
Not open for further replies.
Top