├── README.md
└── CovidTracker.ino
/README.md:
--------------------------------------------------------------------------------
1 | # COVID19-Tracker-ESP32
2 | This little tracker will help you to be up to date about the Corona virus outbreak and the situation in your country. The display shows alternating the current data of different countries of your choice.
3 |
4 | The data is collected by the website www.worldometers.info/coronavirus/
5 |
6 | 
7 |
8 | ## Hardware
9 |
10 | I've used our AZ-Touch kit for ESP32 as hardware plattform. This kit comes with a 2.4 inch tft touchscreen, which will be used for the data output.
11 |
12 | 
13 |
14 | You can find all information about the hardware here:
15 | https://www.hwhardsoft.de/english/projects/arduitouch-esp/
16 |
17 |
18 | ## Libraries
19 |
20 | Install the following libraries through Arduino Library Manager
21 |
22 | Adafruit GFX Library https://github.com/adafruit/Adafruit-GFX-Library/archive/master.zip
23 |
24 | Adafruit ILI9341 Library https://github.com/adafruit/Adafruit_ILI9341
25 |
26 | You can also download the library also directly as ZIP file and uncompress the folder under yourarduinosketchfolder/libraries/
27 |
28 | After installing the libraries, restart the Arduino IDE.
29 |
30 | ## WiFi settings
31 |
32 | Enter your WiFi SSID & password in the fields in the WiFi section:
33 |
34 | #define WIFI_SSID "xxxxxx" // Enter your SSID here
35 |
36 | #define WIFI_PASS "xxxxx" // Enter your WiFi password here
37 |
38 |
39 | ## Country settings
40 |
41 | You can change/add/delete the countries in the main loop of the program according your interests.
42 |
43 | 
44 |
45 |
46 |
47 | # License
48 |
49 | This library is free software; you can redistribute it and/or
50 | modify it under the terms of the GNU Lesser General Public
51 | License as published by the Free Software Foundation; either
52 | version 2.1 of the License, or (at your option) any later version.
53 |
54 | This library is distributed in the hope that it will be useful,
55 | but WITHOUT ANY WARRANTY; without even the implied warranty of
56 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
57 | Lesser General Public License for more details.
58 |
--------------------------------------------------------------------------------
/CovidTracker.ino:
--------------------------------------------------------------------------------
1 | /*
2 | * Application note: Covid 19 tracker for AZ-Touch and ESP32 DEV KIT 3
3 | * Version 1.1
4 | * Copyright (C) 2020 Hartmut Wendt www.zihatec.de
5 | *
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 |
21 | /*______Import Libraries_______*/
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include "Adafruit_GFX.h"
28 | #include "Adafruit_ILI9341.h"
29 |
30 | /*______End of Libraries_______*/
31 |
32 | /*__Pin definitions for the Arduino MKR__*/
33 | #define TFT_CS 5
34 | #define TFT_DC 4
35 | #define TFT_MOSI 23
36 | #define TFT_CLK 18
37 | #define TFT_RST 22
38 | #define TFT_MISO 19
39 | #define TFT_LED 15
40 |
41 |
42 | #define HAVE_TOUCHPAD
43 | #define TOUCH_CS 14
44 | #define TOUCH_IRQ 2
45 | /*_______End of definitions______*/
46 |
47 | /*____Calibrate Touchscreen_____*/
48 | #define MINPRESSURE 10 // minimum required force for touch event
49 | #define TS_MINX 370
50 | #define TS_MINY 470
51 | #define TS_MAXX 3700
52 | #define TS_MAXY 3600
53 | /*______End of Calibration______*/
54 |
55 |
56 | /*____Wifi _____________________*/
57 | ///////please enter your sensitive data in the Secret tab/arduino_secrets.h
58 | #define WIFI_SSID "xxxxxx" // Enter your SSID here
59 | #define WIFI_PASS "xxxxx" // Enter your WiFi password here
60 |
61 | // Number of milliseconds to wait without receiving any data before we give up
62 | const int kNetworkTimeout = 30*1000;
63 | // Number of milliseconds to wait if no data is available before trying again
64 | const int kNetworkDelay = 2000;
65 | /*______End of Wifi______*/
66 |
67 |
68 | int status = WL_IDLE_STATUS;
69 | int infected=0;
70 | int recovered=0;
71 | int deaths=0;
72 |
73 |
74 | WiFiClientSecure client;
75 | HttpClient http(client,"www.worldometers.info", 443);
76 |
77 | Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
78 |
79 |
80 | void setup() {
81 | //Initialize serial and wait for port to open:
82 | Serial.begin(9600);
83 | while (!Serial) {
84 | ; // wait for serial port to connect. Needed for native USB port only
85 | }
86 |
87 | // init GPIOs
88 | pinMode(TFT_LED, OUTPUT); // define as output for backlight control
89 |
90 | // initialize the TFT
91 | Serial.println("Init TFT ...");
92 | tft.begin();
93 | tft.setRotation(3); // landscape mode
94 | tft.fillScreen(ILI9341_BLACK);// clear screen
95 |
96 | tft.setCursor(70,110);
97 | tft.setTextColor(ILI9341_WHITE);
98 | tft.setTextSize(2);
99 | tft.print("Connecting...");
100 | digitalWrite(TFT_LED, LOW); // LOW to turn backlight on;
101 |
102 |
103 | // Set WiFi to station mode and disconnect from an AP if it was Previously
104 | // connected
105 | WiFi.mode(WIFI_STA);
106 | WiFi.disconnect();
107 | delay(100);
108 |
109 | // Attempt to connect to Wifi network:
110 | Serial.print("Connecting Wifi: ");
111 | Serial.println(WIFI_SSID);
112 | WiFi.begin(WIFI_SSID, WIFI_PASS);
113 | while (WiFi.status() != WL_CONNECTED) {
114 | Serial.print(".");
115 | delay(500);
116 | }
117 | Serial.println("");
118 | Serial.println("WiFi connected");
119 | Serial.println("IP address: ");
120 | IPAddress ip = WiFi.localIP();
121 | Serial.println(ip);
122 |
123 |
124 | }
125 |
126 | void loop() {
127 | check_country("US");
128 | delay(2000);
129 | check_country("UK");
130 | delay(2000);
131 | check_country("Italy");
132 | delay(2000);
133 | check_country("Germany");
134 | delay(2000);
135 | check_country("Spain");
136 | delay(2000);
137 | check_country("Russia");
138 | delay(2000);
139 | check_country("Brazil");
140 | delay(2000);
141 | }
142 |
143 |
144 | void draw_country_screen(String sCountry){
145 | tft.fillScreen(ILI9341_BLACK);// clear screen
146 |
147 | // headline
148 | tft.setCursor(10,10);
149 | tft.setTextColor(ILI9341_WHITE);
150 | tft.setTextSize(3);
151 | tft.print(sCountry + ":");
152 |
153 | // infected
154 | tft.setCursor(5,70);
155 | tft.setTextColor(ILI9341_RED);
156 | tft.print("Infected:");
157 | tft.setCursor(190,70);
158 | tft.print(infected);
159 |
160 | // recovered
161 | tft.setCursor(5,130);
162 | tft.setTextColor(ILI9341_GREEN);
163 | tft.print("Recovered:");
164 | tft.setCursor(190,130);
165 | tft.print(recovered);
166 |
167 | // deaths
168 | tft.setCursor(5,190);
169 | tft.setTextColor(ILI9341_LIGHTGREY);
170 | tft.print("Deaths:");
171 | tft.setCursor(190,190);
172 | tft.print(deaths);
173 |
174 | }
175 |
176 | void check_country(String sCountry) {
177 | int err =0;
178 | int readcounter = 0;
179 | int read_value_step = 0;
180 | String s1 = "";
181 | String s2 = "";
182 |
183 | err = http.get("/coronavirus/country/" + sCountry +"/");
184 | if (err == 0)
185 | {
186 | Serial.println("startedRequest ok");
187 |
188 | err = http.responseStatusCode();
189 | if (err >= 0)
190 | {
191 | Serial.print("Got status code: ");
192 | Serial.println(err);
193 |
194 | // Usually you'd check that the response code is 200 or a
195 | // similar "success" code (200-299) before carrying on,
196 | // but we'll print out whatever response we get
197 |
198 | // If you are interesting in the response headers, you
199 | // can read them here:
200 | //while(http.headerAvailable())
201 | //{
202 | // String headerName = http.readHeaderName();
203 | // String headerValue = http.readHeaderValue();
204 | //}
205 |
206 | Serial.print("Request data for ");
207 | Serial.println(sCountry);
208 |
209 | // Now we've got to the body, so we can print it out
210 | unsigned long timeoutStart = millis();
211 | char c;
212 | // Whilst we haven't timed out & haven't reached the end of the body
213 | while ( (http.connected() || http.available()) &&
214 | (!http.endOfBodyReached()) &&
215 | ((millis() - timeoutStart) < kNetworkTimeout) )
216 | {
217 | if (http.available())
218 | {
219 | c = http.read();
220 | s2 = s2 + c;
221 | if (readcounter < 300) {
222 | readcounter++;
223 | } else {
224 | readcounter = 0;
225 | String tempString = "";
226 | tempString.concat(s1);
227 | tempString.concat(s2);
228 | // check infected first
229 | if (read_value_step == 0) {
230 | int place = tempString.indexOf("Coronavirus Cases:");
231 | if ((place != -1) && (place < 350)) {
232 | read_value_step = 1;
233 | s2 = tempString.substring(place + 15);
234 | tempString = s2.substring(s2.indexOf("#aaa") + 6);
235 | s1 = tempString.substring(0, (tempString.indexOf("")));
236 | s1.remove(s1.indexOf(","),1);
237 | s1.remove(s1.indexOf(","),1); // for large 7 digit numbers
238 | Serial.print("Coronavirus Cases: ");
239 | Serial.println(s1);
240 | infected = s1.toInt();
241 | }
242 |
243 | }
244 | // check deaths
245 | if (read_value_step == 1) {
246 | int place = tempString.indexOf("Deaths:");
247 | if ((place != -1) && (place < 350)) {
248 | read_value_step = 2;
249 | s2 = tempString.substring(place + 15);
250 | tempString = s2.substring(s2.indexOf("") + 6);
251 | s1 = tempString.substring(0, (tempString.indexOf("")));
252 | s1.remove(s1.indexOf(","),1);
253 | s1.remove(s1.indexOf(","),1); // for large 7 digit numbers
254 | Serial.print("Deaths: ");
255 | Serial.println(s1);
256 | deaths = s1.toInt();
257 | }
258 | }
259 | // check recovered
260 | if (read_value_step == 2) {
261 | int place = tempString.indexOf("Recovered:");
262 | if ((place != -1) && (place < 350)) {
263 | s2 = tempString.substring(place + 15);
264 | tempString = s2.substring(s2.indexOf("") + 6);
265 | s1 = tempString.substring(0, (tempString.indexOf("")));
266 | s1.remove(s1.indexOf(","),1);
267 | s1.remove(s1.indexOf(","),1); // for large 7 digit numbers
268 | Serial.print("Recovered: ");
269 | Serial.println(s1);
270 | recovered = s1.toInt();
271 | draw_country_screen(sCountry);
272 | http.stop();
273 | return;
274 | }
275 | }
276 |
277 | s1 = s2;
278 | s2 = "";
279 | }
280 |
281 | // We read something, reset the timeout counter
282 | timeoutStart = millis();
283 | }
284 | else
285 | {
286 | // We haven't got any data, so let's pause to allow some to
287 | // arrive
288 | delay(kNetworkDelay);
289 | }
290 | }
291 | }
292 | else
293 | {
294 | Serial.print("Getting response failed: ");
295 | Serial.println(err);
296 | }
297 | }
298 | else
299 | {
300 | Serial.print("Connect failed: ");
301 | Serial.println(err);
302 | }
303 | http.stop();
304 |
305 | }
306 |
307 |
308 | void printWiFiStatus() {
309 | // print the SSID of the network you're attached to:
310 | Serial.print("SSID: ");
311 | Serial.println(WiFi.SSID());
312 |
313 | // print your board's IP address:
314 | IPAddress ip = WiFi.localIP();
315 | Serial.print("IP Address: ");
316 | Serial.println(ip);
317 |
318 | // print the received signal strength:
319 | long rssi = WiFi.RSSI();
320 | Serial.print("signal strength (RSSI):");
321 | Serial.print(rssi);
322 | Serial.println(" dBm");
323 | }
324 |
--------------------------------------------------------------------------------