-
11Compiling the “upsmon” application
Now try to compile the “upsmon” application:
gcc -o upsmon upsmon.c
There’s something unfortunate about the name of “upsmon”…the NAS already has an application by that name in the path. You may wish to use a different name.
-
12Deploying "upsmon" to the NAS
If successful compiling, you can do the following:
- Connect the Arduino via USB to the NAS
- Copy your upsmon application to a suitable place on the NAS
- Make sure your upsmon application has “execute” permissions:
ls -l
Much could be said about Linux/Unix permissions. I was satisfied to have any user on the system able to read/execute the application so I used permissions "755". Here you can confirm which users have execute ("x") permissions.
-
13A quick test of "upsmon" application
from the command line, type the following (use your port name instead):
[/share/Installers/QNAPUPSMon] # ./upsmon /dev/ttyUSB0 MONITORING /dev/ttyUSB0 Received 3 bytes buffer contains [OK ] Power is on! [/share/Installers/QNAPUPSMon] #
-
14Scheduling "upsmon" execution
The last thing we need to do is have the NAS’s “cron” application run our upsmon application at regular intervals. QNAP’s assistance was again helpful here.
I chose 1 minute intervals because I didn't see any need to keep my system running at all once a power outage has occurred.
You’ll want to be really careful when editing the "crontab" file because it's so important for the correct operation of your NAS and it's also quite intricate.
1. Type the following:
vi /etc/config/crontab
2. Add the following line: (it will run at one minute intervals)
*/1 * * * * /share/Installers/QNAPUPSMon/upsmon /dev/ttyUSB0
3. Save
4. Exit the editor
5. Restart cron
crontab /etc/config/crontab && /etc/init.d/crond.sh restart
-
15Final test
1. Connect up the Arduino as shown in the block diagram
2. Restart your NAS
3. Unplug your UPS
4. (NAS initiates shutdown)
5. (when NAS shutdown is complete, UPS is turned off as well)
-
16Possible adaptations
- Choose different polling intervals in "crontab"
- Choose different "shutdown rules" in the Arduino sketch (review sketch for details)
- Use "SoftwareSerial" to communicate with a more sophisticated (but still unsupported) UPS
- I wanted to have the cron job run my application from the “timeout” command like: (“timeout –s 9 60 [my_command_line_here]” to limit the amount of time that cron will allow the task to run) but it seems Debian and therefore QNAP doesn’t support this.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.