#include #include #include //LCD Display Library #include #include
LiquidCrystal_I2C lcd(0x3F,16,2); // Set the LCD I2C address
//#include "rgb_lcd.h" //rgb_lcd lcd;
const char* ssid = "yourSSID"; // WiFi user anme const char* pass = "yourPASS"; //WiFi Password const char* host = "api.thingspeak.com"; //We read the data from this host const int httpPortRead = 80; // HTTP post definition
//URL we need const char* url0 = "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=(Country_Region=%27Thailand%27)&returnGeometry=false&outFields=Country_Region,Confirmed,Recovered,Deaths"; const char* url1 = "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=(Country_Region=%27Afghanistan%27)&returnGeometry=false&outFields=Country_Region,Confirmed,Recovered,Deaths"; const char* url2 = "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=(Country_Region=%27Bangladesh%27)&returnGeometry=false&outFields=Country_Region,Confirmed,Recovered,Deaths"; const char* url3 = "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=(Country_Region=%27Bhutan%27)&returnGeometry=false&outFields=Country_Region,Confirmed,Recovered,Deaths"; const char* url4 = "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=(Country_Region=%27India%27)&returnGeometry=false&outFields=Country_Region,Confirmed,Recovered,Deaths"; const char* url5 = "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=(Country_Region=%27Maldives%27)&returnGeometry=false&outFields=Country_Region,Confirmed,Recovered,Deaths"; const char* url6 = "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=(Country_Region=%27Nepal%27)&returnGeometry=false&outFields=Country_Region,Confirmed,Recovered,Deaths"; const char* url7 = "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=(Country_Region=%27Pakistan%27)&returnGeometry=false&outFields=Country_Region,Confirmed,Recovered,Deaths"; const char* url8 = "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=(Country_Region=%27Sri%20Lanka%27)&returnGeometry=false&outFields=Country_Region,Confirmed,Recovered,Deaths"; const char* url9 = "/apps/thinghttp/send_request?api_key=S8DNGOFDS3C9LC22"; //Those URLs are mine but I kept them so you can replace the key only const char* url10 = "/apps/thinghttp/send_request?api_key=MHT7SYQLFLAACP86"; const char* url11 = "/apps/thinghttp/send_request?api_key=YPV7MTZZYD9G13PT"; int To_remove; //There are some irrelevant data on the string and here's how I keep the index of those characters String Cases,Death,Recover,Data_Raw; //Here I keep the numbers that I got
void setup() { Serial.begin(115200); lcd.init(); lcd.backlight(); lcd.print("KoMoMi RTCovid19"); lcd.setCursor(0,1); lcd.print(" Case Counter"); delay(2000); // lcd.begin(16, 2); Serial.println("Connecting to "); Serial.println(ssid); lcd.clear(); lcd.print("WiFi Connecting"); lcd.setCursor(0,1); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); // print ... till not connected lcd.print("."); } Serial.println("WiFi connected"); lcd.clear(); lcd.print("WiFi Connected"); lcd.setCursor(0,1); lcd.print(ssid); }
void loop() {
HTTPClient https; String data; Thailand(); // Afganistan(); // Bangladesh(); // Bhutan(); // India(); // Maldives(); // Nepal(); // Pakistan(); // Srilanka(); World(); }
void World() { WiFiClient client; //Create a WiFi client and http client HTTPClient http; if( http.begin(host,httpPortRead,url9)) //Connect to the host and the url { int httpCode = http.GET(); //Check feedback if there's a response if (httpCode > 0) { if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) { Data_Raw = http.getString(); //Here we store the raw data string To_remove = Data_Raw.indexOf(">"); Data_Raw.remove(0,To_remove+1); To_remove = Data_Raw.indexOf("<"); Data_Raw.remove(To_remove,Data_Raw.length()); Cases=Data_Raw; } } else { Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); } http.end(); } else //If we can't connect to the HTTP { Serial.printf("[HTTP} Unable to connect\n"); }
if( http.begin(host,httpPortRead,url10)) { int httpCode = http.GET(); if (httpCode > 0) { if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) { Data_Raw = http.getString(); To_remove = Data_Raw.indexOf(">"); Data_Raw.remove(0,To_remove+1); To_remove = Data_Raw.indexOf("<"); Data_Raw.remove(To_remove,Data_Raw.length()); Death=Data_Raw; } } else { Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); } http.end(); } else { Serial.printf("[HTTP} Unable to connect\n"); }
if( http.begin(host,httpPortRead,url11)) { int httpCode = http.GET(); if (httpCode > 0) { if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) { Data_Raw = http.getString(); To_remove = Data_Raw.indexOf(">"); Data_Raw.remove(0,To_remove+1); To_remove = Data_Raw.indexOf("<"); Data_Raw.remove(To_remove,Data_Raw.length()); Recover=Data_Raw; } } else { Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); } http.end(); } else { Serial.printf("[HTTP} Unable to connect\n"); } Serial.println("World"); Serial.println(Cases); Serial.println(Recover); Serial.println(Death); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 0, 255); lcd.print("___World Data___"); lcd.setCursor(0, 1); lcd.print("Case:"); lcd.setCursor(6, 1); lcd.print(Cases); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(255, 0, 0); lcd.print("___World Data___"); lcd.setCursor(0, 1); lcd.print("Death:"); lcd.setCursor(7, 1); lcd.print(Death); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 255, 0); lcd.print("___World Data___"); lcd.setCursor(0, 1); lcd.print("Recover:"); lcd.setCursor(9, 1); lcd.print(Recover); delay(2000); while (WiFi.status() != WL_CONNECTED) //In case the Wifi connexion is lost { WiFi.disconnect(); delay(1000); WiFi.begin(ssid, pass); Serial.println("Reconnecting to WiFi.."); delay(10000); } // lcd.clear(); }
void Thailand() { HTTPClient https; String data; https.begin(url0); int httpCode = https.GET(); if (httpCode > 0) { //Check for the returning code String payload = https.getString(); char charBuf[500]; payload.toCharArray(charBuf, 500); const size_t capacity = JSON_ARRAY_SIZE(4) + JSON_ARRAY_SIZE(7) + 7*JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(2) + 7*JSON_OBJECT_SIZE(4) + 3*JSON_OBJECT_SIZE(6) + 2*JSON_OBJECT_SIZE(7) + 1130; DynamicJsonDocument doc(capacity); deserializeJson(doc, payload); JsonArray fields = doc["fields"]; JsonObject features_0_attributes = doc["features"][0]["attributes"]; const char* features_0_attributes_Country_Region = features_0_attributes["Country_Region"]; // "Thailand" int features_0_attributes_Confirmed = features_0_attributes["Confirmed"]; // 84 int features_0_attributes_Recovered = features_0_attributes["Recovered"]; // 2 int features_0_attributes_Deaths = features_0_attributes["Deaths"]; // 2 Serial.println(features_0_attributes_Country_Region); Serial.println(features_0_attributes_Confirmed); Serial.println(features_0_attributes_Recovered); Serial.println(features_0_attributes_Deaths); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 0, 255); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Case:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Confirmed); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(255, 0, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Death:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Deaths); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 255, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Recover:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Recovered); delay(2000); } else { Serial.println("Error on HTTP request"); } https.end(); return; }
void Afganistan() { HTTPClient https; String data; https.begin(url1); int httpCode = https.GET(); if (httpCode > 0) { //Check for the returning code String payload = https.getString(); char charBuf[500]; payload.toCharArray(charBuf, 500); const size_t capacity = JSON_ARRAY_SIZE(4) + JSON_ARRAY_SIZE(7) + 7*JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(2) + 7*JSON_OBJECT_SIZE(4) + 3*JSON_OBJECT_SIZE(6) + 2*JSON_OBJECT_SIZE(7) + 1130; DynamicJsonDocument doc(capacity); deserializeJson(doc, payload); JsonArray fields = doc["fields"]; JsonObject features_0_attributes = doc["features"][0]["attributes"]; const char* features_0_attributes_Country_Region = features_0_attributes["Country_Region"]; // "Afghanistan" int features_0_attributes_Confirmed = features_0_attributes["Confirmed"]; // 84 int features_0_attributes_Recovered = features_0_attributes["Recovered"]; // 2 int features_0_attributes_Deaths = features_0_attributes["Deaths"]; // 2 Serial.println(features_0_attributes_Country_Region); Serial.println(features_0_attributes_Confirmed); Serial.println(features_0_attributes_Recovered); Serial.println(features_0_attributes_Deaths); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 0, 255); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Case:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Confirmed); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(255, 0, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Death:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Deaths); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 255, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Recover:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Recovered); delay(2000); } else { Serial.println("Error on HTTP request"); } https.end(); return; }
void Bangladesh() { HTTPClient https; String data; https.begin(url2); int httpCode = https.GET(); if (httpCode > 0) { //Check for the returning code String payload = https.getString(); char charBuf[500]; payload.toCharArray(charBuf, 500); //Serial.println(payload); const size_t capacity = JSON_ARRAY_SIZE(4) + JSON_ARRAY_SIZE(7) + 7*JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(2) + 7*JSON_OBJECT_SIZE(4) + 3*JSON_OBJECT_SIZE(6) + 2*JSON_OBJECT_SIZE(7) + 1130; DynamicJsonDocument doc(capacity); deserializeJson(doc, payload); JsonArray fields = doc["fields"]; JsonObject features_0_attributes = doc["features"][0]["attributes"]; const char* features_0_attributes_Country_Region = features_0_attributes["Country_Region"]; // "Afghanistan" int features_0_attributes_Confirmed = features_0_attributes["Confirmed"]; // 84 int features_0_attributes_Recovered = features_0_attributes["Recovered"]; // 2 int features_0_attributes_Deaths = features_0_attributes["Deaths"]; // 2 Serial.println(features_0_attributes_Country_Region); Serial.println(features_0_attributes_Confirmed); Serial.println(features_0_attributes_Recovered); Serial.println(features_0_attributes_Deaths); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 0, 255); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Case:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Confirmed); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(255, 0, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Death:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Deaths); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 255, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Recover:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Recovered); delay(2000); } else { Serial.println("Error on HTTP request"); } https.end(); return; } void Bhutan() { HTTPClient https; String data; https.begin(url3); int httpCode = https.GET(); if (httpCode > 0) { //Check for the returning code String payload = https.getString(); char charBuf[500]; payload.toCharArray(charBuf, 500); //Serial.println(payload); const size_t capacity = JSON_ARRAY_SIZE(4) + JSON_ARRAY_SIZE(7) + 7*JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(2) + 7*JSON_OBJECT_SIZE(4) + 3*JSON_OBJECT_SIZE(6) + 2*JSON_OBJECT_SIZE(7) + 1130; DynamicJsonDocument doc(capacity); deserializeJson(doc, payload); JsonArray fields = doc["fields"]; JsonObject features_0_attributes = doc["features"][0]["attributes"]; const char* features_0_attributes_Country_Region = features_0_attributes["Country_Region"]; // "Afghanistan" int features_0_attributes_Confirmed = features_0_attributes["Confirmed"]; // 84 int features_0_attributes_Recovered = features_0_attributes["Recovered"]; // 2 int features_0_attributes_Deaths = features_0_attributes["Deaths"]; // 2 Serial.println(features_0_attributes_Country_Region); Serial.println(features_0_attributes_Confirmed); Serial.println(features_0_attributes_Recovered); Serial.println(features_0_attributes_Deaths); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 0, 255); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Case:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Confirmed); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(255, 0, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Death:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Deaths); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 255, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Recover:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Recovered); delay(2000); } else { Serial.println("Error on HTTP request"); } https.end(); return; }
void India() { HTTPClient https; String data; https.begin(url4); int httpCode = https.GET(); if (httpCode > 0) { //Check for the returning code String payload = https.getString(); char charBuf[500]; payload.toCharArray(charBuf, 500); //Serial.println(payload); const size_t capacity = JSON_ARRAY_SIZE(4) + JSON_ARRAY_SIZE(7) + 7*JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(2) + 7*JSON_OBJECT_SIZE(4) + 3*JSON_OBJECT_SIZE(6) + 2*JSON_OBJECT_SIZE(7) + 1130; DynamicJsonDocument doc(capacity); deserializeJson(doc, payload); JsonArray fields = doc["fields"]; JsonObject features_0_attributes = doc["features"][0]["attributes"]; const char* features_0_attributes_Country_Region = features_0_attributes["Country_Region"]; // "Afghanistan" int features_0_attributes_Confirmed = features_0_attributes["Confirmed"]; // 84 int features_0_attributes_Recovered = features_0_attributes["Recovered"]; // 2 int features_0_attributes_Deaths = features_0_attributes["Deaths"]; // 2 Serial.println(features_0_attributes_Country_Region); Serial.println(features_0_attributes_Confirmed); Serial.println(features_0_attributes_Recovered); Serial.println(features_0_attributes_Deaths); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 0, 255); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Case:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Confirmed); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(255, 0, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Death:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Deaths); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 255, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Recover:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Recovered); delay(2000); } else { Serial.println("Error on HTTP request"); } https.end(); return; }
void Maldives() { HTTPClient https; String data; https.begin(url5); int httpCode = https.GET(); if (httpCode > 0) { //Check for the returning code String payload = https.getString(); char charBuf[500]; payload.toCharArray(charBuf, 500); //Serial.println(payload); const size_t capacity = JSON_ARRAY_SIZE(4) + JSON_ARRAY_SIZE(7) + 7*JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(2) + 7*JSON_OBJECT_SIZE(4) + 3*JSON_OBJECT_SIZE(6) + 2*JSON_OBJECT_SIZE(7) + 1130; DynamicJsonDocument doc(capacity); deserializeJson(doc, payload); JsonArray fields = doc["fields"]; JsonObject features_0_attributes = doc["features"][0]["attributes"]; const char* features_0_attributes_Country_Region = features_0_attributes["Country_Region"]; // "Afghanistan" int features_0_attributes_Confirmed = features_0_attributes["Confirmed"]; // 84 int features_0_attributes_Recovered = features_0_attributes["Recovered"]; // 2 int features_0_attributes_Deaths = features_0_attributes["Deaths"]; // 2 Serial.println(features_0_attributes_Country_Region); Serial.println(features_0_attributes_Confirmed); Serial.println(features_0_attributes_Recovered); Serial.println(features_0_attributes_Deaths); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 0, 255); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Case:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Confirmed); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(255, 0, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Death:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Deaths); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 255, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Recover:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Recovered); delay(2000); } else { Serial.println("Error on HTTP request"); } https.end(); return; }
void Nepal() { HTTPClient https; String data; https.begin(url6); int httpCode = https.GET(); if (httpCode > 0) { //Check for the returning code String payload = https.getString(); char charBuf[500]; payload.toCharArray(charBuf, 500); //Serial.println(payload); const size_t capacity = JSON_ARRAY_SIZE(4) + JSON_ARRAY_SIZE(7) + 7*JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(2) + 7*JSON_OBJECT_SIZE(4) + 3*JSON_OBJECT_SIZE(6) + 2*JSON_OBJECT_SIZE(7) + 1130; DynamicJsonDocument doc(capacity); deserializeJson(doc, payload); JsonArray fields = doc["fields"]; JsonObject features_0_attributes = doc["features"][0]["attributes"]; const char* features_0_attributes_Country_Region = features_0_attributes["Country_Region"]; // "Afghanistan" int features_0_attributes_Confirmed = features_0_attributes["Confirmed"]; // 84 int features_0_attributes_Recovered = features_0_attributes["Recovered"]; // 2 int features_0_attributes_Deaths = features_0_attributes["Deaths"]; // 2 Serial.println(features_0_attributes_Country_Region); Serial.println(features_0_attributes_Confirmed); Serial.println(features_0_attributes_Recovered); Serial.println(features_0_attributes_Deaths); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 0, 255); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Case:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Confirmed); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(255, 0, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Death:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Deaths); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 255, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Recover:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Recovered); delay(2000); } else { Serial.println("Error on HTTP request"); } https.end(); return; } void Pakistan() { HTTPClient https; String data; https.begin(url7); int httpCode = https.GET(); if (httpCode > 0) { //Check for the returning code String payload = https.getString(); char charBuf[500]; payload.toCharArray(charBuf, 500); //Serial.println(payload); const size_t capacity = JSON_ARRAY_SIZE(4) + JSON_ARRAY_SIZE(7) + 7*JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(2) + 7*JSON_OBJECT_SIZE(4) + 3*JSON_OBJECT_SIZE(6) + 2*JSON_OBJECT_SIZE(7) + 1130; DynamicJsonDocument doc(capacity); deserializeJson(doc, payload); JsonArray fields = doc["fields"]; JsonObject features_0_attributes = doc["features"][0]["attributes"]; const char* features_0_attributes_Country_Region = features_0_attributes["Country_Region"]; // "Afghanistan" int features_0_attributes_Confirmed = features_0_attributes["Confirmed"]; // 84 int features_0_attributes_Recovered = features_0_attributes["Recovered"]; // 2 int features_0_attributes_Deaths = features_0_attributes["Deaths"]; // 2 Serial.println(features_0_attributes_Country_Region); Serial.println(features_0_attributes_Confirmed); Serial.println(features_0_attributes_Recovered); Serial.println(features_0_attributes_Deaths); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 0, 255); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Case:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Confirmed); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(255, 0, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Death:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Deaths); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 255, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Recover:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Recovered); delay(2000); } else { Serial.println("Error on HTTP request"); } https.end(); return; }
void Srilanka() { HTTPClient https; String data; https.begin(url8); int httpCode = https.GET(); if (httpCode > 0) { //Check for the returning code String payload = https.getString(); char charBuf[500]; payload.toCharArray(charBuf, 500); //Serial.println(payload); const size_t capacity = JSON_ARRAY_SIZE(4) + JSON_ARRAY_SIZE(7) + 7*JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(2) + 7*JSON_OBJECT_SIZE(4) + 3*JSON_OBJECT_SIZE(6) + 2*JSON_OBJECT_SIZE(7) + 1130; DynamicJsonDocument doc(capacity); deserializeJson(doc, payload); JsonArray fields = doc["fields"]; JsonObject features_0_attributes = doc["features"][0]["attributes"]; const char* features_0_attributes_Country_Region = features_0_attributes["Country_Region"]; // "Afghanistan" int features_0_attributes_Confirmed = features_0_attributes["Confirmed"]; // 84 int features_0_attributes_Recovered = features_0_attributes["Recovered"]; // 2 int features_0_attributes_Deaths = features_0_attributes["Deaths"]; // 2 Serial.println(features_0_attributes_Country_Region); Serial.println(features_0_attributes_Confirmed); Serial.println(features_0_attributes_Recovered); Serial.println(features_0_attributes_Deaths); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 0, 255); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Case:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Confirmed); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(255, 0, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Death:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Deaths); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // lcd.setRGB(0, 255, 0); lcd.print(features_0_attributes_Country_Region); lcd.setCursor(0, 1); lcd.print("Recover:"); lcd.setCursor(8, 1); lcd.print(features_0_attributes_Recovered); delay(2000); } else { Serial.println("Error on HTTP request"); } https.end(); return; }
|