My first NAS: Custom solution for Power outage detection

Status
Not open for further replies.

Prasant J

Dabbler
Joined
Nov 7, 2016
Messages
11
Hi,

I'm planning to build my first NAS.
I have a simple APC UPS but it does not have USB port. I don't have money to spend on APC UPS with power outage notification.
I plan to build my own power outage detection (may be using Arduino) with serial connection to FreeNAS PC.

I'm planning to run FreeNAS from USB Stick


I would like to the following:

1) How can my Serial PC utility notify NAS software about power outage?
a) Do I have to shutdown the PC or is there a facility to just unmount the DISKs?

2) Is the FreeNAS installed on the USB Stick or does it run Live from USB Stick?
a) If yes, how can I install my Serial PC utility to the USB Stick ?

3) Did any one used any other custom solution for Power Outage Detection?

Any inputs will be of help to me.


Awaiting feedback from the community! :)

Regards, Pj
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
Your best bet would be to make your Arduino emulate one of the known and supported UPS protocols. Then you could just configure FreeNAS as normal.
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
While I can see how I'd make this project work using some external circuit, I'm curious on how you plan to implement it. @danb35 is correct, you should have it output either serial or USB signals based on a standard format.

So if you have some experience in electronics and programming then you should be able to pull this off okay but let me just say this one thing... Timing is everything when dealing with serial data.

If this is a first time dive into electronics, you might be over your head. Before buying an Arduino, plan out how you are going to execute this task, what the input signal and output signals need to be (voltage, frequency, duration, and format). Write it down and then buy an Arduino which will meet the needs.

If you have no idea what you are doing and you just thought of this idea, you might be better off buying a new UPS.

If you do build this, I'd like to hear about it.
 

Prasant J

Dabbler
Joined
Nov 7, 2016
Messages
11
@danb35 :

I'm not sure if I can emulate arduino to give out supported UPS signals. That was my first option too. But I'm not sure if I can write standard protocol by myself without any bug.


@joeschmuck :

I have thought about it. I'm pretty confident I can make it work. However, I don't know 2 things:

1) Can I run the custom serial listener utility program alongside FreeNAS? How will I compile it ? (python listener would be preferred by me)

2) Is there any API available (other than standard UPS protocol) for my serial listener to inform/notify FreeNAS about Power outage?
 

Sakuru

Guru
Joined
Nov 20, 2015
Messages
527

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
1) Can I run the custom serial listener utility program alongside FreeNAS? How will I compile it ? (python listener would be preferred by me)
No, this is a bad idea. You would need to compile each version of FreeNAS if you did this. Use the NUT API as previously described.

Here is how I'd do it and please understand that this is off the cuff so I'd have to do more research into it myself.

1) Google Search for Arduino and UPS Monitoring. There are a lot of projects out there that have already been done so use that to help you out.
2) I would need to monitor when I have a loss of power. For me I'd just simply use a 115VAC SPDT relay (US Power) and use the contact as the input to the Arduino and that is now my trigger. If you are really good, this could be built into the UPS when you are all done, or you could just keep it as a separate unit and plug the relay into a surge only connection on the UPS.
3) I'd have to ensure that the Arduino has a serial port that I could use.
4) I'd need to look up the NUT API and ensure it will do what I wanted and create two static files which I could send over the serial port. The files would be a OL Status and then a OB Status (On Line and On Battery). Remember that you should be able to respond to a serial request with the OL Status and while in a shell window, be able to request the status. The OB Status is of course for when you are on better and you could just disconnect the relay power to simulate that.
5) Then you need to fine tune the software so it will only submit an OB Status after a power loss of maybe 1 second. You would then make FreeNAS the Master (the default setting) and set up the system to shut down immediately.

Extra stuff you could do is to actually build this internal to the UPS and then you could monitor the voltage of the battery and when it hits a specific voltage, you guessed it, another Status message stating the UPS is at critical voltage and then you could also use that as a trigger. You would just need either an Arduino with an Analog voltage input, and I think they all have that.
 

Pitfrr

Wizard
Joined
Feb 10, 2014
Messages
1,531
I would use a solution without any additional hardware: just a script running each minute (or longer, depending on your UPS), pinging a device (or several for more reliability) on the network that would go off line in case of a power outage (like a switch or a modem). If the device is not responding then I would shutdown the server.

