Hi Community
Would you kindly take a look at this piece of code which locks up my mkr 1010.
In essence I am querying OpenWeatherMap and decoding the returned json using JsonArduino 6.17.2. The json blob is approx. 6kB in size and is initially decoded just fine. However upon the 5th execution the mkr hangs. This is regardless of the interval between executions.
I narrowed it down to the exact line of code. So it must either be deserializeJson() or
httpClient or String
Any recommendations as to the use of dynamic vs. static JsonDocument are also greatly appreciated.
#include <Arduino.h>
#include <WiFiNINA.h>
#include <ArduinoHttpClient.h>
#include <RTCZero.h>
#include <ArduinoJson.h>
#include <math.h>
DynamicJsonDocument jDoc(10000);
queryOW(now(), jDoc);
[...]
bool CWeatherman::queryOW(uint32_t dt, DynamicJsonDocument &jsonDoc) {
char qry[256];
snprintf(qry, 255, "/data/2.5/onecall/timemachine?lat=%f&lon=%f&dt=%lu&appid=f39d26xxx",m_latitude,m_longitude,dt);
WiFiSSLClient wifiCl;
HttpClient httpCl = HttpClient(wifiCl, m_OWServer, 443);
httpCl.get(qry);
int httpStat = httpCl.responseStatusCode();
if (httpStat != 200) {
Serial.println("Request failed");
return false;
}
//## Parse Response => Json
Serial.print("works");
DeserializationError err = deserializeJson(jsonDoc, httpCl.responseBody().c_str());
Serial.print("not reached after 5th execution");
if (err) {
Serial.print(F("deserializeJson() failed: "));
return false;
}
return true;
}