Archive for the ‘Technical’ Category

I put together a 1-wire temperature sensor with a Arduino board with Ethernet Shield. Every 5 minutes, it posts the current temperature to Pachube.com. Since there is only outbound connections, it works with firewalls and NATs with not port forwarding. It also has DHCP as I find hard coding IP addresses sort of a pain. I used a DS18S20 temperature sensor.

You can find the software at: http://fluffyhome.googlecode.com/svn/trunk/arduino/PachubeClientWithDHCP.cpp

First you will need to install the DHCP library from: http://blog.jordanterrell.com/post/Arduino-DHCP-Library-Version-03.aspx

And then install the 1-wire library and Dallas Temperature Control library which are both found inside the the zip file at: http://milesburton.com/wiki/index.php?title=Dallas_Temperature_Control_Library#Download

At this point you need to have an account on Pachube and create a manual update feed. The first data stream will be used for the temperature. Next you need to go in to the PachubeClientWithDHCP.cpp file and edit the API KEY and feed ID to match yours. You don’t really need to change anything else. If you have other Arduino with fake MAC addresses, you might want to check this one does not conflict.

The 1-wire bus is connected to Digital IO pin 8 on the Arduino and pulled high to the 5v power with a 4K ohm resistor. Pin 1 of the DS18S20 is connected to ground, pin 2 to the 1-wire bus, and pin 3 to 5v power. (Yah, I know about parasitic power but I have power so I used it).

Compile and install the software, connect up the Ethernet, and start it. That’s about it.

Useful LInks:

http://www.pachube.com

http://milesburton.com/wiki/index.php?title=Dallas_Temperature_Control_Library#Download

http://arduino.cc/en/Main/ArduinoEthernetShield

http://arduino.cc/

http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2815

http://fluffyhome.googlecode.com/svn/trunk/arduino/PachubeClientWithDHCP.cpp

http://blog.jordanterrell.com/post/Arduino-DHCP-Library-Version-03.aspx

Let me start by just ranting about how bad MRTG is. It is unquestionable the worst graphing program I have ever used. No auto scale, can’t to negative numbers, can’t have a y axis that does not start at zero, need I say more. Oh, yah, obtuse and confusing to use.