That was the solution I had in mind for one of my setups but I didn't implement it yet... I kind of forgot about it but your post reminded me about that, thanks. ;-)
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
You could do something like that too and is not a bad suggestion, it's actually an easy one to do.
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
I'm not sure if I can emulate arduino to give out supported UPS signals.
Why not? There are a number of documented UPS interface protocols (I'd dig into the NUT docs, as @Sakuru noted above). A number of them are designed to use serial signaling (a number of others use a USB interface, which you might also consider, depending on what flavor of Arduino you want to use). You'd need to program the Arduino to signal (at a minimum) when it's on battery and when it's online, so why not make it send signals that NUT will already understand as being UPS signals?
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
I'll tell you, I really like the suggestion above to just use a script and ping a known device. If the device fails to respond then you assume the power has gone out. The only problem with this is if the device goes down because you removed it or disconnected an Ethernet cable. There could be a bit more risk but the worst thing that can happen is your NAS shuts down properly even though you may not have desired that. For my self I'd ping my WiFi access point since it is in the ceiling and not on an UPS. If it didn't respond to a ping or access, that could send the command shutdown in 5 minutes and if the WiFi AP came back before the 5 minutes were up it could send the command to stop the shutdown.

You would also want to keep track on overall time the power has gone out in case you have multiple short power outages which could drain the UPS and maybe if there are 10 minutes of On Battery time within 1 hour, the next powr failure would trigger the shutdown and not be allowed to stay on even if power is restored. You need to think about those things with the Arduino as well.
 

wblock

Documentation Engineer
Joined
Nov 14, 2014
Messages
1,506
Back up a second: APC UPSes that lack USB have serial. That is far easier to deal with than creating your own solution.
 

Noctris

Contributor
Joined
Jul 3, 2013
Messages
163
Joined
Feb 2, 2016
Messages
574
Are you doing this because you love hardware design, software design, a challenge and are willing to work out the bugs over who knows how many revisions or are you looking to efficiently solve a problem?

For $60 USD, you can get a new, brand-name UPS with USB power status notification. For half that you can get a used UPS with a lousy battery that will still provide power status notification over USB - just don't plug your FreeNAS server into the questionable UPS, it's just there for notification. (If you lived closer, I'd just give you one that is old enough we're not willing to replace the battery. We have a bunch of them in the shop that we will likely throw away.)

@Pitfrr 's middle ground of pinging an intermediary device sounds like the second best choice.

Cheers,
Matt
 

wblock

Documentation Engineer
Joined
Nov 14, 2014
Messages
1,506
I was thinking just a serial to USB adapter. The PL2303 ones are cheap and probably adequate. it will still likely require one of the funny APC custom-wired cables, or you can build your own. That cable would plug into the USB serial adapter.

The problem with a home-grown solution is that the failure modes are varied and most of them involve the system losing power unexpectedly.
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
I am under the impression that the OP has an UPS with no data connection at all.
 

wblock

Documentation Engineer
Joined
Nov 14, 2014
Messages
1,506
Possibly, but I've been using APC units for an embarrassingly long time, and don't recall any that didn't have something. The cheap ones used to have a fake serial which might not work with a USB serial adapter, but I don't know.

So we should probably find out exactly which model OP has.
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
The cheaper APC UPS might have had an Ethernet surge suppressor built in but they typically were crap.
 

Prasant J

Dabbler
Joined
Nov 7, 2016
Messages
11
Guys sorry for my late response.

One clarification, my APC UPS is the most basic one, with no interfaces at all (no serial, no USB, no RJ45)

@Sakuru
I have to reverse engineer and I'm too lazy to do that. If I get a library that UPS uses then it will be helpful.

@joeschmuck
Thanks for your helpful points. I did not think that I would need to take care of frequent disruptions. I will keep those in mind.

@Pitfrr
That is a nice and simple solution for data safety. I could think about this one.
One question: When we use the APC UPS with NUT support, does the NAS turn back ON when the power is back?


@wblock
I actually meant that my UPS is not 'smart'. I have no interfaces. The most basic model.

@Noctris
I'm trying to create my NUT Client/Slave which can inform NUT Master (in this case FreeNAS) that the UPS is on battery. Lack of network is not my problem (at the moment at least).

@MatthewSteinhoff
I love hardware design and creating my own solution cheaper solution is what I really love to do (of course it should not compromise my data, so I'm looking for opinion from the experts).
In India, the smart UPS (APC) is priced at $120 - $150.
I will sadly have to spend this money, if I feel that my custom solution may compromise the data in any manner.


If there is a 'C' library for the NUT Client (the code used by UPS manufacturers, like APC) then I can easily make one Arduino that uses a USB to Serial converter and interfaces to my FreeNAS.


Thanks for inputs so far!

Regards, Pj
 

wblock

Documentation Engineer
Joined
Nov 14, 2014
Messages
1,506

anodos

Sambassador
iXsystems
Joined
Mar 6, 2014
Messages
9,554
Please give a model number.

I was going to make a snarky comment, but then I realized that the BE350G lacks a comm port. WTF, APC!

One other option is to get something like the Ubiquiti mpower adapter and plug the UPS into it. Install the controller software in a FreeNAS jail, then script it so that if the mpower adapter goes offline for more than a couple of minutes, the unifi controller will send a command via SSH to the freenas server to shut it down.

Overkill? Probably, but on the bright side you'll be able to buy other mfi sensors and install them around the house / server room (motion, temperature, door sensors). You can do everything from simple environmental monitoring to full-on "big brother".
 
Status
Not open for further replies.
Top