-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpClient.h
More file actions
63 lines (45 loc) · 1.73 KB
/
httpClient.h
File metadata and controls
63 lines (45 loc) · 1.73 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
void httpPresetRadio() {
HTTPClient http;
PRESET = String(preset);
String presetToRadio = "http://192.168.43.45/?preset=" + PRESET;
dbgprint("Connexion 192.168.43.45 => PRESET n° %s", PRESET.c_str());
http.begin(presetToRadio); //HTTP
dbgprint("\n[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
dbgprint("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
dbgprint("%s \n", payload.c_str());
}
}
else {
dbgprint("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
myDFPlayer.play(1);
}
http.end();
}
void httpStopRadio() {
HTTPClient http;
http.begin("http://192.168.43.45/?stop"); //HTTP
dbgprint("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
dbgprint("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
dbgprint("%s \n",payload.c_str());
}
} else {
dbgprint("[HTTP] GET... failed, erro \n");
}
http.end();
}