-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoviddata.ino
More file actions
146 lines (133 loc) · 5.39 KB
/
coviddata.ino
File metadata and controls
146 lines (133 loc) · 5.39 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <ESP8266WiFi.h> //Use ESP8266 functions
#include <ESP8266HTTPClient.h>
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const char* ssid = "i"; //WIFI SSID Name
const char* password = "12345678"; //WIFI Password
const char* host = "api.thingspeak.com"; //We read the data from this host
const int httpPortRead = 80;
const char* url1 = "/apps/thinghttp/send_request?api_key=B5DHMPN9JED04JKS"; //Change this URL Cases
const char* url2 = "/apps/thinghttp/send_request?api_key=AA6FLGVVLL80U6FA";
const char* url3 = "/apps/thinghttp/send_request?api_key=UGJN4QW1PLO73HHO";
const char* url4 = "/apps/thinghttp/send_request?api_key=AGA9647JXBW3CPJR";
const char* url5 = "/apps/thinghttp/send_request?api_key=YAR0957PUN9Y4TP7";
String Cases,Deaths,Recovered,State,Active,Data_Raw,Data_Raw_1;
WiFiClient client; //Create a WiFi client and http client
HTTPClient http;
void setup()
{
Serial.begin(115200);
WiFi.disconnect(); //Disconnect and reconnect to the Wifi you set
delay(1000);
WiFi.begin(ssid, password);
while(WiFi.status() != WL_CONNECTED)
{
delay(1000);
Serial.print(".");
}
Serial.println("Connected to the WiFi network"); //Display feedback on the serial monitor
Serial.println(WiFi.localIP());
lcd.begin(); // initialize the lcd Print a message to the LCD.
lcd.backlight();
Serial.println("LCD is ready");
}
void data(String url){
if( http.begin(client,host,httpPortRead,url)) //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
Data_Raw_1 = Data_Raw;
Data_Raw_1.replace("<td>","");
Data_Raw_1.replace("</td>","");
Data_Raw_1.replace("<td align=\"center\">","");
Data_Raw_1.replace(" ","");
Data_Raw_1.replace("\n"," ");
Data_Raw_1.remove(0,2);
State = Data_Raw_1.substring(0,Data_Raw_1.indexOf(" "));
Data_Raw_1.remove(0,Data_Raw_1.indexOf(" ")+1);
Cases = Data_Raw_1.substring(1,Data_Raw_1.indexOf(" "));
Data_Raw_1.remove(0,Data_Raw_1.indexOf(" ")+1);
Active = Data_Raw_1.substring(1,Data_Raw_1.indexOf(" "));
Data_Raw_1.remove(0,Data_Raw_1.indexOf(" ")+1);
Recovered = Data_Raw_1.substring(1,Data_Raw_1.indexOf(" "));
Data_Raw_1.remove(0,Data_Raw_1.indexOf(" ")+1);
Deaths = Data_Raw_1.substring(1,Data_Raw_1.length()-1);
Serial.println("0-------------------0");
Serial.print("State:");
Serial.println(State);
Serial.print("Cases:");
Serial.println(Cases);
Serial.print("Active:");
Serial.println(Active);
Serial.print("Recovered:");
Serial.println(Recovered);
Serial.print("Deaths:");
Serial.println(Deaths);
}
}
else //If we can't get data
{
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");
}
}
void display_data(){
lcd.setCursor(0, 0); // lcd.home();
lcd.print(State);
lcd.setCursor(0,1);
lcd.print("Total:");
lcd.setCursor(6,1);
lcd.print(Cases);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);// lcd.home();
lcd.print(State);
lcd.setCursor(0,1);
lcd.print("Recovr:");
lcd.setCursor(7,1);
lcd.print(Recovered);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0); // lcd.home();
lcd.print(State);
lcd.setCursor(0,1);
lcd.print("Active:");
lcd.setCursor(7,1);
lcd.print(Active);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0); // lcd.home();
lcd.print(State);
lcd.setCursor(0,1);
lcd.print("Deaths:");
lcd.setCursor(6,1);
lcd.print(Deaths);
delay(2000);
}
void loop() {
data(url1);
display_data();
lcd.clear();
data(url2);
display_data();
lcd.clear();
data(url3);
display_data();
lcd.clear();
data(url4);
display_data();
lcd.clear();
data(url5);
display_data();
lcd.clear();
}