From: Brian P. <br...@th...> - 2002-12-30 02:23:00
|
Here's what I use... To use it, you should be able to list your ibuttons at the top and then list the names of the rooms in the %ib_mapping hash. It will then read each of the ibuttons every minute (evenly distributed throughout the minute) Brian # Category = iButtons # Enable iButton support by changing the mh.ini ibutton_port parm. # You can buy iButton stuff here: # http://www.iButton.com/index.html # http://www.pointsix.com # # More info on coding iButton_Item is in mh/docs/mh.html # $ib_basement = new iButton '280000000ecb65'; $ib_home_theater = new iButton '1000080019c01f'; $ib_outside = new iButton '1000000054b5f3'; $ib_guest_room = new iButton '1000080019cf7c'; $ib_kitchen = new iButton '280000000ee739'; $ib_front_room = new iButton '1000080019ac36'; $ib_baby_room = new iButton '1000080019cd86'; $ib_master_bedroom = new iButton '1000080019b5ef'; $ib_office = new iButton '1000080019c79b'; $ib_family_room = new iButton '1000080019cb6d'; $ib_living_room = new iButton '280000000ee4b6'; my %ib_mapping = ( "basement" => $ib_basement, "home theater" => $ib_home_theater, # "outside" => $ib_outside, "guest room" => $ib_guest_room, "kitchen" => $ib_kitchen, "front room" => $ib_front_room, "baby room" => $ib_baby_room, # "master bedroom" => $ib_master_bedroom, "office" => $ib_office, "family room" => $ib_family_room, "living room" => $ib_living_room, ); my $locations = join( ",", sort keys %ib_mapping ); $v_iButton_connect = new Voice_Cmd "[Connect,Disconnect] to the iButton bus"; $v_iButton_connect -> set_info('Use this to free up the serial port or test the iButton start/stop cal ls'); $v_iButton_readtemps = new Voice_Cmd "Read all the temperatures"; $v_iButton_readtemps-> set_info('This reads all all iButton temperature devices. Takes a while (.6 s p er device)'); $v_iButton_readtemp = new Voice_Cmd "Read the [$locations] temperature"; $v_iButton_readtemp -> set_info('Read only the temperature from a specific button'); $v_iButton_list = new Voice_Cmd "List all the iButton buttons"; $v_iButton_list -> set_info('Lists the family and ID codes of all the buttons on the bus'); if ($state = said $v_iButton_connect) { print "$state the iButton bus"; if ($state eq 'Connect') { print_log &iButton::connect($config_parms{ibutton_port}); } else { print_log &iButton::disconnect; } } if ($state = said $v_iButton_readtemp) { my $ib = $ib_mapping{ $state }; my $temp = read_temp $ib; if ( !defined $temp ) { speak "Can't read $state temperature"; } else { my $t = int( $temp + 0.5); speak "$state temperature is $t degrees"; print_log "Temp for sensor $state: $temp F"; } } if ($New_Second and !($Minute % 1)) { my $device; my $checkSecond = int( 60 / (scalar keys %ib_mapping) ); if ( $Second % $checkSecond == 0 ) { $device = (keys %ib_mapping)[$Second / $checkSecond]; } if (defined $device) { my $ib = $ib_mapping{$device}; my $gotTemp = 0; for ( 1..5 ) { my $temp = read_temp $ib; my $ib_name = $device; $ib_name =~ s/ /_/g; if ( defined $temp ) { update_rrd($ib_name, $temp); logit("$config_parms{data_dir}/iButton_temps.log", "$device: $temp"); $gotTemp = 1; last; } } if ( !$gotTemp ) { # print_log "Error reading $device\n"; } } } if ( $New_Minute ) { run( "/home/brian/misterhouse/code/rrd_graph > /dev/null 2>&1" ); } # List all iButton temperatures. This can take a while if (said $v_iButton_readtemps) { print_log "Reading iButton temperatures"; my @ib_list = &iButton::scan('10'); # gets DS1920/DS1820 devices for my $ib (@ib_list) { my $temp = $ib->read_temperature_hires(); print_log "ID:" . $ib->serial() . " Temp: $temp C, " . ($temp*9/5 +32) . " F"; } @ib_list = &iButton::scan('22'); # gets DS1822 devices for my $ib (@ib_list) { my $temp = $ib->read_temperature_hires(); print_log "ID:" . $ib->serial() . " Temp: $temp C, " . ($temp*9/5 +32) . " F"; } @ib_list = &iButton::scan('28'); # gets DS18B20 devices for my $ib (@ib_list) { my $temp = $ib->read_temperature_hires(); print_log "ID:" . $ib->serial() . " Temp: $temp C, " . ($temp*9/5 +32) . " F"; } } # List all iButton devices if ( said $v_iButton_list ) { my $report = &iButton::scan_report; my @lines = split /\n/, $report; foreach my $i ( @lines ) { foreach my $j ( keys %ib_mapping ) { my $serial = $ib_mapping{ $j }->serial(); if ( $i =~ /$serial/ ) { $i .= " $j"; } } } $report = join( "\n", @lines ); my $ibuttonlist = "List of ibuttons:\n" . $report; $ibuttonlist =~ s/\n/\n\<BR\>/g; print_log $ibuttonlist; } sub update_rrd { return unless $config_parms{rrd_dir}; my ($sensor, $temp) = @_; my ($rrd_file, $rrd_error); $rrd_file = "$config_parms{rrd_dir}/temp/$sensor.rrd"; # print "Storing $sensor data=$temp in $rrd_file $Time:$temp\n"; RRDs::update $rrd_file, "$Time:$temp"; print_log "RRD ERROR: $rrd_error\n" if $rrd_error = RRDs::error; } On Sunday, December 29, 2002, at 06:57 PM, Nigel Titley wrote: > On Sun, 2002-12-29 at 22:47, Gary Sanders wrote: >> Nigel Titley wrote: >>> >>> I do this by cycling around the sensors reading one each 2 minutes. >>> This >>> seems to be acceptable. >> >> >> Yes, I could do that, but I really need 2 minute resolution on each of >> the sensors, as I'm trying to determine a HVAC problem here at home, >> and >> the resulting 14 minute resolution wouldn't give me enough >> information. > > Fair enough :-) > >> >> Gary Sanders >> >> >> >> >> ------------------------------------------------------- >> This sf.net email is sponsored by:ThinkGeek >> Welcome to geek heaven. >> http://thinkgeek.com/sf >> ________________________________________________________ >> To unsubscribe from this list, go to: >> http://sourceforge.net/mail/?group_id=1365 >> >> > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > ________________________________________________________ > To unsubscribe from this list, go to: > http://sourceforge.net/mail/?group_id=1365 |