I basically have multiple APIs (weather, time, etc) which I like to update every hr or so and display..
For whatever reason, the fetched data panics the esp32
H file:
class ShaService {
protected:
String source_url;
DynamicJsonDocument *payload;
int payload_size;
private:
UpdateRate update_rate;
u_int32_t updated_at = 0;
void httpGETRequest();
public:
ShaService(UpdateRate update_rate, int payload_size, String source_url);
void display();
bool needsUpdate();
void updated();
virtual void fetch();
};
C file
ShaService::ShaService(UpdateRate update_rate, int payload_size,
String source_url) {
this->update_rate = update_rate;
this->payload_size = payload_size;
this->source_url = source_url;
this->payload = new DynamicJsonDocument(payload_size);
}
void ShaService::fetch() {
if (this->needsUpdate()) {
WiFiClientSecure client;
HTTPClient http;
debug_print("payload %s\n", this->source_url);
Serial.println(this->source_url);
client.setInsecure();
http.begin(client, this->source_url);
// Send HTTP GET request
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
debug_print("HTTP Response code: %d\n", httpResponseCode);
DeserializationError err =
deserializeJson(*this->payload, http.getStream());
if (err) {
debug_print("Could not undestand the json : %s", err.c_str());
}
serializeJsonPretty(*this->payload, Serial); // Works fine
} else {
printf("Error code: %d\n", httpResponseCode);
}
// Free resources
http.end();
updated();
} else {
printf("No Need to fetch");
}
delay(10 * 1000);
}
panic here ||
\ /
void ShaService::display() {
Serial.println("Display....\n");
serializeJsonPretty(*payload, Serial);
}