From 7c6887eaaf812b63bab6c5e134f80a2ef36aeb31 Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Tue, 12 Jan 2021 16:58:31 +0000 Subject: works --- .../html/weatherstation/updateweatherstation.php | 1 + .../html/weatherstation/updateweatherstation.pl | 83 ++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 120000 prometheus/home/httpd/html/weatherstation/updateweatherstation.php create mode 100755 prometheus/home/httpd/html/weatherstation/updateweatherstation.pl (limited to 'prometheus/home') diff --git a/prometheus/home/httpd/html/weatherstation/updateweatherstation.php b/prometheus/home/httpd/html/weatherstation/updateweatherstation.php new file mode 120000 index 0000000..b629fc9 --- /dev/null +++ b/prometheus/home/httpd/html/weatherstation/updateweatherstation.php @@ -0,0 +1 @@ +updateweatherstation.pl \ No newline at end of file diff --git a/prometheus/home/httpd/html/weatherstation/updateweatherstation.pl b/prometheus/home/httpd/html/weatherstation/updateweatherstation.pl new file mode 100755 index 0000000..87b8893 --- /dev/null +++ b/prometheus/home/httpd/html/weatherstation/updateweatherstation.pl @@ -0,0 +1,83 @@ +#!/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( $socket, 1 ); + -- cgit v1.2.3