FHEM Forum

FHEM - Hausautomations-Systeme => Unterstützende Dienste => Wettermodule => Thema gestartet von: lauterba am 31 Juli 2026, 18:26:48

Titel: Aufdopplung von OpenWeatherApi requests
Beitrag von: lauterba am 31 Juli 2026, 18:26:48
Wenn bei einem HTTP request zu OpenWeatherAPI (temporär) keine Verbindung aufgebaut werden kann, führt das dazu, dass sich die Anzahl der Requests in jedem Zyklus verdoppeln.
Nach kurzer Zeit werden damit extrem viele Requests ausgelöst, das dann sehr schnell zu hohen kosten führen könnte.

Ich vermute, dass _CallWeatherCallbackFn zweimal aufgerufen wird, wenn die Verbindung fehlschlägt

Ich verwende folgende OpenWeather Settings:
location=xxx,yyy interval=600 apikey=zzz API=OpenWeatherMapAPI lang=de apioptions=cachemaxage:3600 endpoint=weather
Titel: Aw: Aufdopplung von OpenWeatherApi requests
Beitrag von: CoolTux am 31 Juli 2026, 18:53:50
Was genau soll eigentlich dieses "endpoint" sein? Wo hast Du diese define Zeile her?

Kannst Du mir bitte einmal einen Screenshot anpingen wo man diese extrem vielen Requests sieht. Verstehe gerade den Zusammenhang nicht so ganz.

Danke
Titel: Aw: Aufdopplung von OpenWeatherApi requests
Beitrag von: lauterba am 31 Juli 2026, 19:02:51
Ich habe den Code ein wenig instrumentiert ...
und fhem mit einer ungültigen URL gestartet, um das Phenomen zu simulieren.

Beim ersten mal waren es zwei Requests
2026.07.31 18:08:46 0: OpenWeather request:https://api.openweathermap1.org/data/2.5/weather?lat=...
2026.07.31 18:08:46 0: OpenWeather request:https://api.openweathermap1.org/data/2.5/forecast?lat=...

Eine zweiten mal waren es schon vier
2026.07.31 18:09:46 0: OpenWeather request:https://api.openweathermap1.org/data/2.5/weather?lat=...
2026.07.31 18:09:46 0: OpenWeather request:https://api.openweathermap1.org/data/2.5/forecast?lat=...
2026.07.31 18:09:46 0: OpenWeather request:https://api.openweathermap1.org/data/2.5/weather?lat=...
2026.07.31 18:09:46 0: OpenWeather request:https://api.openweathermap1.org/data/2.5/forecast?lat=...


Da ich letzte Nacht einen längeren Ausfall hatte, ist die Anzahl der Anfragen exponentiel gestiegen und FHEM lief bei 100% CPU load und hatte nicht mehr reagiert. Es half nur noch ein kill -9.
Titel: Aw: Aufdopplung von OpenWeatherApi requests
Beitrag von: CoolTux am 31 Juli 2026, 19:05:02
Ok da muss ich mal schauen wie ich das simulieren kann.

Ist Dein FHEM aktuell?
Titel: Aw: Aufdopplung von OpenWeatherApi requests
Beitrag von: CoolTux am 31 Juli 2026, 19:05:38
Das "endpoint" ist dennoch falsch.
Titel: Aw: Aufdopplung von OpenWeatherApi requests
Beitrag von: lauterba am 31 Juli 2026, 19:06:42
Bei der Analyse vom Code hatte ich eine Vermutung, dass dies mit der Endpoint Variable zu tun hat.
Dies hatte aber keinen Änderung zezeigt, ich hatte nur vergessen es wieder zu entfernen.
Titel: Aw: Aufdopplung von OpenWeatherApi requests
Beitrag von: lauterba am 31 Juli 2026, 19:11:12
Ich verwende Version 6.4.

Es lässt sich relativ einfach simulieren, wenn man im Code eine nicht erreichbare URL verwendet.
Titel: Aw: Aufdopplung von OpenWeatherApi requests
Beitrag von: CoolTux am 31 Juli 2026, 19:15:31
Version 6.4? Damit meinst Du FHEM Version?
Hast Du jemals mittels FHEM ein Update gemacht?

Zeig mal bitte ein

list vom Weather Device. Irgendwie sieht die Ausgabe seltsam aus.
Hast Du das API Modul angepasst?
Titel: Aw: Aufdopplung von OpenWeatherApi requests
Beitrag von: lauterba am 31 Juli 2026, 19:25:30
Da ich fhem als rpm package verwende, habe ich bis jetzt kein Update gemacht.
6.4. ist das letzte fhem Release.

    
59_Weather.pm:v2.2.35-s29619/2025-02-04

