Windows SNMP UPS Support
Monday, 7. January 2008, 06:57:09
My last post went into my development of UPS support for the QNAP TS-109 Pro. I ended with the question of whether or not Windows support of my SNMP UPS monitor could be developed.
After a couple of days of frustration, the answer is Yes!
Windows has built-in support for UPS monitoring via a "minidriver" interface provided by a DLL.
The frustration started when I found I could not develop a DLL using Microsoft's C++ Express edition. Instead, I had to dig through my CD collection looking for an old copy of Visual C++ (5.0).
I haven't done any low-level Windows programming for ages, so it was a bit of a steep (re)learning curve figuring out how to setup DLL exports, manage threads and events, and do UDP network programming. My first attempt kept on crashing, until I found Microsoft's demo UPS driver, which worked fine. I copied my C code over that and suddenly my code started working fine too!
Obviously some magic in the demo build environment.
It's still not quite perfect, as for some reason no notifications are being shown, even though they're selected. However, once a low battery state is signaled, my PC shuts down!
The minidriver listens out for three types of APC SNMP traps: 9 (power good), 5 (on battery), and 7 (battery low). It doesn't care where the trap came from, so it may not be good on an untrusted network!
Below is a ZIP of my DLL, if anyone is interested. Right click on the INF and select Install. Probably not, as it's only good for APC SNMP notifications, in which case you'll already have proper APC software.
upsmon.zip (12KB)
For building, I can't help with the compiler, but the Windows Device Driver DDK is very handy, as is the MSDN documentation on Writing UPS Minidrivers!
After a couple of days of frustration, the answer is Yes!
Windows has built-in support for UPS monitoring via a "minidriver" interface provided by a DLL.
The frustration started when I found I could not develop a DLL using Microsoft's C++ Express edition. Instead, I had to dig through my CD collection looking for an old copy of Visual C++ (5.0).
I haven't done any low-level Windows programming for ages, so it was a bit of a steep (re)learning curve figuring out how to setup DLL exports, manage threads and events, and do UDP network programming. My first attempt kept on crashing, until I found Microsoft's demo UPS driver, which worked fine. I copied my C code over that and suddenly my code started working fine too!
It's still not quite perfect, as for some reason no notifications are being shown, even though they're selected. However, once a low battery state is signaled, my PC shuts down!
The minidriver listens out for three types of APC SNMP traps: 9 (power good), 5 (on battery), and 7 (battery low). It doesn't care where the trap came from, so it may not be good on an untrusted network!
Below is a ZIP of my DLL, if anyone is interested. Right click on the INF and select Install. Probably not, as it's only good for APC SNMP notifications, in which case you'll already have proper APC software.
upsmon.zip (12KB)
For building, I can't help with the compiler, but the Windows Device Driver DDK is very handy, as is the MSDN documentation on Writing UPS Minidrivers!
