0

Here is my sketch, where the time is in the JSON document:

#include <HTTPClient.h>
#include <Time.h>
#include <TimeLib.h>
#include <Wire.h>
#include <WiFi.h>
#include <ArduinoJson.h>
#include <LiquidCrystal.h>

const char* ssid = "moto z play";
const char* pass = "143Mithun";
int count;
const int rs = 22, en = 4, d4 = 15, d5 = 13, d6 = 26, d7 = 21;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int trigPin = 5;
const int echoPin = 18;
const int pump = 19;
long duration;
int distance;
const char* url = "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/"
    "arcgis/rest/services/ncov_cases/FeatureServer/1/query?"
    "where=Country_Region+%3D+%27India%27&objectIds=205&time="
    "&geometry=&geometryType=esriGeometryEnvelope&inSR="
    "&spatialRel=esriSpatialRelIntersects&resultType=none"
    "&distance=0.0&units=esriSRUnit_Meter&returnGeodetic=false&"
    "outFields=Province_State%2CCountry_Region%2CLast_Update%2C"
    "Confirmed%2CRecovered%2CDeaths%2C"
    "&returnGeometry=false&featureEncoding=esriDefault"
    "&multipatchOption=xyFootprint&maxAllowableOffset="
    "&geometryPrecision=&outSR=&datumTransformation="
    "&applyVCSProjection=false&returnIdsOnly=false"
    "&returnUniqueIdsOnly=false&returnCountOnly=false"
    "&returnExtentOnly=false&returnQueryGeometry=false"
    "&returnDistinctValues=false&cacheHint=false&orderByFields="
    "&groupByFieldsForStatistics=&outStatistics=&having="
    "&resultOffset=&resultRecordCount=&returnZ=false&returnM=false"
    "&returnExceededLimitFeatures=true&quantizationParameters="
    "&sqlFormat=none&f=pjson&token=";// specify the url

void setup() {
  Serial.begin(115200);
  delay(2000);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(pump, OUTPUT);
  digitalWrite(pump, LOW);
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Covid19 Tracker");
  lcd.setCursor(0,1);
  lcd.print("Hand Sanitizer");
  Serial.println("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");              // print ... till not connected
  }
  Serial.println("WiFi connected");
}

void ultra() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.0340 / 1;
  Serial.println("Distance");
  Serial.println(distance);
  if (distance <= 15) {
    Serial.print("Opening Pump");
    digitalWrite(pump, HIGH);
    delay(2000);
    digitalWrite(pump, LOW);
    ESP.restart();
  }
}

