OpenWeather icon indicating copy to clipboard operation
OpenWeather copied to clipboard

timeout for request

Open AlexJust139 opened this issue 2 years ago • 2 comments

Hello! Began to use your library, and noticed that sometimes openweather site doesn't answer on the request. In that case Arduino hangs for 60 secs:

Requesting weather information from OpenWeather... 

The connection to server is secure (https). Certificate not checked.
Connection failed.
Duration of OW request:60098

(If I try just to disable internet access for the MCU - it hangs only for 18 secs).

A quick look into the OpenWeather.cpp file shows only few 5 seс timeouts for "Sending GET request to " and 5 seс timeouts for "Client timeout during JSON parse".

Tell me pls, what the timeout should I decrease to not wait for 60 secs? Is it possible to do the appropriate configuration setting?

Thank you for the library !)

AlexJust139 avatar Jan 29 '24 18:01 AlexJust139

There are 5s and 8s timeouts but none for 60s. The delay may be in the board package WiFi functions. Which processor are you using.

I suspect you will need to add debug messages to the library code to see which WiFi library call is the culprit.

Bodmer avatar Jan 30 '24 12:01 Bodmer

Thank you for your answer!

Turned "#define SHOW_HEADER" on. But today openweather site answers well:

Requesting weather information from OpenWeather... 
The connection to server is secure (https). Certificate not checked.
Sending GET request to api.openweathermap.org port 443
HTTP/1.1 200 OK
Server: openresty
Date: Tue, 30 Jan 2024 17:31:05 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 16632
Connection: close
X-Cache-Key: /data/2.5/forecast?lang=ru&lat=55.78&lon=37.66&units=metric
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST
Header end found
Parsing JSON
Done in 3920 ms

So I ask you to wait untill errors appear )

AlexJust139 avatar Jan 30 '24 17:01 AlexJust139

Hello Bodmer! Here it is!:

22:10:42.385 -> Requesting weather information from OpenWeather... 
22:10:42.385 -> 
22:10:42.385 -> The connection to server is secure (https). Certificate not checked.
22:11:42.652 -> Connection failed.
22:11:42.652 -> _Duration of OW request:60271 / sec:60. City name length:0 - it's my code's answer_
22:11:42.652 -> city_name           : 
22:11:42.652 -> 
22:11:42.652 -> _No answer from OW server! Exit! - it's my code's answer_

Ping.averageTime to 8.8.8.8 =82.21 ms, so internet connection is normal.

What should I to do more?

AlexJust139 avatar Feb 08 '24 19:02 AlexJust139

It looks like the delay is in the board package code, wiating for a connection that does not happen.

Unfortuantely there is nothing the library can do unless a way is found to shorten that timeout.

Bodmer avatar Feb 08 '24 23:02 Bodmer

It looks like the timeout can be set for a connect now. It did not used to work but this issue seems to be fixed now.

Try changing this line to: if (!client.connect(host, port, 20000))

The timeout should then be 20s.

Bodmer avatar Feb 08 '24 23:02 Bodmer

Hello Bodmer!

I'm very sorry, but in the end I didn’t fight the delays, but rewrote my sketch with ESP RTOS Tasks. So delays are don't matter for me; and ticket can be closed.

Thank you very much and for your help and for your great work!

AlexJust139 avatar Mar 26 '24 19:03 AlexJust139