mirror of
https://github.com/OpenEPaperLink/OpenEPaperLink.git
synced 2026-03-21 07:06:36 +01:00
bugfix getlocation
This commit is contained in:
@@ -69,7 +69,7 @@ static void printLargestFreeBlock() {
|
||||
/// @param timeout Request timeout
|
||||
/// @param redirects Redirects handling
|
||||
/// @return True on success, false on error (httpCode != 200 || deserialization error)
|
||||
static bool httpGetJson(String &url, JsonDocument &json, const uint16_t timeout) //, const followRedirects_t redirects = followRedirects_t::HTTPC_DISABLE_FOLLOW_REDIRECTS)
|
||||
static bool httpGetJson(String &url, JsonDocument &json, const uint16_t timeout, JsonDocument *filter = nullptr) //, const followRedirects_t redirects = followRedirects_t::HTTPC_DISABLE_FOLLOW_REDIRECTS)
|
||||
{
|
||||
HTTPClient http;
|
||||
http.begin(url);
|
||||
@@ -82,7 +82,12 @@ static bool httpGetJson(String &url, JsonDocument &json, const uint16_t timeout)
|
||||
return false;
|
||||
}
|
||||
|
||||
DeserializationError error = deserializeJson(json, http.getString());
|
||||
DeserializationError error;
|
||||
if (filter) {
|
||||
error = deserializeJson(json, http.getString(), DeserializationOption::Filter(*filter));
|
||||
} else {
|
||||
error = deserializeJson(json, http.getString());
|
||||
}
|
||||
http.end();
|
||||
if (error) {
|
||||
Serial.println(error.c_str());
|
||||
|
||||
@@ -1198,8 +1198,12 @@ void getLocation(JsonObject &cfgobj) {
|
||||
|
||||
if (util::isEmptyOrNull(lat) || util::isEmptyOrNull(lon)) {
|
||||
wsLog("get location");
|
||||
StaticJsonDocument<80> filter;
|
||||
filter["results"][0]["latitude"] = true;
|
||||
filter["results"][0]["longitude"] = true;
|
||||
filter["results"][0]["timezone"] = true;
|
||||
StaticJsonDocument<1000> doc;
|
||||
if (util::httpGetJson("https://geocoding-api.open-meteo.com/v1/search?name=" + urlEncode(cfgobj["location"]) + "&count=1", doc, 5000)) {
|
||||
if (util::httpGetJson("https://geocoding-api.open-meteo.com/v1/search?name=" + urlEncode(cfgobj["location"]) + "&count=1", doc, 5000, &filter)) {
|
||||
cfgobj["#lat"] = doc["results"][0]["latitude"].as<String>();
|
||||
cfgobj["#lon"] = doc["results"][0]["longitude"].as<String>();
|
||||
cfgobj["#tz"] = doc["results"][0]["timezone"].as<String>();
|
||||
|
||||
Reference in New Issue
Block a user