From 8f8423b196a46fd4a6b83121a53e2a0b5ad1d60d Mon Sep 17 00:00:00 2001 From: betateilchen <> Date: Wed, 14 Aug 2013 10:04:54 +0000 Subject: [PATCH] git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@3695 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/98_openweathermap.pm | 66 +++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/FHEM/98_openweathermap.pm b/FHEM/98_openweathermap.pm index 5ed664c56..fcf2f90ea 100644 --- a/FHEM/98_openweathermap.pm +++ b/FHEM/98_openweathermap.pm @@ -279,7 +279,7 @@ OWO_GetStatus($;$){ my $station = AttrVal($name, "owoStation", undef); if(defined($user) && defined($station)){ - Log3($name, 3, "openweather $name: started: SendData"); + Log3($name, 3, "owo $name: started: SendData"); my $lat = AttrVal("global", "latitude", ""); my $lon = AttrVal("global", "longitude", ""); @@ -300,7 +300,7 @@ OWO_GetStatus($;$){ $o = 0 if(!defined($o)); $v = ReadingsVal($s, $v, "?") + $o; $dataString = $dataString."&$p=$v"; - Log3($name, 3, "openweather $name: reading: $paraName $p $s $v"); + Log3($name, 3, "owo $name: reading: $paraName $p $s $v"); readingsSingleUpdate($hash, "my_".$p, $v, 1); } } @@ -309,15 +309,15 @@ OWO_GetStatus($;$){ my $sendString = $urlString."?".$dataString; if(AttrVal($name, "owoDebug",1) == 0){ - Log3($name, 3, "openweather $name: sending: $dataString"); + Log3($name, 3, "owo $name: sending: $dataString"); $htmlDummy = $ua->get($sendString); - Log3($name, 3, "openweather $name: htmlResponse: ".$htmlDummy->status_line); + Log3($name, 3, "owo $name: htmlResponse: ".$htmlDummy->status_line); } else { - Log3($name, 3, "openweather $name: debug: $dataString"); + Log3($name, 3, "owo $name: debug: $dataString"); } readingsBeginUpdate($hash); - readingsBulkUpdate($hash, "_my_HtmlResponse", $htmlDummy->status_line); + readingsBulkUpdate($hash, "_httpResponse_my", $htmlDummy->status_line) if $htmlDummy; readingsBulkUpdate($hash, "state","active"); if(AttrVal($name, "owoTimestamp", 0) == 1){ readingsBulkUpdate($hash, "my_lastSent", time); @@ -338,7 +338,7 @@ OWO_GetStatus($;$){ my $cId = ReadingsVal($name,"c_stationId", undef); if(defined($cId)){ my $cName = ReadingsVal($name,"stationName", ""); - Log3($name, 3, "openweather $name: retrievingStationData: Id: $cId Name: $cName"); + Log3($name, 3, "owo $name: retrievingStationData: Id: $cId Name: $cName"); fhem("set $name stationById $cId"); } @@ -367,7 +367,7 @@ OWO_Define($$){ readingsEndUpdate($hash, 1); InternalTimer(gettimeofday()+$hash->{helper}{INTERVAL}, "OWO_GetStatus", $hash, 0); - Log3($name, 3, "openweather $name: created"); + Log3($name, 3, "owo $name: created"); return; } @@ -388,24 +388,25 @@ UpdateReadings($$$){ my $xmlMode = AttrVal($name, "owoUseXml", ""); $url .= "&mode=xml" if($xmlMode eq "1"); $url .= "&APPID=".AttrVal($name, "owoApiKey", ""); - $response = $ua->get("$url"); + eval {$response = $ua->get("$url")}; if(defined($response)){ if(AttrVal($name, "owoDebug", 1) == 1){ - Log3($name, 3, "openweather $name: response:\n".$response->decoded_content); + Log3($name, 3, "owo $name: response:\n".$response->decoded_content); } } else { - Log3($name, 3, "openweather $name: error: no response from server"); + Log3($name, 3, "owo $name: error: no response from server"); + return; } CommandDeleteReading(undef, "$name $prefix.*"); - readingsSingleUpdate($hash, "_$prefix"."HtmlResponse", $response->status_line, 1); + readingsSingleUpdate($hash, "_httpResponse_".substr($prefix,0,1), $response->status_line, 1); - if($xmlMode eq "1"){ - Log3($name, 3, "openweather $name: decoding XML"); + if($xmlMode eq "1" && $response->is_success){ + Log3($name, 3, "owo $name: decoding XML"); my $xml = new XML::Simple; $jsonWeather = undef; - $jsonWeather = $xml->XMLin($response->decoded_content, KeyAttr => { 'current' } ); + $jsonWeather = $xml->XMLin($response->decoded_content, KeyAttr => 'current' ); if(defined($jsonWeather)){ readingsBeginUpdate($hash); @@ -436,10 +437,12 @@ UpdateReadings($$$){ readingsBulkUpdate($hash, "state", "active"); readingsEndUpdate($hash, 1); } else { - Log3($name, 3, "openweather $name error: update not possible!"); + Log3($name, 3, "owo $name error: update not possible!"); } - } else { - Log3($name, 3, "openweather $name: decoding JSON"); + } + + if($xmlMode ne "1" && $response->is_success){ + Log3($name, 3, "owo $name: decoding JSON"); my $json = JSON->new->allow_nonref; eval {$jsonWeather = $json->decode($response->decoded_content)}; warn $@ if $@; @@ -478,7 +481,7 @@ UpdateReadings($$$){ readingsBulkUpdate($hash, "state", "active"); readingsEndUpdate($hash, 1); } else { - Log3($name, 3, "openweather $name error: update not possible!"); + Log3($name, 3, "owo $name error: update not possible!"); } } return; @@ -591,22 +594,22 @@ OWO_isday($$){
- define myWeather openweather
- attr myWeather owoUser myuser:mypassword
- attr myWeather owoStation myStationName
- attr myWeather owoInterval 600
- attr myWeather owoSrc00 temp:sensorname:temperature
+ define owo openweathermap
+ attr owo owoUser myuser:mypassword
+ attr owo owoStation myStationName
+ attr owo owoInterval 600
+ attr owo owoSrc00 temp:sensorname:temperature
- set myWeather stationByName Leimen
+ set owo stationByName Leimen
- set myWeather stationById 2879241
+ set owo stationById 2879241
- set myWeather stationByGeo 49.3511 8.6894
+ set owo stationByGeo 49.3511 8.6894
- get myWeather stationByName Leimen
+ get owo stationByName Leimen
- get myWeather stationById 2879241
+ get owo stationById 2879241
- get myWeather stationByGeo 49.3511 8.6894
+ get owo stationByGeo 49.3511 8.6894
cpan install JSON