Skip to content

Commit

Permalink
Added http client tcp timeout option, fix for #83
Browse files Browse the repository at this point in the history
  • Loading branch information
lmarzen committed May 4, 2024
1 parent 3fc7cb1 commit e41f6fa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
9 changes: 5 additions & 4 deletions platformio/include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,20 @@
// This can either be Probability of Precipitation (PoP) or hourly volume.
// Metric : Millimeters
// Imperial : Inches
// #define UNITS_HOURLY_PRECIP_POP
#define UNITS_HOURLY_PRECIP_POP
// #define UNITS_HOURLY_PRECIP_MILLIMETERS
// #define UNITS_HOURLY_PRECIP_CENTIMETERS
#define UNITS_HOURLY_PRECIP_INCHES
// #define UNITS_HOURLY_PRECIP_INCHES

// UNITS - PRECIPITATION (DAILY)
// Measure of precipitation.
// This can either be Probability of Precipitation (PoP) or daily volume.
// Metric : Millimeters
// Imperial : Inches
#define UNITS_DAILY_PRECIP_POP
// #define UNITS_DAILY_PRECIP_POP
// #define UNITS_DAILY_PRECIP_MILLIMETERS
// #define UNITS_DAILY_PRECIP_CENTIMETERS
// #define UNITS_DAILY_PRECIP_INCHES
#define UNITS_DAILY_PRECIP_INCHES

// Hypertext Transfer Protocol (HTTP)
// HTTP
Expand Down Expand Up @@ -274,6 +274,7 @@ extern const uint8_t BME_ADDRESS;
extern const char *WIFI_SSID;
extern const char *WIFI_PASSWORD;
extern const unsigned long WIFI_TIMEOUT;
extern const unsigned HTTP_CLIENT_TCP_TIMEOUT;
extern const String OWM_APIKEY;
extern const String OWM_ENDPOINT;
extern const String OWM_ONECALL_VERSION;
Expand Down
4 changes: 4 additions & 0 deletions platformio/src/client_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ bool waitForSNTPSync(tm *timeInfo)
}

HTTPClient http;
http.setConnectTimeout(HTTP_CLIENT_TCP_TIMEOUT); // default 5000ms
http.setTimeout(HTTP_CLIENT_TCP_TIMEOUT); // default 5000ms
http.begin(client, OWM_ENDPOINT, OWM_PORT, uri);
httpResponse = http.GET();
if (httpResponse == HTTP_CODE_OK)
Expand Down Expand Up @@ -250,6 +252,8 @@ bool waitForSNTPSync(tm *timeInfo)
}

HTTPClient http;
http.setConnectTimeout(HTTP_CLIENT_TCP_TIMEOUT); // default 5000ms
http.setTimeout(HTTP_CLIENT_TCP_TIMEOUT); // default 5000ms
http.begin(client, OWM_ENDPOINT, OWM_PORT, uri);
httpResponse = http.GET();
if (httpResponse == HTTP_CODE_OK)
Expand Down
8 changes: 8 additions & 0 deletions platformio/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ const char *WIFI_SSID = "ssid";
const char *WIFI_PASSWORD = "password";
const unsigned long WIFI_TIMEOUT = 10000; // ms, WiFi connection timeout.

// HTTP
// The following errors are likely the result of insuffient http client tcp
// timeout:
// -1 Connection Refused
// -11 Read Timeout
// -258 Deserialization Incomplete Input
const unsigned HTTP_CLIENT_TCP_TIMEOUT = 10000; // ms

// OPENWEATHERMAP API
// OpenWeatherMap API key, https://openweathermap.org/
const String OWM_APIKEY = "abcdefghijklmnopqrstuvwxyz012345";
Expand Down

0 comments on commit e41f6fa

Please sign in to comment.