-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGET_Example.ino
More file actions
66 lines (56 loc) · 1.68 KB
/
Copy pathGET_Example.ino
File metadata and controls
66 lines (56 loc) · 1.68 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
#include <WiFi.h>
#include "AsyncHTTPClientLight.h"
const char* ssid = "TUO_SSID";
const char* password = "TUA_PASSWORD";
AsyncHTTPClientLight client;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Connessione WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(" connesso!");
Serial.println(WiFi.localIP());
// Configurazione client
client.setDebug(true);
client.setLogToFile(true);
client.setMaxRetries(3);
client.setTimeout(8000);
// Callback unificato
client.onEvent([](HTTPEventType type, const String& msg) {
switch (type) {
case HTTPEventType::Response:
Serial.println("Risposta ricevuta: " + msg);
Serial.println("Codice HTTP: " + String(client.getLastHTTPcode()));
break;
case HTTPEventType::Timeout:
Serial.println("Timeout: " + msg);
break;
case HTTPEventType::Error:
Serial.println("Errore: " + msg);
break;
case HTTPEventType::Chunk:
Serial.println("Chunk ricevuto: " + msg);
break;
case HTTPEventType::Overload:
Serial.println("Richiesta ignorata: " + msg);
break;
}
});
// Header personalizzati
client.addHeader("Authorization", "Bearer xyz123");
client.addHeader("Custom-Header", "DavidePower");
// Titolo per logging
client.addTitle("Richiesta GET iniziale");
// Avvio richiesta asincrona
client.beginRequest("http://httpbin.org/get", "GET", "");
}
void loop() {
client.poll();
if (client.isFinished()) {
Serial.println("Risposta ricevuta:");
Serial.println(client.getLastResponseBody());
}
}