I changed my code to get JSON via http client, everything looks ok however system hang/crash happen again after a failed URL call occasionally.
My program is very simple which allow Bluetooth Client to connect and provide WIFI SSID & pwd.
Then download data periodically from web server via wifi and disable in screen as a system monitor device… Unfortunately the network API is unstable
DynamicJsonDocument getJson(char* url)
{
HTTPClient client;
client.setTimeout(10);
client.begin(url);
int httpCode = client.GET();
String payload = “”;
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET… code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK) {
payload = client.getString();
Serial.println(payload);
}
client.end();
} else {
Serial.printf("[HTTP] GET… failed, error: %s\n", client.errorToString(httpCode).c_str());
client.end();
DynamicJsonDocument doc(1);
return doc;
}
const size_t capacity = JSON_OBJECT_SIZE(3) + 2000;
DynamicJsonDocument doc(capacity);
deserializeJson(doc, payload);
return doc;
}