diff --git a/ESP32_AP-Flasher/include/util.h b/ESP32_AP-Flasher/include/util.h index 602b8675..6719cacc 100644 --- a/ESP32_AP-Flasher/include/util.h +++ b/ESP32_AP-Flasher/include/util.h @@ -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()); diff --git a/ESP32_AP-Flasher/src/contentmanager.cpp b/ESP32_AP-Flasher/src/contentmanager.cpp index 0daa31d6..3eeeff7e 100644 --- a/ESP32_AP-Flasher/src/contentmanager.cpp +++ b/ESP32_AP-Flasher/src/contentmanager.cpp @@ -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(); cfgobj["#lon"] = doc["results"][0]["longitude"].as(); cfgobj["#tz"] = doc["results"][0]["timezone"].as();