[ncolug] Re: Linux Home Automation

  • From: larry <larry@xxxxxxxxxxxx>
  • To: ncolug@xxxxxxxxxxxxx
  • Date: Sat, 15 Dec 2007 19:56:36 -0500

What does a firecracker module do?

Rob Gibson wrote:
So, having Time Warner Cable is both interesting and problematic at
the same time.

Every couple of weeks, the cable modem will decide to seize up for no
apparent reason.  When this happens, I have to walk over to the cable
modem, unplug it, and plug it back in.  This problem is most
irritating when I am not at home and able to reconnect it.

To solve this issue, I did some research and landed on the X10 series
of HA products.  I bought a kit which included the serial-driven
Firecracker module and a wireless transceiver.  Connecting the
equipment is "so easy a caveman could do it."  I just set up a house
code and turned on the transceiver.  After connecting the Firecracker
interface to my serial port, I grabbed the "bottlerocket" package from
the Debian repositories and installed it.

Some quick testing of the BottleRocket software led to the appropriate syntax.

Inspired by the last meeting, I wrote a shell script to monitor
network traffic and reset the device upon a number of failed pings to
google.

#! /bin/bash

ping -c 5 www.google.com &> /dev/null || echo "FAILURE" >> ~/.x10/$(date)
if [ $(ls -1 ~/.x10/ | wc -l) -gt 2 ]
then
        br -x /dev/ttyS0 X15 OFF
        sleep 5
        br -x /dev/ttyS0 X15 ON
        rm ~/.x10/*200*
fi

For the folks who want to know how this works, here's the quick pseudocode:

1. Set up the interpreter (/bin/bash).
2. ping Google's website 5 times, sending the output to the bit
bucket.  If the ping fails, create a file with a datestamped name and
the contents of "FAILURE".
3. List the files in a specific directory, with the files one per
line, and count the resulting number of lines.
4. If the number of files in that directory is greater than 2, execute
the following commands:
   a. Use BottleRocket to tell the module connected to the cable modem
to turn off, using the Firecracker attached to /dev/ttyS0
   b. Sleep for 5 seconds
   c. Use BottleRocket to power on the module connected to the cable
modem, with the same Firecracker module
   d. Remove the datestamped files from the working directory.
5. If the earlier test was false (2 or less files are in the working
directory), do nothing.

This script is then saved in my ~/bin directory, and I chmod u+x the script.

Finally, I am running the script every 5 minutes from my personal
crontab.  My cable modem should be inactive for less than 5 minutes at
any time.

For the shell-scripting gurus who inhabit the list, I know that my
next iteration will make at least a couple of changes:
1. I really don't need the word "FAILURE" in each of these files which
are soon-to-be deleted.  I could simply "touch" each file.
2. I probably should be setting paths a little bit more securely or
creating temporary files securely.  In its current form, an errant or
maliciously-placed symlink could overwrite anything I would otherwise
have access to through my standard login credentials.

I am also using the extra lamp module to connect the lamp near the
door to the x10 system.  At some point, I want to integrate Asterisk
so that I can call home and turn on the lights while I am getting
close to home.

If anyone sees any other improvements or suggestions which could be
made, I would be most appreciative.

Thanks,
Rob
----
Rob Gibson
nosbig@xxxxxxxxx
http://www.nosbig.net

To unsubscribe send to ncolug-request@xxxxxxxxxxxxx with 'unsubscribe' in the 
Subject field.



--
"When you sit with a nice girl for two hours,
you think it's only a minute. But when you sit on a hot stove for a minute, you think it's two hours. That's relativity." Einstein (1879-1955)


To unsubscribe send to ncolug-request@xxxxxxxxxxxxx with 'unsubscribe' in the 
Subject field.

Other related posts: