Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

iguanodon's scratchpad

by iguanodon (Curate)
on Jun 01, 2004 at 19:48 UTC ( #358476=scratchpad: print w/ replies, xml ) Need Help??

#!/home/don/perl5/perlbrew/perls/perl-5.18.1/bin/perl # $Header: svn://revcon/svn/za/apps/zwave/thermo_ctl.pl 630 2014-02-05 + 02:50:01Z don $ use strict; use warnings; $| = 1; use Getopt::Long; use LWP::UserAgent; use HTTP::Request::Common qw(GET POST); use Data::Dumper; use Config::General; use Log::Log4perl; use Time::HiRes qw(gettimeofday tv_interval); use Template; GetOptions ( 'cfg_file:s' => \(my $cfg_file = 'thermo_ctl.conf'), 'temp_f:i' => \(my $temp_f = undef), 'device:s' => \(my $device = undef), 'set!' => \(my $set = 1), ); my %conf = Config::General->new(-ConfigFile => $cfg_file)->getall; my $start = [gettimeofday]; Log::Log4perl->init($conf{'log4perl'}); my $log = Log::Log4perl->get_logger(); $log->info('Start'); $log->trace(Data::Dumper->Dump([\%conf], ['*conf'])); # Get ThermostatSetPoint: # http://zwave:8083/ZWaveAPI/Run/devices%5B2%5D.instances%5B0%5D.comma +ndClasses%5B0x43%5D.Get(1) # Set ThermostatSetPoint 19C: # http://zwave:8083/ZWaveAPI/Run/devices%5B2%5D.instances%5B0%5D.comma +ndClasses%5B0x43%5D.Set(1,19) my $temp_c = sprintf('%.0f', ($temp_f - 32) * 5 / 9); #my $deg = ''; #chr(176); $log->info("Setting $device temperature to $temp_f F ($temp_c C)"); my $tmpl = Template->new; my %vars = ('device' => $conf{'zwave'}{'devices'}{$device}); my $url; my $base_url = $conf{'zwave'}{'url'}; $tmpl->process(\$base_url, \%vars, \$url) || $log->logdie($tmpl->error +()); $url .= ".Set($conf{'zwave'}{'instance'},$temp_c)"; $log->debug("URL: $url"); my $ua = LWP::UserAgent->new(); if ($set) { $log->debug("POST $url"); my $req = POST $url; my $response = $ua->request($req); $log->debug($response->code . ' ' . $response->message); my $content = $response->content; $log->trace($content); } END { $log->info('End') if $log; } __END__
# $Header: svn://revcon/svn/za/apps/zwave/thermo_ctl.conf 630 2014-02- +05 02:50:01Z don $ <zwave> url = http://zwave:8083/ZWaveAPI/Run/devices%5B[% device %]%5D.ins +tances%5B0%5D.commandClasses%5B0x43%5D <devices> downstairs = 2 upstairs = 3 </devices> instance = 1 </zwave> <log4perl> log4perl.logger = DEBUG, CONSOLE, FILE log4perl.appender.FILE = Log::Dispatch::FileRotate log4perl.appender.FILE.mode = append log4perl.appender.FILE.filename = thermo_ctl.log log4perl.appender.FILE.size = 10485760 # 10 MB log4perl.appender.FILE.max = 5 log4perl.appender.FILE.layout = PatternLayout log4perl.appender.FILE.layout.ConversionPattern = %d %p: %m%n log4perl.appender.CONSOLE = Log::Log4perl::Appender::Screen log4perl.appender.CONSOLE.stderr = 0 log4perl.appender.CONSOLE.layout = PatternLayout log4perl.appender.CONSOLE.layout.ConversionPattern = %d %p: %m%n </log4perl>
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (12)
As of 2014-11-24 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (142 votes), past polls