#!/usr/bin/perl #use CGI qw(:standard); #use Sys::Syslog qw(:standard :macros); use Net::MQTT::Simple; use IO::Socket; #openlog("weather", "", "local0"); my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = gmtime(time); my @mons = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my @days = qw(Sun Mon Tue Wed Thr Fri Sat); my $dt = sprintf( "%s, %02d %s %04d %02d:%02d:%02d GMT", $days[$wday], $mday, $mons[$mon], 1900 + $year, $hour, $min, $sec ); print "Content-Type: text/plain\r\n"; print "Date: ", $dt, "\n"; print "\n"; print "success\n"; my $mqtt = Net::MQTT::Simple->new("10.32.139.1"); for my $t ( split( /&/, $ENV{'QUERY_STRING'} ) ) { $t =~ s/%20/ /g; next unless $t =~ /^([^=]*)=([^=]*)$/; my ( $wot, $value ) = ( $1, $2 ); if ( $wot =~ /f$/ ) { $wot =~ s/f$/c/; $value = sprintf( "%.1f", 5.0 * ( ( $value - 32.0 ) / 9.0 ) ); } elsif ( $wot eq "baromin" ) { $wot = "barommb"; $value = sprintf( "%.1f", $value * 33.8639 ); } elsif ( $wot =~ /in$/ ) { $wot =~ s/in$/mm/; $value = sprintf( "%.1f", $value * 25.4 ); } if ( $wot eq "baromin" ) { $wot = "barommb"; $value = sprintf( "%.1f", $value * 33.8639 ); } if ( $wot eq "tempc" ) { $mqtt->retain( "tele/weather/" . $wot, $value ); } else { $mqtt->publish( "tele/weather/" . $wot, $value ); } #syslog(LOG_WARNING,"fish: $wot => $value"); } $mqtt->tick(0); $mqtt->disconnect; alarm(5); my $sock = IO::Socket::INET->new( PeerAddr => "88.96.137.6", PeerPort => 30956, Proto => 'tcp', Timeout => 5 ); exit 0 unless defined $sock; $sock->print( "GET /weatherstation/updateweatherstation.php?" . $ENV{'QUERY_STRING'} . " HTTP/1.0\r\n" ); $sock->print("\r\n"); $sock->shutdown( 1 );