#include "covid19.h" Covid19::Covid19() { lastWorld = 0; } String Covid19::getDataFor(String myuri) { String payload; std::unique_ptrclient(new BearSSL::WiFiClientSecure); client->setInsecure(); HTTPClient https; https.setTimeout(5000); Serial.print("[HTTPS] begin...\n"); if (https.begin(*client, "https://corona.lmao.ninja/"+myuri)) { int httpCode = https.GET(); if (httpCode > 0) { Serial.printf("[HTTPS] GET... code: %d\n", httpCode); if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) { payload = https.getString(); } } else { payload = "{'error " + (String)https.errorToString(httpCode).c_str() + "'}"; //Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str()); } https.end(); } else { Serial.printf("[HTTPS] Unable to connect\n"); payload = "{'error'}"; } return payload; } void Covid19::displayCountry(String country, Adafruit_SSD1306 &OLED) { String json = getDataFor("countries/"+country); StaticJsonDocument<1024> doc; DeserializationError error = deserializeJson(doc, json); if (error) { Serial.print(F("deserializeJson() failed: ")); Serial.println(error.c_str()); return; } int cases = doc["cases"]; int todayCases = doc["todayCases"]; int deaths = doc["deaths"]; int todayDeaths = doc["todayDeaths"]; int recovered = doc["recovered"]; Serial.print("|=============================\n"); Serial.print("| STATS FOR : " + country + "\n"); Serial.print("|=============================\n"); Serial.print("| Cases : " + String(cases) + " \n"); Serial.print("| todayCases : " + String(todayCases) + " \n"); Serial.print("| deaths : " + String(deaths) + " \n"); Serial.print("| todayDeaths : " + String(todayDeaths) + " \n"); Serial.print("| recovered : " + String(recovered) + " \n"); OLED.clearDisplay(); OLED.setTextWrap(false); OLED.setTextSize(1); OLED.setTextColor(WHITE); OLED.setCursor(0,0); OLED.println(" === " + country + " === " ); OLED.println("Cases : " + String(cases) + " (" + todayCases + ")" ); OLED.println("Death : " + String(deaths) ); OLED.println("Recov : " + String(recovered) ); OLED.display(); } void Covid19::displayWorld(Adafruit_SSD1306 &OLED) { String json = getDataFor("all"); StaticJsonDocument<512> doc; DeserializationError error = deserializeJson(doc, json); if (error) { Serial.print(F("deserializeJson() failed: ")); Serial.println(error.c_str()); return; } int cases = doc["cases"]; int deaths = doc["deaths"]; int recovered = doc["recovered"]; if(lastWorld==0) lastWorld = cases; int delta = cases - lastWorld; Serial.print("|=============================\n"); Serial.print("| STATS FOR : WORLD \n"); Serial.print("|=============================\n"); Serial.print("| Cases : " + String(cases) + " ("+delta+")\n"); Serial.print("| deaths : " + String(deaths) + " \n"); Serial.print("| recovered : " + String(recovered) + " \n"); OLED.clearDisplay(); OLED.setTextWrap(false); OLED.setTextSize(1); OLED.setTextColor(WHITE); OLED.setCursor(0,0); OLED.println(" === WORLDWIDE === " ); OLED.println("Cases : " + String(cases) + "("+delta+")" ); OLED.println("Death : " + String(deaths) ); OLED.println("Recov : " + String(recovered) ); OLED.display(); lastWorld = cases; }