I have now had a Wattson power meter for more than a year – and although it now comes with software for the Mac this is IMHO not terribly useful for my purposes, so I wanted to read the Wattson in real time, and use a server to send the information to other programs around the house and outside it.
This fits into the house monitoring system I am building using Arduino microcontrollers both to collect data, and to display data. More about this in other posts.
But the necessary information is hard to come by, and the public API has been a long time coming.
Bu using a terminal emulator running on my laptop and the FDDI drivers i normally use for the Arduino I managed to communicate with the Wattson (19200 – N81 for anyone interested), and through various tests I found that if I send the command “nowp” to the Wattson, it returns a hex string containing the current power usage.
After discovering the “ruby-serialport” library I wrote a short (and very ugly) ruby program to retrieve the data at regular intervals and also to twitter these (at http://twitter.com/gisvoldhouse)
#!/usr/bin/ruby
#
# My first try at Ruby programming for the Wattson power meter
#
require ‘uri’
require ‘net/http’
require(‘rubygems’)
require(‘time’)
require ‘serialport’
gem(‘twitter4r’, ‘0.3.1’)
require(‘twitter’)
require(‘twitter/console’)
require ‘timeout’
$version = “0.1”;
$debug = false;
#params for serial port
port_str = “/dev/tty.usbserial-A4004sx2” #differs depending on your setup
baud_rate = 19200
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
sleep(2)
sp.write “nowp\r”
puts “Start”
begin
while true do
inn = ‘ ‘
sp.write “nowp\r”
inn[0] = sp.getc
inn[1] = sp.getc
inn[2] = sp.getc
inn[3] = sp.getc
inn[4] = sp.getc
if $debug then
puts inn
end
if inn.length < 6 then
inn2 = inn.slice!(1..4)
print Time.now.hour.to_s + ‘:’ + Time.now.min.to_s + “->” + inn2.hex.to_s + ‘W’
puts ”
sleep(2)
twitter = Twitter::Client.from_config(“/users/tor/.twitter.yml”,’house’)
message = “Power usage just now ->” + inn2.hex.to_s + ‘W’
twitter.status(:post,message )
sleep(0)
end
sleep(300)
end
end