Thursday, August 28, 2008

Slug and Syslog Server

One thing I miss about having the web server on the Slug, is having logfiles. Since it's running on a USB flash drive, I've turned off logging for everything so I don't kill the flash. I finally got around to setting it up to use a syslog server and pointed it at my HA box.

To do this, I edited /etc/syslog.conf on the Slug, setting DESTINATION to "remote" and REMOTE pointing to the HA server.

DESTINATION="remote" # log destinations (buffer file remote)
MARKINT=60 # interval between --mark-- entries [min]
REDUCE=no # reduced-size logging
BUFFERSIZE=64 # buffer: size of circular buffer [kByte]
LOGFILE= # file: where to log
REMOTE=aaa.bbb.ccc.ddd:514 # remote: where to log
FOREGROUND=no # run in foreground (don't use!)

In /etc/lighttpd.conf, I set up some conditionals for access logging:

$HTTP["url"] !~ "(\.css|\.js$)" {
$HTTP["remoteip"] != "aaa.bbb.ccc.0/24" {
accesslog.use-syslog = "enable"
}
}

Anything other than .css and .js files viewed from anywhere but my LAN will get logged. Cool.

Finally, I played around with few free syslog servers. None of them did what I wanted so I wrote my own in Perl. It's very simple so far and not very efficient with the logfile handling, but it works for now:

use warnings;

use IO::Socket;
use IO::Select;
use Sys::Hostname;

$port = 514;

$socket = IO::Socket::INET->new(
Proto => 'udp',
LocalPort => $port,
);
die "Could not create socket: $!\n" unless $socket;

print "syslog server\n";

while (defined($socket)) {
recv($socket,$msg,1500,0);
@msg=split(' ',$msg);

if ($msg[11] ne "") {
print "$msg[1] $msg[2] $msg[3] $msg[4] $msg[7] $msg[11]\n";
}
open(SYSLOG,">>./syslog.txt");
print SYSLOG "$msg\n";
close(SYSLOG);
}

close($socket);

Thursday, August 21, 2008

Slug Online

I ended up ditching Unslung for OpenSlug, mainly because OpenSlug has drivers for the EdgePort USB to serial adapter. (I'm planning on getting another Slug to use as a minimal HA controller for monitoring our other house.) I also dropped Apache for the lighttpd which has a smaller memory footprint. I dropped the idea of Squid as I ended up using my home router as a SOCKS proxy over SSH. I've got my Slug running off a 1GB flash drive and it uses a meager 4-5 watts! I had tested it running an 40GB USB hard drive and together, it used about 13 watts. The 466 MHz Celeron that has run the webserver for years uses about 35-40 watts, but that will get shutdown when I iron out a few remote access issues. The Celeron box currently is instrumental in accessing the home network and I hope to move that functionality to the firewall. It is no longer a webserver, as the Slug is doing that as of today.

Tuesday, August 19, 2008

Playing With The Slug

I received the NSLU2 yesterday and had a few cycles to play around with it. I flashed it with the latest Unslung firmware. That was pretty easy. I checked out a what packages are available to see what I could put on it. I installed OpenSSH, my public key. I also installed Apache as I'm pondering replacing my public webserver (running on a 466 MHz Celeron) with this. Finally, I did the overclocking mod to boost the Slug's CPU frequency from 133MHz to 266Mhz. Apparently, the unit I got was an older rev. I'm also looking into installing Squid as a proxy, not a cache, since I use my current webserver to proxy web traffic from work inside an SSH tunnel. I'm not sure if this will have the power to proxy better than the Celeron box.

Friday, August 15, 2008

Slug On The Way

I bought a Linksys NSLU2 (aka Slug) off eBay the other day. I took advantage of the Microsoft Live 25% Cashback promotion and saved a little extra. I'm not sure what I'm going to do with it, but I'm going to play around with Unslung and build a cheap, low power server out of it.

Monday, August 11, 2008

HA Burnout

I haven't been up to much with HA the last few weeks. I did a year's worth of projects in 1.5 months, and I've run out of ideas for projects I want to do. I did finish up xPL Gameport, but I haven't bundled it up for download yet. Not sure if I'll be doing much in the next couple months as we're contemplating some other much more costly home projects...

Thursday, July 24, 2008

DNS Exploit Loose - Check Your DNS Server

To the 2 or 3 people that read my blog, make sure your DNS is secure. There is an exploit in the wild that can poison DNS settings (steering you to a malicious site instead of your banking site for example). Read this article for more details. There is a link to a DNS checker or better yet, just switch to OpenDNS. I've been using OpenDNS for years now. You should also look into using NoScript if you're running Firefox. It's an addon that only allows Javascript to run from sites on your whitelist. It's a pain in the ass at first because you have to whitelist everything you usually use, but it's one of the best ways to secure yourself from malicious websites (although if your DNS is poisoned, you're out of luck).

