-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcorona.ino
103 lines (76 loc) · 2.34 KB
/
corona.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <ESP8266HTTPClient.h>
#include <LiquidCrystal_I2C.h>
#include "json_parser.h"
#include "WifiConnect.h"
#define s2ms(second) (second*1000)
unsigned long long prev_millis(0);
#define country_code "Turkey"
LiquidCrystal_I2C lcd(0x3f, 16, 2);
int interval = s2ms(60);
unsigned long long PreviousMillis = 0;
unsigned long long CurrentMillis = interval;
bool bFirstKickMillis = false;
extern bool bGotIpFlag;
static String build_url_from_country(String country)
{
String url = "http://coronavirus-19-api.herokuapp.com/countries/";
url = url + country;
return url;
}
void setup(void)
{
lcd.begin();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Covid-19 Watch");
#if defined JSON_DEBUG
Serial.begin(9600);
#endif
JSON_LOG("Connecting...");
vConnWifiNetworkViaSdk();
}
void loop()
{
if(bGotIpFlag) bGotIp();
if(bFirstKickMillis) CurrentMillis = millis();
if (!bGotIpFlag && CurrentMillis - PreviousMillis >= interval)
{
if(!bFirstKickMillis) CurrentMillis = 0;
bFirstKickMillis = true;
PreviousMillis = CurrentMillis;
HTTPClient http;
http.begin(build_url_from_country(country_code));
int httpCode = http.GET();
if(httpCode > 0)
{
String payload = http.getString();
char* JsonArray = (char *)malloc(payload.length() + 1);
if (!JsonArray) JSON_LOG("upssss fuck");
payload.toCharArray(JsonArray, payload.length() + 1);
JSON_LOG(JsonArray);
if (json_validate(JsonArray))
{
int confirmed = (int)get_json_value(JsonArray, "cases", INT);
int deaths = (int)get_json_value(JsonArray, "deaths", INT);
int recovered = (int)get_json_value(JsonArray, "recovered", INT);
JSON_LOG(confirmed);
JSON_LOG(deaths);
JSON_LOG(recovered);
lcd.clear();
lcd.print("Cnfrmd");
lcd.setCursor(7,0);
lcd.print("dths");
lcd.setCursor(12,0);
lcd.print("rcvd");
lcd.setCursor(2, 1);
lcd.print(confirmed);
lcd.setCursor(8, 1);
lcd.print(deaths);
lcd.setCursor(14, 1);
lcd.print(recovered);
}
free(JsonArray);
}
http.end();
}
}