I’m using a venstar T1900 thermostat (http://venstar.com) along with insteon module from SmartLabs (http://www.smartlabsinc.com) over to a INSTEON controller connected to the Indigo software from http://www.perceptiveautomation.com.The first step is to get the temperature from the thermostat into the database on the system running the Indigo software. I do that with using a “Time/Date Action” in the Indigo software that runs ever 10 minutes and has an action type of “Execute AppleScript”. I use the following embedded script

All the code following in this blog post is license under the simplified BSD license (see http://www.opensource.org/licenses/bsd-license.php) if you want to use it.

set myThermostatName to “MainThermo” # you can find the name to put here in the Device screen in Indigo

tell application “IndigoServer”

set mainThermoDev to device myThermostatName

set myTemp to temperatures of mainThermoDev

set value of variable “mainTemp” to myTemp

set myHumidity to humidities of mainThermoDev

set value of variable “mainHumidity” to myHumidity

end tell

This causes the variables to be updated with the values from the thermostat. Any time they change, they get written to the database.

Next I have a shell script program that reads values out of the databases and puts them in weird format that MRTG wants. This script looks like

#!/bin/csh

setenv VAL ` sqlite3 -csv /Library/Application\ Support/Perceptive\ Automation/Indigo\ 4/IndigoSqlClient/sqlite_db ” SELECT var_value FROM variable_history WHERE var_name=’$1’ ORDER BY ts DESC LIMIT 1 ; ” `

if ( $VAL == false ) then

echo 0

else if ( $VAL == true ) then

echo 100

else

echo $VAL

endif

echo 0

echo 0

echo $1

exit 0

I call this script from the MRTG. My MRTG configuration has an entry that looks like

Target[mHumidity]: `/Library/WebServer/mrtg/scripts/mrtgGetVar.sh mainHumidity`

Options[mHumidity]: nopercent,growright,nobanner,integer,gauge,noo

Title[mHumidity]: Main Humidity

PageTop[mHumidity]: <h1>Main Humidity</h1>

YLegend[mHumidity]: Percent

ShortLegend[mHumidity]: %

LegendI[mHumidity]: Humidity

LegendO[mHumidity]: Humidity Index

MaxBytes[mHumidity]: 100

And the end result is a graph like

Humidity

I also have some triggers that happen when my office ligth goes on or off and set a variable called COfficeLight to true or false. The MRTG config looks like:

Target[cOffLight]: `/Library/WebServer/mrtg/scripts/mrtgGetVar.sh COfficeLights`

Options[cOffLight]: nopercent,growright,nobanner,integer,gauge,noo

Title[cOffLight]: C Office Lights

PageTop[cOffLight]: <h1>C Office Lights</h1>

YLegend[cOffLight]: TBD1

ShortLegend[cOffLight]: TBD2

LegendI[cOffLight]: TBD3

LegendO[cOffLight]: TBD4

MaxBytes[cOffLight]: 110

Produces a graph like

COffice Lights

Finally I have a python program to get weather information. This program requires the wether API for python to be installed (see http://code.google.com/p/python-weather-api/ ). The python program looks like

#!/usr/bin/env python

import pywapi

import string

import optparse

import sys

def main():

global options

optionParser = optparse.OptionParser(version=”%prog 0.1”,

description=”Get weather in format approperate for MRTG”,

usage=”%prog [options] city”)

optionParser.add_option(‘—verbose’,’-v’,action=’store_true’)

optionParser.add_option(‘—metric’,’-m’,

action=’store_true’,

help=”use metric values. Default is imperial”)

optionParser.add_option(‘—humidity’,”,

action=’store_true’,

help=”Return relative humidity instead of temperature.”)

options, arguments = optionParser.parse_args()

if ( len(arguments) != 1 ):

optionParser.error(“Must provide one city name such as ‘Calgary,AB’ “)

if options.verbose:

print “City is ” + arguments[0]

result = pywapi.get_weather_from_google( arguments[0] )

if options.humidity:

humRes = result[‘current_conditions’][‘humidity’]

hum = “%s”%humRes

if options.verbose:

print “Raw humidity string is ” + hum

h = int( float( hum.lstrip(“Humidity: “).rstrip(“%”) ) )

if options.verbose:

print “Parsed humidity is %d”%h

print “%d”%h

print 0

print 0

print “OutsideHumidity”

else:

if options.metric:

print result[‘current_conditions’][‘temp_c’]

print 0

print 0

print “OutsideTempCelcius”

else:

print result[‘current_conditions’][‘temp_f’]

print 0

print 0

print “OutsideTempFahrenheit”

return 0

if __name__ == “__main__”:

sys.exit(main())

and I use a MRTG config like:

Target[outsideHumidity]: `/Library/WebServer/mrtg/scripts/mrtgGetWeather.py —humidity “Calgary,AB” `

Options[outsideHumidity]: nopercent,growright,nobanner,integer,gauge,noo

Title[outsideHumidity]: Outside Humidity

PageTop[outsideHumidity]: <h1>Outside Humidity</h1>

YLegend[outsideHumidity]: Percent

ShortLegend[outsideHumidity]: %

LegendI[outsideHumidity]: Humidity

LegendO[outsideHumidity]: Humidity Index

MaxBytes[outsideHumidity]: 100

To get a graph like

Weekly Humidity

I wanted to publish some sensor data from my house up to pachube.

I used a venstar T1900 thermostat (http://venstar.com) along with insteon module from SmartLabs (http://www.smartlabsinc.com) over to a INSTEON controller connected to the Indigo software from http://www.perceptiveautomation.com.

First you need to create an account on pachube.com and create a new feed with two data streams. The first stream is temperature and second is humidity. Make sure the “Feed Type” is set to manual when you created the feed. From the pachube site, you need to get your API key and the feed ID for the feed you created. In the Indigo software, I created a “Time/Date Action” that runs ever 10 minutes and has an action type of “Execute AppleScript”. I use the following embedded script

The following code is license under the simplified BSD license (see http://www.opensource.org/licenses/bsd-license.php) if you want to use it.

# to use this script, you need to edit the next three lines with your API key, and URL for for your feed, and device name in indigo software for your thermostat

set myPachubeAPIKey to “PUT YOUR KEY HERE”

set myPachubeFeed to “http://www.pachube.com/api/feeds/1234.csv” # change to your key

set myThermostatName to “MainThermo” # you can find the name to put here in the Device screen in Indigo

tell application “IndigoServer”

set mainThermoDev to device myThermostatName

set myTemp to temperatures of mainThermoDev

set value of variable “mainTemp” to myTemp

set myHumidity to humidities of mainThermoDev

set value of variable “mainHumidity” to myHumidity

end tell

try

set myRes to do shell script “curl –max-time 10 –silent –show-error –request PUT –header ‘X-PachubeApiKey:” & myPachubeAPIKey & “‘ –data ‘” & myTemp & “,” & myHumidity & “‘ ” & myPachubeFeed

if myRes is not equal to ” “ then

log “Problem with posting to pachube. curl result is:” & myRes

end if

on error

log “Error execting curl to post to pachube.com: Result was ” & myRes

end try

#log “ran the temp log script temp=” & myTemp & ” humidity=” & myHumidity

You can get a google gadget on a web page to graph your feed by embedding the following code after changing the feedID from 1234 to whatever your feed is.

<script src=”http://www.gmodules.com/ig/ifr?url=http://apps.pachube.com/google_gadget/p.xml&amp;up_feedID=1234&amp;synd=open&amp;w=400&amp;h=300&amp;title=House+Temp&amp;border=http%3A%2F%2Fwww.gmodules.com%2Fig%2Fimages%2F&amp;output=js”></script>

The end result should look something like:

PhD

I was taking abuse about an existence proof of my PhD Thesis the other day so here it is:
http://www.dial911anddie.com/PhD/CullenJenningsPhDThesis.pdf

And the proposal for it is at:
http://www.dial911anddie.com/PhD/CullenJenningsPhDProposal.pdf

http://www.blueboxpodcast.com/2006/04/blue_box_podcas.html

Dan’s slides are at:

http://www3.ietf.org/proceedings/06mar/slides/raiarea-1/sld1.htm

or

http://www3.ietf.org/proceedings/06mar/slides/raiarea-1/raiarea-1.ppt

Outstanding Young Alumnus Award – UBC Alumni Association

See http://sourceforge.net/projects/srtp

Continue reading ‘Latest release of lib SRTP is out’ »

target="NewWindow">www.p2psip.org is now the top hit in google

Continue reading ‘For my P2P SIP stuff, go to www.p2psip.org’ »

Many people think they are pretty good at basic
statistics and probability theory. So give this one some thought

Imagine there are two drugs, A and B,
that might help cure a problem you have and you are given the following
information. 1100 people took drug A and it helped 505 of them. And 1100 people
took drug B and it helped 195 of them. I put this in the table below along with
the percentage of people where each drug was a success. Assume you can’t take
both drugs and that neither drug has any ill effect, risk, or cost from taking
it.

Drug | Successful | Failed   | percentage success
A    |    505     |     595  |   46%
B    |    195     |     905  |   18%

Which drug would you choose to take given this
information?

Now let me provide a little
extra information. In the study above, it turns out that for drug A, there were
100 males and it worked for 5 of them and for drug B there were 1000 males and
it worked for 100 of them. From this information, and a little subtraction, I
have filled out the two tables below.

For
males

Drug | Successful  |  Failed   | percentage success
A    |      5      |      95   |   5%
B    |    100      |     900   |  10%

For
females

Drug | Successful |   Failed   | percentage success
A    |    500     |     500    |   50%
B    |     95     |       5    |   95%

Continue reading ‘How good is your basic probability theory?’ »

I love the mobile phones guys – first they
trained users that lousy voice quality really was OK. Then they got people to
understand that when they were done pressing all the digits in a phone number,
they had to press some some other send key before anything would happen.

Continue reading ‘Mobile phones kill early media? One can only hope’ »

Continue reading ‘Photos from ReSiprocate Nov 04 coding session’ »

Continue reading ‘Clean up photographs of text documents in PhotoShop’ »

Continue reading ‘Why DRM will never work over an extended period of time’ »

Continue reading ‘The mastermind behind IPv6’ »