Wie geschrieben, habe ich OpenWeatherMapAPI.pm etwas instrumentiert. Ich habe vor "::HttpUtils_NonblockingGet" eine Log Message eingebaut, um eine Vermutung zu bestätigen.
Titel: Aw: Aufdopplung von OpenWeatherApi requests
Beitrag von: lauterba am 31 Juli 2026, 19:39:17
Ich habe jetzt auch mal ein Update gemacht und den zusätzlichen Log und die korrupte URL wieder reingepacht.
Das Ergebnis ist dasselbe.

Beim ersten Request 2 HTTP Anfrage,
Beim zweiten Request (1min später) sind es 4 HTTP Anfragen,
Beim fritten Request (wieder 1min später) sind es 8 HTTP Anfragen,
Titel: Aw: Aufdopplung von OpenWeatherApi requests
Beitrag von: CoolTux am 31 Juli 2026, 19:55:37
Kannst Du den Patch hier einmal bitte anhängen? Danke
Titel: Aw: Aufdopplung von OpenWeatherApi requests
Beitrag von: lauterba am 31 Juli 2026, 20:03:51
--- OpenWeatherMapAPI.pm.orig   2026-07-31 19:59:37.065866335 +0200
+++ OpenWeatherMapAPI.pm   2026-07-31 20:00:59.547387538 +0200
@@ -120,7 +120,7 @@
 ## use critic
 
 # Readonly my $URL => 'https://api.openweathermap.org/data/2.5/';
-Readonly my $URL => 'https://api.openweathermap.org/data/';
+Readonly my $URL => 'https://api.openweathermap2.org/data/';
 ## URL . 'weather?' for current data
 ## URL . 'onecall?' for current,forecast data
 
@@ -362,6 +362,7 @@
           . 'exclude='
           . _CreateExcludeString( $self->{forecast}, $self->{alerts} );
 
+    ::Log(0, "HttpUtils_NonblockingGet: ".$paramRef->{url});
         ::HttpUtils_NonblockingGet($paramRef);
     }
Titel: Aw: Aufdopplung von OpenWeatherApi requests
Beitrag von: CoolTux am 31 Juli 2026, 21:20:12
Ich habe Deine Änderungen mal bei mir eingepflegt und bekomme als log Ausagbe


2026.07.31 21:18:00 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/3.0/onecall?lat=51.73524&lon=10.8135&APPID=XXXXXXXXXXXXXXXXXXXXXX&units=metric&lang=de&exclude=alerts,minutely


Aber sowas wie

2026.07.31 18:09:46 0: OpenWeather request:https://api.openweathermap1.org/data/2.5/weather?lat=...

habe ich nicht bekommen.
Titel: Aw: Aufdopplung von OpenWeatherApi requests
Beitrag von: lauterba am 31 Juli 2026, 21:29:28
Als ich das Update eingespielt habe, wurde mein hinzugefügter Log überschrieben.
Also musste ich den Log neu hinzufügen, dabei habe ich wohl ein anderes Pattern verwendet als im Text oben.

Ist das Aufdoppeln der Requests sichtbar?
Ich sehe mit dem Patch folgende Messages im Log:

2026.07.31 20:01:33 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/weather?lat=
2026.07.31 20:01:33 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/forecast?lat=

2026.07.31 20:02:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/weather?lat=
2026.07.31 20:02:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/forecast?lat=
2026.07.31 20:02:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/weather?lat=
2026.07.31 20:02:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/forecast?lat=

2026.07.31 20:03:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/weather?lat=
2026.07.31 20:03:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/forecast?lat=
2026.07.31 20:03:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/weather?lat=
2026.07.31 20:03:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/forecast?lat=
2026.07.31 20:03:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/weather?lat=
2026.07.31 20:03:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/forecast?lat=
2026.07.31 20:03:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/weather?lat=

2026.07.31 20:03:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/forecast?lat=
2026.07.31 20:04:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/weather?lat=
2026.07.31 20:04:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/forecast?lat=
2026.07.31 20:04:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/weather?lat=
2026.07.31 20:04:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/forecast?lat=
2026.07.31 20:04:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/weather?lat=
2026.07.31 20:04:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/forecast?lat=
2026.07.31 20:04:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/weather?lat=
2026.07.31 20:04:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/forecast?lat=
2026.07.31 20:04:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/weather?lat=
2026.07.31 20:04:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/forecast?lat=
2026.07.31 20:04:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/weather?lat=
2026.07.31 20:04:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/forecast?lat=
2026.07.31 20:04:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/weather?lat=
2026.07.31 20:04:34 0: HttpUtils_NonblockingGet: https://api.openweathermap2.org/data/2.5/forecast?lat=
Titel: Aw: Aufdopplung von OpenWeatherApi requests
Beitrag von: CoolTux am 31 Juli 2026, 21:57:03
Interessant, bei onecall mit 3.0 scheint es das nicht zu geben. Ich muss da mal die Definition ändern und dann schauen.

Ich schaue mir das morgen weiter an.