|
From: <kru...@us...> - 2013-09-14 05:12:17
|
Revision: 1888
http://sourceforge.net/p/openautomation/code/1888
Author: krumboeck
Date: 2013-09-14 05:12:14 +0000 (Sat, 14 Sep 2013)
Log Message:
-----------
Added plugin OpenWeatherMap
Added plugin OpenWeatherMapUpload
Added Paths:
-----------
wiregate/plugin/generic/OpenWeatherMap.pl
wiregate/plugin/generic/OpenWeatherMapUpload.pl
wiregate/plugin/generic/conf.d/OpenWeatherMap.conf_sample
wiregate/plugin/generic/conf.d/OpenWeatherMapUpload.conf_sample
Added: wiregate/plugin/generic/OpenWeatherMap.pl
===================================================================
--- wiregate/plugin/generic/OpenWeatherMap.pl (rev 0)
+++ wiregate/plugin/generic/OpenWeatherMap.pl 2013-09-14 05:12:14 UTC (rev 1888)
@@ -0,0 +1,120 @@
+######################################################################################
+#
+# Plugin OpenWeatherMap
+# Copyright: krumboeck (http://knx-user-forum.de/members/krumboeck.html)
+# License: GPL (v2)
+# V0.3 2013-09-07
+#
+# Ein Wiregate Plugin zum Senden von openweathermap.org Wetterdaten auf den KNX Bus
+#
+######################################################################################
+
+
+#################
+### Konfiguration
+#################
+
+# Festlegen, dass das Plugin alle 20 Minuten laufen soll
+$plugin_info{$plugname.'_cycle'} = 1200;
+
+
+#################################
+### Lesen der Konfigurationsdatei
+#################################
+
+my ($lat, $lon, $locale);
+my $knxGA;
+
+# Read config file in conf.d
+my $confFile = '/etc/wiregate/plugin/generic/conf.d/'.basename($plugname,'.pl').'.conf';
+if (! -f $confFile) {
+ plugin_log($plugname, " no conf file [$confFile] found.");
+ return "no conf file [$confFile] found.";
+} else {
+ open(CONF, $confFile);
+ my @lines = <CONF>;
+ close($confFile);
+ my $result = eval("@lines");
+ if ($@) {
+ plugin_log($plugname, "conf file [$confFile] returned:");
+ my @parts = split(/\n/, $@);
+ plugin_log($plugname, "--> $_") foreach (@parts);
+ }
+}
+
+
+################
+### Definitionen
+################
+
+use LWP::UserAgent;
+use XML::Simple;
+
+my $units = 'metric';
+my $mode = 'xml';
+
+
+#########################
+### Wetterdaten ermitteln
+#########################
+
+my $baseurl = 'http://api.openweathermap.org/data/2.5/weather?';
+my $url = $baseurl . 'lat=' . $lat . '&lon=' . $lon . '&units=' . $units . '&mode=' . $mode . '&lang=' . $locale;
+
+my $ua = LWP::UserAgent->new;
+$ua->timeout(30);
+my $response = $ua->get($url);
+
+if (! $response->is_success) {
+ return $response->status_line;
+}
+
+my $content = $response->decoded_content;
+
+my $xml = new XML::Simple;
+my $data = $xml->XMLin($content);
+
+
+#################################
+### Wetterdaten auf Bus schreiben
+#################################
+
+if (defined $knxGA->{temperature}) {
+ knx_write($knxGA->{temperature}, $data->{temperature}->{value}, 9.001);
+}
+
+if (defined $knxGA->{humidity}) {
+ knx_write($knxGA->{humidity}, $data->{humidity}->{value}, 9.007);
+}
+
+if (defined $knxGA->{pressure}) {
+ knx_write($knxGA->{pressure}, $data->{pressure}->{value}, 9.006);
+}
+
+if (defined $knxGA->{windSpeed}) {
+ var $windSpeed = sprintf("%.1f", $data->{wind}->{speed}->{value} / 3.6);
+ knx_write($knxGA->{windSpeed}, $windSpeed, 9.005);
+}
+
+if (defined $knxGA->{windDirection}) {
+ knx_write($knxGA->{windDirection}, $data->{wind}->{direction}->{value}, 9.003);
+}
+
+if (defined $knxGA->{clouds}) {
+ knx_write($knxGA->{clouds}, $data->{clouds}->{value}, 5.004);
+}
+
+if (defined $knxGA->{city}) {
+ my $city = $data->{city}->{name};
+ if (length($city) > 14) {
+ $city = subtr($city, 0, 14);
+ }
+ knx_write($knxGA->{city}, $city, 16.001);
+}
+
+my $ret = "Temperatur: " . $data->{temperature}->{value} . " °C";
+$ret .= "; Luftfeuchtigkeit: " . $data->{humidity}->{value} . " %";
+$ret .= "; Luftdruck: " . $data->{pressure}->{value} . " hPa";
+$ret .= "; Windgeschwindigkeit: " . $data->{wind}->{speed}->{value} . " km/h";
+
+return $ret;
Property changes on: wiregate/plugin/generic/OpenWeatherMap.pl
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: wiregate/plugin/generic/OpenWeatherMapUpload.pl
===================================================================
--- wiregate/plugin/generic/OpenWeatherMapUpload.pl (rev 0)
+++ wiregate/plugin/generic/OpenWeatherMapUpload.pl 2013-09-14 05:12:14 UTC (rev 1888)
@@ -0,0 +1,135 @@
+######################################################################################
+#
+# Plugin OpenWeatherMapUpload
+# Copyright: krumboeck (http://knx-user-forum.de/members/krumboeck.html)
+# License: GPL (v2)
+# V0.3 2013-08-24
+#
+# Ein Wiregate Plugin zum Upload von Wetterdaten für openweathermap.org
+# Folgende Funktionen werden unterstützt:
+# - Zeitliches Aussetzen wegen Messfehler (z.B.: Sonne scheint auf Tempfühler, etc.)
+# - Außentemperatur
+#
+# TODO:
+# - Andere Wetterdaten
+#
+######################################################################################
+
+
+#################
+### Konfiguration
+#################
+
+# Festlegen, dass das Plugin alle 10 Minuten laufen soll
+$plugin_info{$plugname.'_cycle'} = 600;
+
+
+#################################
+### Lesen der Konfigurationsdatei
+#################################
+
+my ($user, $pass, $name, $lat, $lon, $alt, $GAtemp);
+my @TimeExclusions;
+
+# Read config file in conf.d
+my $confFile = '/etc/wiregate/plugin/generic/conf.d/'.basename($plugname,'.pl').'.conf';
+if (! -f $confFile) {
+ plugin_log($plugname, " no conf file [$confFile] found.");
+ return "no conf file [$confFile] found.";
+} else {
+ open(CONF, $confFile);
+ my @lines = <CONF>;
+ close($confFile);
+ my $result = eval("@lines");
+ if ($@) {
+ plugin_log($plugname, "conf file [$confFile] returned:");
+ my @parts = split(/\n/, $@);
+ plugin_log($plugname, "--> $_") foreach (@parts);
+ }
+}
+
+use LWP::UserAgent;
+use HTTP::Request;
+use URI::Escape;
+
+
+######################
+### Prüfen von Sperren
+######################
+
+my ($Sekunden, $Minuten, $Stunden, $Tag, $Monat, $Jahr, $Wochentag, $Jahrestag, $Sommerzeit) = localtime(time);
+
+$Stunden = ($Stunden < 10) ? "0" . $Stunden : $Stunden;
+$Minuten = ($Minuten < 10) ? "0" . $Minuten : $Minuten;
+
+my $currentTime = $Stunden . $Minuten;
+print $currentTime;
+
+foreach my $exclusion (@TimeExclusions) {
+ my $from = $exclusion->{from};
+ $from =~ s/://;
+ my $until = $exclusion->{until};
+ $until =~ s/://;
+ print $from;
+ print $until;
+ if ($from <= $until) {
+ if (($from <= $currentTime) && ($until >= $currentTime)) {
+ return "Übertragung ist derzeit gesperrt";
+ }
+ } else {
+ if (($from <= $currentTime) && (2359 >= $currentTime)) {
+ return "Übertragung ist derzeit gesperrt";
+ }
+ if ((0 <= $currentTime) && ($until >= $currentTime)) {
+ return "Übertragung ist derzeit gesperrt";
+ }
+ }
+}
+
+
+#########################
+### Wetterdaten ermitteln
+#########################
+
+my $ret = "";
+my %post_data;
+$post_data{name} = $name;
+$post_data{lat} = $lat;
+$post_data{long} = $lon;
+$post_data{alt} = $alt;
+
+if ((defined $GAtemp) && (length($GAtemp) >= 5)) {
+ my $temp = knx_read($GAtemp, 300, 9.001);
+ if (defined $temp) {
+ $post_data{temp} = $temp;
+ $ret .= "Temperatur: " . $temp . "; ";
+ } else {
+ $ret .= "Temperatur: N/A" . "; ";
+ }
+}
+
+
+########################
+### Übertragen der Daten
+########################
+
+my $encoded_data = "";
+while ( my ($key, $value) = each(%post_data) ) {
+ $encoded_data .= $key . "=" . uri_escape($value) . "&";
+}
+$encoded_data =~ s/&$//;
+
+my $ua = new LWP::UserAgent;
+my $request = new HTTP::Request(POST => 'http://openweathermap.org/data/post');
+$request->authorization_basic($user, $pass);
+$request->header('Content-Type' => 'application/x-www-form-urlencoded');
+$request->content($encoded_data);
+my $response = $ua->request($request);
+
+if ($response->is_success) {
+ $ret =~ s/; $//;
+ return $ret;
+} else {
+ return "Upload Fehler: " . $response->status_line;
+}
+
Property changes on: wiregate/plugin/generic/OpenWeatherMapUpload.pl
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: wiregate/plugin/generic/conf.d/OpenWeatherMap.conf_sample
===================================================================
--- wiregate/plugin/generic/conf.d/OpenWeatherMap.conf_sample (rev 0)
+++ wiregate/plugin/generic/conf.d/OpenWeatherMap.conf_sample 2013-09-14 05:12:14 UTC (rev 1888)
@@ -0,0 +1,17 @@
+
+# Längengrad, Breitengrad und Sprache
+$lat = 49.235;
+$lon = 16.653;
+$locale = 'de';
+
+# Die Gruppenadressen müssen vorher mit dem Gruppenadresseditor erfasst werden.
+# Wenn ein Wert nicht benötigt wird, kann man ihn einfach auskommentieren.
+$knxGA = {
+ temperature => '1/2/0', # DPT 9.001: Außentemperatur in °C
+ humidity => '1/2/1', # DPT 9.007: Luftfeuchtigkeit in %
+ pressure => '1/2/2', # DPT 9.006: Luftdruck in hPa
+ windSpeed => '1/2/3', # DPT 9.005: Windgeschwindigkeit in km/h
+ windDirection => '1/2/4', # DPT 5.003: Winkel in Grad
+ clouds => '1/2/5', # DPT 5.004: Bewölkung in %
+ city => '1/2/6', # DPT 16.001: Name des nächsten Ortes (mit Wettervorhersage)
+ };
Added: wiregate/plugin/generic/conf.d/OpenWeatherMapUpload.conf_sample
===================================================================
--- wiregate/plugin/generic/conf.d/OpenWeatherMapUpload.conf_sample (rev 0)
+++ wiregate/plugin/generic/conf.d/OpenWeatherMapUpload.conf_sample 2013-09-14 05:12:14 UTC (rev 1888)
@@ -0,0 +1,20 @@
+
+# Benutzername und Passwort für openweathermap.org
+$user = "myusername"; # Benutzername
+$pass = "supergeheim"; # Passwort
+
+# Name, Koordinaten und Meereshöhe der Wetterstation
+$name = "Name-Station"; # Name der Wetterstation
+$lat = 49.275; # Breitengrad in Grad
+$lon = 16.683; # Längengrad in Grad
+$alt = 276; # Höhe über dem Meeresspiegel in Meter
+
+# Gruppenadresse für den Außentemperaturfühler
+$GAtemp = "4/3/0";
+
+# Zeiträume in welchen keine Übertragung stattfinden soll
+# z.B. Messfehler wegen direkter Sonneneinstrahlung
+# Wenn nicht benötigt einfach auskommentieren. Für einen
+# zusätzlichen Zeitraum die Zeile kopieren.
+push @TimeExclusions, { from => "06:00", until => "10:00" };
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|