A jeenode ROOMS database

I've given in - and from now on I'll use a MySQL database to continuously store all the readings from the various ROOMS sensors dotted around the house.

The database is very simple :

201008150922.jpg

(Click for larger)

For those who wonder about the first field (id) - it's there to make usage in Ruby on Rails easier for a novice like me.

And to get the data out - here is a simple code example in Ruby

----------

require 'rubygems'
require 'active_record'

ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "127.0.0.1",
:database => "xxx",
:username => "xxx",
:password => "" )

class Rooms < ActiveRecord::Base
# set_primary_key "timestamp"
end

node = 35
#start_time = "Sat Aug 14 00:00:00 +0100 2010"
end_time = Time.now
start_time = end_time - 1.day
linje = Rooms.find(:all, :order => "rooms.timestamp asc", :conditions => [ "node = ? AND timestamp > ? AND timestamp < ?",node, start_time.to_datetime, end_time.to_datetime])

linje.each { |l|
puts "At " + %{#{l.timestamp} payload was #{l.payload} for node #{l.node}}
}

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.