-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalert_api.ino
More file actions
52 lines (40 loc) · 927 Bytes
/
alert_api.ino
File metadata and controls
52 lines (40 loc) · 927 Bytes
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
#include "alert_api.h"
AlertAPI::AlertAPI(char* url, char *key){
this->apiUrl = url;
this->apiKey = key;
}
int AlertAPI::IsAlert(){
HTTPClient http;
http.begin(this->apiUrl);
http.addHeader("X-API-Key", this->apiKey);
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
#ifdef DEBUG
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
#endif
String payload = http.getString();
#ifdef DEBUG
Serial.println(payload);
#endif
http.end();
StaticJsonDocument<128> jsonResponse;
deserializeJson(jsonResponse, payload);
bool is_alert = jsonResponse["alert"];
if(is_alert){
#ifdef DEBUG
Serial.println("alert");
#endif
return 1;
}
#ifdef DEBUG
Serial.println("no alert");
#endif
return 0;
}
http.end();
#ifdef DEBUG
Serial.println("No response from the server");
#endif
return 2;
}