mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-22 08:11:44 +00:00
59_Twilight: correction of issues when starting fhem wehn reading weatherdata in nonBlockingmode
git-svn-id: https://svn.fhem.de/fhem/trunk@7462 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
23202c6537
commit
d69c676c87
@ -144,6 +144,7 @@ sub Twilight_Define($$)
|
|||||||
$hash->{LATITUDE} = $latitude;
|
$hash->{LATITUDE} = $latitude;
|
||||||
$hash->{LONGITUDE} = $longitude;
|
$hash->{LONGITUDE} = $longitude;
|
||||||
$hash->{WEATHER} = $weather;
|
$hash->{WEATHER} = $weather;
|
||||||
|
$hash->{DEFINE} = 1;
|
||||||
$hash->{SUNPOS_OFFSET} = 5*60;
|
$hash->{SUNPOS_OFFSET} = 5*60;
|
||||||
|
|
||||||
$attr{$name}{verbose} = 4 if ($name =~ /^tst.*$/ );
|
$attr{$name}{verbose} = 4 if ($name =~ /^tst.*$/ );
|
||||||
@ -152,6 +153,8 @@ sub Twilight_Define($$)
|
|||||||
Twilight_sunpos($mHash);
|
Twilight_sunpos($mHash);
|
||||||
Twilight_Midnight($mHash);
|
Twilight_Midnight($mHash);
|
||||||
|
|
||||||
|
delete $hash->{DEFINE};
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
################################################################################
|
################################################################################
|
||||||
@ -321,31 +324,26 @@ sub Twilight_CreateHttpParameterAndGetData($$) {
|
|||||||
my $location = $hash->{WEATHER};
|
my $location = $hash->{WEATHER};
|
||||||
my $verbose = AttrVal($hash->{NAME}, "verbose", 3 );
|
my $verbose = AttrVal($hash->{NAME}, "verbose", 3 );
|
||||||
|
|
||||||
# my $xml = GetFileFromURL("http://weather.yahooapis.com/forecastrss?w=".
|
|
||||||
# $location."&u=c",4.0, undef, 1);
|
|
||||||
# xxxxxxxx
|
|
||||||
#$param->{noshutdown}
|
|
||||||
#optional
|
|
||||||
# Wenn $param->{noshutdown} auf 1 gesetzt ist, wird dem HTTP-Server nicht implizit
|
|
||||||
# mitgeteilt, dass die Verbindung nach dem Request geschlossen werden soll. Viele
|
|
||||||
# Webserver schließen in solch einem Fall die Verbindung bevor sie die Antwort senden.
|
|
||||||
# Bei 0 wird dem Webserver mitgeteilt, dass der Sendevorgang beendet ist und nun die
|
|
||||||
# Antwort abgewartet wird.
|
|
||||||
# Standardwert: 1 wie undef
|
|
||||||
# 0 schliest die Verbindung explizit.
|
|
||||||
my $param = {
|
my $param = {
|
||||||
|
#noshutdown => 1,
|
||||||
url => "http://weather.yahooapis.com/forecastrss?w=".$location."&u=c",
|
url => "http://weather.yahooapis.com/forecastrss?w=".$location."&u=c",
|
||||||
timeout => ($mode eq "Mid") ? 7 : 5,
|
timeout => defined($hash->{DEFINE}) ? 5 : 5,
|
||||||
hash => $hash,
|
hash => $hash,
|
||||||
method => "GET",
|
method => "GET",
|
||||||
noshutdown => 1,
|
|
||||||
loglevel => 4-($verbose-3),
|
loglevel => 4-($verbose-3),
|
||||||
header => "User-Agent: Mozilla/5.0\r\nAccept: application/xml",
|
header => "User-Agent: Mozilla/5.0\r\nAccept: application/xml",
|
||||||
callback => \&Twilight_WeatherCallback,
|
callback => \&Twilight_WeatherCallback,
|
||||||
mode => $mode
|
mode => $mode };
|
||||||
};
|
|
||||||
|
if (defined($hash->{DEFINE})) {
|
||||||
|
delete $param->{callback};
|
||||||
|
my ($err, $xml) = HttpUtils_BlockingGet($param);
|
||||||
|
Twilight_WeatherCallback($param, $err, $xml);
|
||||||
|
} else {
|
||||||
HttpUtils_NonblockingGet($param);
|
HttpUtils_NonblockingGet($param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
################################################################################
|
################################################################################
|
||||||
sub Twilight_WeatherCallback(@) {
|
sub Twilight_WeatherCallback(@) {
|
||||||
my ($param, $err, $xml) = @_;
|
my ($param, $err, $xml) = @_;
|
||||||
@ -380,7 +378,7 @@ sub Twilight_WeatherTimerSet($) {
|
|||||||
myRemoveInternalTimer ("perlTime", $hash);
|
myRemoveInternalTimer ("perlTime", $hash);
|
||||||
foreach my $key ("ss_weather", "sr_weather" ) {
|
foreach my $key ("ss_weather", "sr_weather" ) {
|
||||||
my $tim = $hash->{TW}{$key}{TIME};
|
my $tim = $hash->{TW}{$key}{TIME};
|
||||||
if ($tim-60*60>$now) {
|
if ($tim-60*60>$now+60) {
|
||||||
myInternalTimer ("perlTime", $tim-60*60, "Twilight_WeatherTimerUpdate", $hash, 0);
|
myInternalTimer ("perlTime", $tim-60*60, "Twilight_WeatherTimerUpdate", $hash, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user