void loop() {
  ultra();
  HTTPClient https;
  String data;
  https.begin(url);
  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(1) + JSON_ARRAY_SIZE(6)
        + JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(2)
        + 4*JSON_OBJECT_SIZE(6) + 4*JSON_OBJECT_SIZE(7) + 990;
    DynamicJsonDocument doc(capacity);
    deserializeJson(doc, payload);
    const char* json = "{\"objectIdFieldName\":\"OBJECTID\","
        "\"uniqueIdField\":{\"name\":\"OBJECTID\","
        "\"isSystemMaintained\":true},"
        "\"globalIdFieldName\":\"\","
        "\"geometryType\":\"esriGeometryPoint\","
        "\"spatialReference\":{\"wkid\":4326,\"latestWkid\":4326},"
        "\"fields\":[{\"name\":\"Province_State\","
        "\"type\":\"esriFieldTypeString\",\"alias\":\"Province/State\","
        "\"sqlType\":\"sqlTypeOther\",\"length\":8000,\"domain\":null,"
        "\"defaultValue\":null},{\"name\":\"Country_Region\","
        "\"type\":\"esriFieldTypeString\",\"alias\":\"Country/Region\","
        "\"sqlType\":\"sqlTypeOther\",\"length\":8000,\"domain\":null,"
        "\"defaultValue\":null},{\"name\":\"Last_Update\","
        "\"type\":\"esriFieldTypeDate\",\"alias\":\"Last Update\","
        "\"sqlType\":\"sqlTypeOther\",\"length\":8,\"domain\":null,"
        "\"defaultValue\":null},{\"name\":\"Confirmed\","
        "\"type\":\"esriFieldTypeInteger\",\"alias\":\"Confirmed\","
        "\"sqlType\":\"sqlTypeOther\",\"domain\":null,"
        "\"defaultValue\":null},{\"name\":\"Recovered\","
        "\"type\":\"esriFieldTypeInteger\",\"alias\":\"Recovered\","
        "\"sqlType\":\"sqlTypeOther\",\"domain\":null,"
        "\"defaultValue\":null},{\"name\":\"Deaths\","
        "\"type\":\"esriFieldTypeInteger\",\"alias\":\"Deaths\","
        "\"sqlType\":\"sqlTypeOther\",\"domain\":null,"
        "\"defaultValue\":null}],\"features\":[{\"attributes\":"
        "{\"Province_State\":\"Karnataka\","
        "\"Country_Region\":\"India\",\"Last_Update\":1594827289000,"
        "\"Confirmed\":44077,\"Recovered\":17390,\"Deaths\":842}}]}";

    deserializeJson(doc, json);

    const char* objectIdFieldName = doc["objectIdFieldName"]; // "OBJECTID"

    const char* uniqueIdField_name = doc["uniqueIdField"]["name"]; // "OBJECTID"
    bool uniqueIdField_isSystemMaintained = doc["uniqueIdField"]["isSystemMaintained"]; // true

    const char* globalIdFieldName = doc["globalIdFieldName"]; // ""
    const char* geometryType = doc["geometryType"]; // "esriGeometryPoint"

    int spatialReference_wkid = doc["spatialReference"]["wkid"]; // 4326
    int spatialReference_latestWkid = doc["spatialReference"]["latestWkid"]; // 4326

    JsonArray fields = doc["fields"];

    JsonObject fields_0 = fields[0];
    const char* fields_0_name = fields_0["name"]; // "Province_State"
    const char* fields_0_type = fields_0["type"]; // "esriFieldTypeString"
    const char* fields_0_alias = fields_0["alias"]; // "Province/State"
    const char* fields_0_sqlType = fields_0["sqlType"]; // "sqlTypeOther"
    int fields_0_length = fields_0["length"]; // 8000

    JsonObject fields_1 = fields[1];
    const char* fields_1_name = fields_1["name"]; // "Country_Region"
    const char* fields_1_type = fields_1["type"]; // "esriFieldTypeString"
    const char* fields_1_alias = fields_1["alias"]; // "Country/Region"
    const char* fields_1_sqlType = fields_1["sqlType"]; // "sqlTypeOther"
    int fields_1_length = fields_1["length"]; // 8000

    JsonObject fields_2 = fields[2];
    const char* fields_2_name = fields_2["name"]; // "Last_Update"
    const char* fields_2_type = fields_2["type"]; // "esriFieldTypeDate"
    const char* fields_2_alias = fields_2["alias"]; // "Last Update"
    const char* fields_2_sqlType = fields_2["sqlType"]; // "sqlTypeOther"
    int fields_2_length = fields_2["length"]; // 8

    JsonObject fields_3 = fields[3];
    const char* fields_3_name = fields_3["name"]; // "Confirmed"
    const char* fields_3_type = fields_3["type"]; // "esriFieldTypeInteger"
    const char* fields_3_alias = fields_3["alias"]; // "Confirmed"
    const char* fields_3_sqlType = fields_3["sqlType"]; // "sqlTypeOther"

    JsonObject fields_4 = fields[4];
    const char* fields_4_name = fields_4["name"]; // "Recovered"
    const char* fields_4_type = fields_4["type"]; // "esriFieldTypeInteger"
    const char* fields_4_alias = fields_4["alias"]; // "Recovered"
    const char* fields_4_sqlType = fields_4["sqlType"]; // "sqlTypeOther"

    JsonObject fields_5 = fields[5];
    const char* fields_5_name = fields_5["name"]; // "Deaths"
    const char* fields_5_type = fields_5["type"]; // "esriFieldTypeInteger"
    const char* fields_5_alias = fields_5["alias"]; // "Deaths"
    const char* fields_5_sqlType = fields_5["sqlType"]; // "sqlTypeOther"

    JsonObject features_0_attributes = doc["features"][0]["attributes"];
    const char* features_0_attributes_Province_State = features_0_attributes["Province_State"]; // "Karnataka"
    const char* features_0_attributes_Country_Region = features_0_attributes["Country_Region"]; // "India"
    long long features_0_attributes_Last_Update = features_0_attributes["Last_Update"]; // 1594827289000
    long features_0_attributes_Confirmed = features_0_attributes["Confirmed"]; // 44077
    int features_0_attributes_Recovered = features_0_attributes["Recovered"]; // 17390
    int features_0_attributes_Deaths = features_0_attributes["Deaths"]; // 842
    if (count > 5) {
      //Serial.println(features_0_attributes_Country_Region);
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Country:");
      lcd.print(features_0_attributes_Country_Region);
      //Serial.println(features_0_attributes_Province_State);
      lcd.setCursor(0,1);
      lcd.print("State:");
      lcd.print(features_0_attributes_Province_State);
    }
    delay(5000);
    {
      //Serial.println(features_0_attributes_Last_Update);
      lcd.begin(16,2);
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Date:");
      lcd.print(features_0_attributes_Last_Update);
      //Serial.println(features_0_attributes_Confirmed);
      lcd.setCursor(0,1);
      lcd.print("Confirmed:");
      lcd.print(features_0_attributes_Confirmed);
    }
    delay(5000);
    {
      //Serial.println(features_0_attributes_Recovered);
      lcd.begin(16,2);
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Recovered:");
      lcd.print(features_0_attributes_Recovered);
      //Serial.println(features_0_attributes_Deaths);
      lcd.begin(16,2);
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Deaths:");
      lcd.print(features_0_attributes_Deaths);
    }
    delay(5000);
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Wash Hands");
      lcd.setCursor(0,1);
      lcd.print("Avoid Contacts");
    }
    delay(5000);
    {
      lcd.begin(16,2);
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Covid19-Tracker");
      lcd.setCursor(0,1);
      lcd.print("DONE BY MITHUN ");
    }
    if (count > 6) {
      count = 0;
    }
  } // if (httpCode > 0)
  else {
    Serial.println("Error on HTTP request");
  }
  https.end();
  count++;
}
  • sprintf(buff, "%d-%02d-%02d %02d:%02d:%02d", year(t), month(t), day(t), hour(t), minute(t), second(t)); – Juraj Jul 16 at 9:35