-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathESPAsyncHTTPClient.h
61 lines (49 loc) · 1.23 KB
/
ESPAsyncHTTPClient.h
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
#ifndef ASYNCHTTPCLIENT_H_
#define ASYNCHTTPCLIENT_H_
#include "Arduino.h"
#ifdef ESP8266
#include "ESPAsyncTCP.h"
#else
#include "AsyncTCP.h"
#endif
#include <base64.h>
#ifndef DEBUG
#define DEBUG(...) {}
#endif
class ByteString: public String {
public:
ByteString(void *data, size_t len) :
String() {
copy(data, len);
}
ByteString() :
String() {
}
String& copy(const void *data, unsigned int length);
};
/**
* Asynchronous HTTP Client
*/
struct AsyncHTTPClient {
AsyncClient *aClient = NULL;
bool initialized = false;
String protocol;
String base64Authorization;
String host;
int port;
String uri;
String request;
ByteString response;
int statusCode;
void (*onSuccess)();
void (*onFail)(String);
void initialize(String url);
int getStatusCode() { return statusCode; }
String getBody();
static void clientError(void *arg, AsyncClient *client, err_t error);
static void clientDisconnect(void *arg, AsyncClient *client);
static void clientData(void *arg, AsyncClient *client, void *data, size_t len);
static void clientConnect(void *arg, AsyncClient *client);
void makeRequest(void (*success)(), void (*fail)(String msg));
};
#endif ASYNCHTTPCLIENT_H_