Tuesday, July 22, 2008

A Busy Month and a Half!

Wow. I just looked back at my archives and I've been busy the last 1.5 months! What I've done:

- Kicked off the addition of UPB by installing a UPB coupler
- Updated my xPL sCU bridge into a full xPL/xAP/sCU bridge, making this my xPL/xAP scripting engine and phasing out xAP floorplan
- Wrote an xPL app to send TTS to 3Com Audreys
- Put a full scripting engine into xPLHALi
- Wrote a HALi client/server app that passes VR from client HAL machine to server HAL machine and passes responses back down, which can be spoken in client HAL voice or SAPI voice.
- Deployed several UPB modules and integrated UPB functionality into sCU and xPL sCU by writing code to communicate with a UPB serial interface. Integration with X10 is seamless.
- Wrote xPL gameport app as a poorman's method of getting contact closures into the system (and learned some DirectX)
- Installed USB Cat-5 extender to connect HA server to gameport in the garage
- Deployed 8 1Wire sensors and converted system over from using LM34s
- Wrote 1Wire VB.net app using TMEX API to poll sensors and dump values into a mySQL table

That was fun! Now I'm wondering what else I'm going to work on next...

Saturday, July 19, 2008

1Wire Serial Adapter Hates EdgePort

Since I've had the 1Wire network running, I've encountered a few fatal system errors that caused an immediate reboot of my HA server. Digging in the Event Viewer, I found messages like this:

Error code 00000044, parameter1 89422548, parameter2 00000d63, parameter3 00000000, parameter4 00000000.

I Googled a bit and found that error code corresponds to a memory problem or a driver issue. I stumbled upon a thread that told about how to read minidump files created by crashes. The dump file pointed to the EdgePort and the most likely culprit was a Java application. That points to the 1Wire stuff since its OWAPI is based on Java and the DS9097U adapter is plugged into the EdgePort.

Rather than take the easy way and move the 1Wire to the motherboard's built in serial port, I decided to write a VB.net app to talk to 1Wire adapter using the TMEX API. This way, I could avoid using all of the convoluted Java/J# crap. The problem with this path is there wasn't a VB example to get the temps, but there was a Delphi example. Ugh. Finally, I managed to cobble the Delphi and VB sample code into one VB.net program to connect to the 1Wire network and read the temperatures. About 7 hours after deploying that, I got another fatal pointing to the EdgePort. Guess it's not the Java part of the 1Wire after all.

So I connected the DS9097U to the onboard serial port and moved the TC+ to the EdgePort. It's been 12 hours without a fatal reboot. Hopefully, this solves the problem.

Update: It's been over 3 days since I moved the DS9097U and there have been no crashes since. Yay!

Thursday, July 17, 2008

Noisy 1Wire Readings

Of the 8 sensors I installed, the last one on the chain fluctuates a little between readings. It's not bad, just not as accurate as the other 7 sensors. What's different about this one?

It's at the end of the 1Wire line - could there be signal issues? I originally wanted to create my 1Wire network in a star pattern as that would be the easiest to wire from the patch panel, but the 1Wire docs advised against it. So I ran the network as 1 giant wire with each sensor as a stub. I actually used 4 wires to run them (voltage and ground since I decided against powering them parasitically and a wire for network in and network out). I chose this method to control the length of the stubs - otherwise the stub length would be the wire distance from the patch panel to wherever the sensor is located, which would vary for each location as each Cat-5 run is some different, unknown length. This, of course, increases the network length, but should be well within the 700 meter limit.

The sensor is also the only one outside. It's installed sticking out of the wall of our enclosed porch. It was exposed, but after seeing the fluctuations, I covered it up with electrical tape. It still fluctuates. I tucked it behind the porch speaker. It still fluctuates. I'm not sure what else to try at this point. Maybe that's the way it is outside?



Here's an RRD graph of the master bedroom temperature vs. the outside temperature. Starting Wednesday evening, after I got all the graphing and data gathering correctly set up, you can see the very smooth curve for the master bedroom sensor. The outdoor sensor, however, has fluctuations, on the order of a degree or more at times. The readings are accurate - they just don't make for a pretty picture.

