Main Menu

Contact Andrew Quinn

jaquinn@ihug.co.nz http://twitter.com/jaquinn
DSL502T + Ruby + Webrick + YAML = DIY Monitoring Appliance
Written by Administrator   
Friday, 02 April 2010 09:00

At the top of the hill on my rural property is a bore that provides stock water for my stock and three neighboring properties.

So what does this have to do with DLink DSL502T routers, Ruby, Webrick and YAML?

From time to time faults in the various farm system drain water from the header tank faster than the bore pump can pull water out of the ground.... so the pump runs continually.  Expensive on power but also potentially damaging.  Normal use is about 1 hour per day in summer, much less in winter.

The problem was how to know if the pump was running excessively without climbing the hill.... and even if I did check it was hard to know if the pump was running because it had just reached to refill point or had been running for three days.

A couple of years back I built a bore monitor that used an IR beam to determine of the bore pump was running and could be queried over the wireless network by a ruby application.  By querying every 5 minutes and storing the data in a MYSQL database I could graph daily usage over time and see when things had gone awry.

The network connection in the original design was performed using an AVR AT90S8515 and a Packet Wacker ethernet interface.  For 2 years this worked well and then the Packet Wacker died.

Around this time i had been playing with DSL502T's to provide Amateur Radio IGate services and had a build environment configured for the OpenWRT firmware.   Included in the OpenWRT packages is Ruby and I know I could easily write a ruby program with a web interface (using Webrick) and simple data storage (using YAML) so replace the original monitor board.

It took some playing but I was able to build OpenWRT with Ruby and the required modules for Webrick and YAML to operate with the following configuration:

make menuconfig

With the following options:

Target System = TI AR7 [2.6]
Target Profile = No WiFi
Target Images = squashfs

Base System = base-files, br2648ctl, busybox, dropbear, hotplug2, libgcc, libpthread, libstdcpp, mtd, opkg, uci, uclibc, udevtrigger

Network = atm-tools, wget
Library = (none)
IPv6 = (none)

Kernel Modules = kmod-ipt-core, kmod-ipt-nathelper, kmod-sangam-atm-annex-a, kmod-ppp, kmod-pppoa, kmod-pppoe, kmod-ocx

Utilities = gpioctl

Languages = ruby, ruby-core, ruby-erb, ruby-irb, ruby-openssl, ruby-webrick, ruby-yaml

The ruby-erb and ruby-openssl libraries are required in addition to ruby-webrick if you actually want webrick to work.  Not including these libraries will cause errors when you require 'webrick' in your ruby code.

I have not attempted a minimum size configuration here... it is highly likely when not used as a modem that modules such as kmod-pppoa, kmod-pppoe and kmod-sangam-atm-annex-a can be excluded.

It's not blindingly fast serving pages but as a stand alone monitoring appliance interfaced to data collection sensors via the onboard serial port and providing a simple web interface showing the current status and historical trends it does the job for me.

Another great use for $1 modems.  Time to buy a few more for the stockpile.