
I like solving problems with technology. I had an excellent opporutnity when one of the AC units that cools the server room malfunctioned and dumped several gallons of water onto the storage room floor, which also flowed under the wall and into the hallway.
Perhaps even more distressing was that there was no apparent cause of the malfunction, it was exactly that. There is a tank of water that is periodically purged and refilled, and for reasons unknown either the pump that discards the water decided not to come on, or the valve that closes after the purge cycle stayed open. The AC tech manually forced several purge cycles and we were unable to reproduce the problem.

So what worries me is, what if this happens again? I was was only able to notice the problem because I happened to walk by the storage room and simulaneously saw the water in the hallway and heard the pitifully quiet water alert beeping from inside.
What if it happens at night? What if it happens on a weekend? The entire suite could be flooded! Something must be done. We need a way to know when there is water on the floor, and more than just a beep, we need an email or SMS message alert, and we need it to be cost-effective. They do sell water detecting devices of various kinds for a pretty penny, and none that will send you an email. So what to do? Innovate!

Clicking a button is nothing more than shorting or connecting two contacts. Guess what is cheap and has clickable buttons? A mouse! And guess what is an excellent conductor? Water! I took a long piece of cat5 networking cable and soldered it to the contacts of the right mouse button.
By converting or extending the mouse button contacts into a simple wire pair, water can connect them and do the same thing as clicking the mouse button. Now we just need a way to read the mouse click. And guess what can do that and also satisfy our need to be able to connect to the CLI network and send an email message. A laptop! We definitely have some old barely working laptops, that while no longer suitable for normal use, will work just fine for this. I took an old laptop (had a broken display but the mouse and network port work just fine) and installed Linux on it.
Now all I need is some software that can read when a mouse button is pressed down (equivalent to the wires being wet) as well as when the button is released (wires dry). I came up with the following perl script:
#!/usr/bin/perl
# This script will detect the state of mouse button
# blazer0x at gmail.com
my $data;
my $fd;
my $buf;
my $mousedev=”/dev/input/mouse0″;
use POSIX;
$fd = POSIX::open($mousedev, &POSIX::O_RDONLY) || die (”Cannot open $mousedev: $!”);
while($data = POSIX::read($fd, $buf, 1))
{
my $DATA=join(”", map(sprintf(”%x”,ord($_)), split(//, $buf)));
my $DATE=scalar localtime();
if ($DATA =~ /8/) {
`echo “Water event ended (mouse button released) at $DATE\n”| mail -s “WATER ALERT (recovered)” sysalert\@myjob.com`;
}
if ($DATA =~ /a/) {
`echo “Water event started (mouse button pressed) at $DATE\n”| mail -s “WATER ALERT” sysalert\@myjob.com`;
}
}
I wish figuring out how to read the mouse button data was as simple as the length of the program suggests. There is a multitude of programming libraries and built-in functions for reading mouse input while running the GUI, but in this case I cannot run the GUI as it would interfere with my reading of the mouse (the GUI wants control of it). So I had to resort to reading the raw mouse device and parsing the data that comes from it when the buttons are pressed. After trial and error and lots of testing I was able to determine there is a certain byte of data that is only seen when the button is pressed, and another unique byte that is seen when the button is released.
Putting it all together, we have a laptop, with a hacked mouse that has a long network cable soldered to one of the buttons, with some software reading the state of the buttons. When the end of the network cable gets wet, it connects the wires, which the software detects as the button being held down. The software then sends an email alert. Once the water is gone, the software sees this as a button release, and that event is dealt with in a similar manner. The final version will log the water events to a log file and integrate into our main systems monitoring that monitors all of our servers.
I love solving problems with technology. In this case I was able to solve the problem of; “How do you detect the presence of water in an area, and send an email?” My solution was to build a Linux-powered TCP/IP networked remote water sensor. Price: Free. Learning experience and fun doing it: Priceless.