Wednesday, July 16, 2008

1Wire Installation Completed

I put in the final four sensors Monday night and started trying to integrate things into the system. I decided to have the temps dumped into mySQL and all other applications can get the temps for there. For now, I've modified the GetTemps.js jscript sample from the 1Wire SDK to poll the sensors, update their values in mySQL and then sleep for 5 minutes.

My next step is getting the temps into the TimeCommander+ since it controls HVAC. The TC+ previously relied on the LM34 sensors connected directly to its analog inputs, so it directly knew the temperatures around the house. With 1Wire, I had to create variables in the TC+ for the temperatures it needs and have starCOMUltra periodically update them.

Finally, I had to update my RRD scripts for graphing temps. Since the 1Wire temps are digital values, there's no need to do any smoothing or error checking that I occasionally had to do with the analog LM34s. Once I had the RRD scripts up and running, I was able to see how nice 0.1 degree accuracy looks. I happened to have 2 DS18B20s, while the others were different flavors of DS18S20s. The rooms with the more accurate DS18B20s had much smoother curves compared to the DS18S20s with their 0.5 degree accuracy. I discovered, though, that you can calculate more accurate values using extra data bits stored in the device. I just added that code to my script and set it off running.

Monday, July 14, 2008

1Wire Deployment

The last few days, I started deploying 1Wire temperature sensors around the house. I've had the serial port interface and a bunch of DS18S20 sensors lying around for a while but I never got around to installing them. Our current system uses LM34 sensors hooked to the analog inputs of the JDS TimeCommander+, but they only have 2 degree accuracy and I've lived with that for 10+ years. Since I've been on my automation surge of late, I figured it was time to install the 1Wire stuff.

I tried putting the serial interface on an EdgePort at the end of the extended USB run in the garage, but for whatever reasons, the PC was unable to communicate consistently with it. It ended up back in the office, near the HA server. I decided I was going to gradually phase them in, which meant leaving the LM34s wired and running, while I tested out 1Wire. This made me clear out more wires in the wiring closet, at least temporarily, until I can shut down the LM34s. While I was cleaning that up, I decided to map out every wire in each of the 15 Cat-5 cables connected to the patch panel. (When we bought the house in 1999, 15 runs of Cat-5 seemed plenty. Now, I know better... *sigh*). I was able to free up some extra wires everywhere I needed them.

After the cleaning and mapping was done, I had time to solder and wire up 4 sensors - the living room, the master bedroom, the office and our daughter's room. There's still our son's room, the family room, the garage and outside left to do. If there's extra sensors, and I'm feeling adventurous drilling holes and running wire, I may try putting one in the attic.

Installing the 1Wire software wasn't as easy as the wiring. The 1Wire API, OWAPI, is some Java stuff and it relied on the Microsoft JVM, which they are no longer allowed to distribute. Anyway, after digging around the 'Net and iterating on the install process, I was able to get OWAPI operational. I had planned to integrate this all into starCOMUltra, but there's so much lag polling the sensors, I'm probably going to write a separate app to poll the sensors. I'm leaning toward making it directly interface it to sCU instead of using xPL as an intermediate step.

Thursday, July 10, 2008

New USB Cat-5 Extender

I grabbed a couple USB extenders ( called Remote KVM USB Extender up to 300 FT CAT5 ) from this seller on eBay and they arrived yesterday. I was going to test connecting the gameport in the garage to the HA server in the office. I already have 3 runs of Cat-5 in the garage, but they are all used for various things. The guest room is adjacent to the garage and I pulled wires from its closet into the garage before. Luckily I had one full Cat-5 cable left and that was used to connect the gameport in the garage to my homemade USB extension over the Cat-5 cable into the guestroom.

In the office, I connected one end of the new USB extender to my HA server and the other to a Cat-5 cable, connected that to the patch panel that led to an unused jack in the nook area. From the nook wall plate, I rolled my own Cat-5 cable (stripped off the wire casing) and ran it under the rug to the guestroom closet. I terminated that end and connected it into the receiver of the USB extender. Finally, I plugged in a powered USB hub and connected the gameport to it. While I was doing that, I also moved the bluetooth adapter into the closet and plugged that into the USB hub.

Everything showed up in the device manager and I started up the bluetooth and gameport apps. It's running great so my next project may be to put an EdgePort USB to Serial device on the hub and move the RFID reader here (or into the garage if I put a hub in there). I am also looking at using 1Wire instead of the LM34s I use for temperatures - and may end up putting a 1Wire serial adapter on the EdgePort as well.