Skip to content

Instantly share code, notes, and snippets.

@jackrobotics
Created April 16, 2020 18:03
Show Gist options
  • Save jackrobotics/b8237a41d0e66cf6b1427cb7b7cd2988 to your computer and use it in GitHub Desktop.
Save jackrobotics/b8237a41d0e66cf6b1427cb7b7cd2988 to your computer and use it in GitHub Desktop.
#include <HONEYLemon.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
#define WIFI_SSID "HONEYLab" // ตั้งค่าชื่อ WiFi
#define WIFI_PASS "@HONEYLab" // ตั้งค่ารหัสผ่าน WiFi
int Confirmed = 0,Recovered = 0,Hospitalized = 0,Deaths = 0,NewConfirmed = 0,NewRecovered = 0,NewHospitalized = 0,NewDeaths = 0;
String UpdateDate = "";
void updateCovid19(){
WiFiClientSecure *client = new WiFiClientSecure;
if( client ){
HTTPClient https;
if (https.begin(*client, "https://covid19.th-stat.com/api/open/today")) { // HTTPS
if (https.GET() == HTTP_CODE_OK) {
String payload = https.getString();
//Serial.println(payload);
DynamicJsonDocument obj(512);
deserializeJson(obj, payload);
Confirmed = obj["Confirmed"];
Recovered = obj["Recovered"];
Hospitalized = obj["Hospitalized"];
Deaths = obj["Deaths"];
NewConfirmed = obj["NewConfirmed"];
NewRecovered = obj["NewRecovered"];
NewHospitalized = obj["NewHospitalized"];
NewDeaths = obj["NewDeaths"];
UpdateDate = obj["UpdateDate"].as<String>();
}
}
https.end();
}
}
void setup() {
lemon.begin(); // เรียกใช้งานฟังก์ชั่นเริ่มต้นของบอร์ด HONEYLemon
Serial.begin(115200); // เรียกใช้งาน Serial
lemon.debug(Serial); // ขอดู debug ของบอร์ด HONEYLemon ผ่าน Serial
// เรียกการใช้งานการตั้งค่า WiFi
lemon.setupWiFi(WIFI_SSID, WIFI_PASS);
}
unsigned long lastUpdate = 0;
void loop() {
if( millis() - lastUpdate > 1000 ){
lastUpdate = millis();
updateCovid19();
Serial.println("UpdateDate : " + (String)UpdateDate);
Serial.println("Confirmed : " + (String)Confirmed + "( " + (String)NewConfirmed + " )");
Serial.println("Recovered : " + (String)Recovered + "( " + (String)NewRecovered + " )");
Serial.println("Hospitalized : "+ (String)Hospitalized + "( " + (String)NewHospitalized + " )");
Serial.println("Deaths : " + (String)Deaths + "( " + (String)NewDeaths + " )");
Serial.println("--------------------------------------\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment