From: Michael B. <bro...@ya...> - 2005-11-21 14:11:50
|
Guy Gibson wrote: > Mike here is a copy of the code so far. > > Guy [snip] Comments in-line... I'm looking at it fairly high-level right now, from the point of view that someone might want to use oww in daemon mode as a replacement for the built-in iButton code, or a mh/digitemp solution. OWW has device support that the author of digitemp has stated that he doesn't want to support (ie, datalogger devices like the HygroChron). OWW could be started as a daemon from the mh start-up script, and give someone a very extensible temperature and humidity monitoring solution, without having to do something like mh proxying. > OWW txttcpreport functionality > > This version should work with all OWW using the txttcpreport. This > allows a more sensors to be reported than with arnetcpreport. You can > also configure what sensors and the format you want. This example uses > > 1-wire weather station V3 > 1-wire rain guage > 1-wire humidity sensor (indoor) > 1-wire humidity sensor (outdoor) > > The following format for the txtfrom parameter in the .owwsetup(NG) file > was used. Guy, what would you think about having all the 1-wire Weather station paramaters up-front as a standardized set-up, and then you could have the code check for a Config parm of oww_ws_present = yes? That way, if someone wants to use oww for internal sensors only, they can simply turn off the ws reporting coming into mh. If they later get a ws, then they can simply change that config parm, and reload code. In my particular case, I'm a stone's throw from our International Airport, and I'm pulling in the outdoor weather hash stuff from Matthew's excellent METAR report. But I might add a weather station sometime in the future, $money and WAF (Wife Acceptance Factor) permitting. > txtform $tc1%4.1$ $dpc1%4.1$ $trhc1%4.1$ $wspkph%5.1$ > $wspmaxkph%5.1$ $wdrpoint%3$ $rainratemm%4.2$ $rainmm%5.1$ > $rainintmm%3.2$ $rh2%3.1$ $rh1%3.1$ I left mine as default (to play with), then added my sensors after the fact... txtform $localtime%d/%m/%y , %H:%M:%S$ , $tc1%7.1$,$wsp%7.2$ $wspunit%5$,$wdrname%10$ $wdrdeg%5.1$ $wdrpoint%3$,$rain%5.2$ $rainunit$,$tc3%7.1$,$tc4%7.1$,$trhc2%7.1$,$rh2%7.1$ TC1 and RH1 are assigned to the weather station. Obviously, we could come up with a "standard" set-up definition, that would cover the majority of things, and then users could add their stuff in after the standard config. If the timestamps aren't needed, they can be turfed. People could do a lot of the set-up in OWW, and we could always pull in the config based on the units shown in the txtform report (tempunit, windspeedunit, etc). Just a thought... I'm new to perl, so I don't know if that's a wise thing to do or not... I'm just firing off ideas for making it general while being easy to maintain code-wise. [snip] > The following are the variables transmitted from the OWW server in txt > form: > > current_out_tempC(Anemometer) dewpointC current_in_tempC > current_windkph wind_gust_kph wind_dir rainrate_mm rain_mm > rain_lasthrm humiduty_outside humidity_inside > > where > 0 current_out_tempC is current outdoor temp in C > 1 dewpointC is current dewpoint outside in C > 2 current_in_tempC is current indoor temp in C > 3 current_windkph is current wind speed in kph > 4 wind_gust_kph is peak wind speed in kph > 5 wind_dir is the current wind direction > 6 rainrate_mm is the current rain rate in mm/hr > 7 rain_mm is the rain total since last reset (month) > 8 rain_lasthrmm is the current rain in the last hour > 9 humidity_outside is the current huidity outside > 10 humidity_inside is the current humidity inside In my case, tc3 and tc4 are my kid's bedrooms, and trh2 and rh2 (in C) is my indoor HydgroChron. I'll be adding other sensors soon, like master bedroom, upstairs, basement, etc... I've been more concerned with watching the kid's room's right now, being that we have a 2 year old and a baby on the way. [snip] > =cut > > my $owwhost = $config_parms{owwserver_host_port_txt}; > $owwhost = "localhost:8891" unless $owwhost ; > > $ibws = new Socket_Item(undef, undef, $owwhost, 'ibws', 'tcp', 'raw'); > > $ibws_v = new Voice_Cmd "[Start,Stop,Speak] the ibutton weather station > client"; > $ibws_v-> set_info('Connects to the ibutton weather station server'); > > my $metric = ($config_parms{default_temp} eq 'Celsius'); > > # REF var refs 0 1 2 3 > 4 5 6 7 8 9 10 > 11 12 13 Would a comment here about the standard functions available in the mh weather hash/rrds vars be appropriate to help with mapping? > my @weather_vars = qw(TempOutdoor DewOutdoor TempIndoor WindAvgSpeed > WindGustSpeed WindDir RainRate RainTotal RainHour HumidOutdoor > HumidIndoor WindChill WindGustDir WindAvgDir ); Pardon my newness to perl... could the @weather_vars be listed on seperate lines, with comments after? That could make it clearer for those who need to customize... for example my @weather_vars = qw(TempOutdoor # Ref 0 DewOutdoor # Ref 1 TempIndoor # Ref 2 Or could they be listed just on seperate lines if the comments would cause perl to barf? Again, pardon my newbie-ness! > # Ref dir nos 0 1 2 > 3 4 5 6 > 7 8 9 10 > 11 12 13 14 15 my > @direction=("North","North North East","North East","East North > East","East","East South East","South East","South South > East","South","South South West","South West","West South > West","West","West North West","North West","North North West"); > my > @directionshort=("N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"); Below, the $freezing below is being calculated in degrees F. Might need a if ($metric) version... > my $freezing = new Weather_Item 'TempOutdoor', '<', 32; > my $chill = 0; > my $pchill = 0; > my $chillwthresh = 3; # thresholds for calculating wind chill > my $chilltthresh = 50; > my $i = 0 ; > > if ($metric) { > $chillwthresh = 6.5; > $chilltthresh = 10; > } > > set $ibws_v 'Start' if $Startup; > > if (time_cron '31 9-23 * * *') { > run_voice_cmd 'Start the ibutton weather station client'; > } > > #if (time_cron '0,15,30,45 7-21 * * *') { > # run_voice_cmd 'Speak the ibutton weather station client'; > #} > > if (my $data = said $ibws) { > > print_log "ibws server said: $data"; > > my @data = split /\s+/, $data; # Split up the individual > Data elements > > # > ---------------------------------------------------------------------------- > > # ------ COLLECT and Sort the Data ------- Might want a comment here about changing the "< 11" to the number of elements in the weather_vars array, depending on how things get implemented. I'm guessing the -1 is to ensure the counter hits 0 on it's way by... > for ($i = -1; $i < 11; $i++) { # ???????? -1 ??????????? > # print_log "Processing data at $i which is $weather_vars[$i] value > of $data[$i]"; > my $key = $weather_vars[$i]; # Get the Name of the data key > > if ($i < 3) { # 0-TempOutdoor 1-DewOutdoor > 2-TempIndoor > if ($metric) { > $Weather{$key} = $data[$i]; > } > else { > $Weather{$key} = convert_c2f $data[$i]; # If you must > } > } > > if (($i == 3) || ($i ==4)) { # 3-WindSpeed 4-WindSpeedGust > if ($metric) { > $Weather{$key} = $data[$i]; > } > else { > $Weather{$key} = $data[$i] * 2.237415; # Whats a > mile! Oh a victorian measure > } > $Weather{$key} = sprintf("%.0f",$Weather{$key}); > } > > if ($i == 5) { # 5-WindDir > $Weather{$key} = $data[$i]; > # print "key = $Weather{$key},data = $data[$i], i= $i \n" ; > } > > if (($i > 5) && ($i < 9)) { # 6-RainRate 7-RainTotal > 8-Rainhour > $Weather{$key} = $data[$i]; > } > if (($i == 9) || ($i ==10)) { # 9-HumidOutside > 10-HumidInside > $Weather{$key} = $data[$i]; > } > > } > > $Weather{WindAvgDir} = ( $Weather{WindDir} * 22.5 ); #convert to rrd > degrees > $Weather{WindGustDir} = $Weather{WindAvgDir} ; # Because rrd wants > this and we dont have it > # print "Weather Dir $Weather{WindAvgDir}\n"; > # } else { > # print_log "Bad ibws data, $i datapoints"; > # } > } > # > ---------------------------------------------------------------------------- > > > # print "Out $Weather{TempOutdoor} / Out Hi $Weather{TempOutdoorHigh} > / OutLow $Weather{TempOutdoorLow} F"; > # print "WindDirAv $direction[$Weather{WindDirAvg}] Wind > $Weather{WindAvgSpeed} / Peak $Weather{WindSpeedPeak} mph \n"; > > # Update the Web Page Data > Here could be one area where an if_oww_present = y could be used to discard the outdoor weather information if the ws is not present... unless that needs to be done above, as things are broken out of the data array. > # this is the standard short summary for the web interfaces > if ($metric) { > $Weather{Summary_Short}=sprintf("%3.1fC in|%3.1fC out|%3dC wc|%3d%%RH > in|%3d%%RH out", # Mark's > $Weather{TempIndoor}, > $Weather{TempOutdoor}, > $Weather{WindChill}, > $Weather{HumidIndoor}, > $Weather{HumidOutdoor}); > #$Weather{Summary_Short} = "$Weather{TempOutdoor} C > $Weather{HumidOutdoor} %"; > } > else { > $Weather{Summary_Short} = "$Weather{TempOutdoor} F > $Weather{HumidOutdoor} %"; > } [snip] The code looks good! I thought I'd bounce those thoughts off of you before I start hacking and slashing away at my copy here. OWW/mh integration really has a lot of power and potential for people with or without weather stations, so it would be nice to have a "standard" OWW codebase that would work for both applications. Thanks for your time and hard work! I appreciate your patience and humoring a perl newb! Have a great week folks! /Mike |