-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
HTTP.h
187 lines (166 loc) · 7.04 KB
/
HTTP.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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#ifndef HTTP_h
#define HTTP_h
#include <Arduino.h>
#include "DTE.h"
#include "IP.h"
struct HttpStatus {
char mode[5];
unsigned char status;
unsigned long finish;
unsigned long remain;
};
class HTTP {
private:
DTE *dte;
IP *ip;
bool initialized;
struct HttpStatus httpStatus;
unsigned long serverResponseDataLength;
bool sslEnabled;
public:
HTTP(DTE &dte, IP &ip);
/**
* Convert HTTP Method to index
* @param method HTTP Method
* @return index of Method
* 0: GET
* 1: POST
* 2: HEAD
*/
unsigned char methodIndex(const char method[]);
unsigned char methodIndex(const __FlashStringHelper *method);
/**
* Command AT+HTTPINIT
* @return true: If command successful, false: Otherwise
*/
bool atInitializeHttpService(void);
/**
* Command AT+HTTPTERM
* @return true: If command successful, false: Otherwise
*/
bool atTerminateHttpService(void);
/**
* Command AT+HTTPPARA
* @param paramTag Parameter Tag
* "CID": Context Identifier Used, see IP Class
* "URL": HTTP Client URL
* "UA": User Agent
* "PROIP": IP Address of HTTP Proxy Server
* "PROPORT": Port of HTTP Proxy Server
* "REDIR": If set to 1, automatic redirect, otherwise no, default is 0
* "BREAK": Integer start address. Parameter for Method GET, for resuming broken transfer, start from BREAK to BREAKEND
* "BREAKEND": Integer end address.
* "TIMEOUT": HTTP Session Timeout value, range 30 - 1000 second, default is 120
* "CONTENT": Used to set Content-Type in HTTP Header
* "USERDATA": Used to set user's data in HTTP Header
* @param paramValue Parameter Value
* @return true: If command successful, false: Otherwise
* @{
*/
bool atSetHttpParametersValue(const char paramTag[], const char paramValue[], const char userdataDelimiter[] = "");
bool atSetHttpParametersValue(const __FlashStringHelper *paramTag, const char paramValue[], const char userdataDelimiter[] = "");
bool atSetHttpParametersValue(const char paramTag[], const __FlashStringHelper *paramValue, const char userdataDelimiter[] = "");
bool atSetHttpParametersValue(const __FlashStringHelper *paramTag, const __FlashStringHelper *paramValue, const char userdataDelimiter[] = "");
bool atSetHttpParametersValue(const char paramTag[], const char paramValue[], const __FlashStringHelper *userdataDelimiter);
bool atSetHttpParametersValue(const __FlashStringHelper *paramTag, const char paramValue[], const __FlashStringHelper *userdataDelimiter);
bool atSetHttpParametersValue(const char paramTag[], const __FlashStringHelper *paramValue, const __FlashStringHelper *userdataDelimiter);
bool atSetHttpParametersValue(const __FlashStringHelper *paramTag, const __FlashStringHelper *paramValue, const __FlashStringHelper *userdataDelimiter);
/**
* Command AT+HTTPDATA
* @param data POST data
* @param timeout Timeout to input POST data
* @return true: If command successful, false: Otherwise
*/
bool atInputHttpData(const char data[], unsigned int timeout = 2000);
bool atInputHttpData(const __FlashStringHelper *data, unsigned int timeout = 2000);
/**
* Command AT+HTTPACTION=
* @param method HTTP Action Method
* 0: GET
* 1: POST
* 2: HEAD
* @return true: If command successful, false: Otherwise
*/
bool atHttpMethodAction(unsigned char method);
/**
* Command AT+HTTPREAD
* @param dataRecieved Buffer to store the data, buffer size should be edaquate
* @param startAddress Starting data output
* @param byteSize Length for data output
* @return true: If command successful, false: Otherwise
*/
bool atReadHttpServerResponse(char dataRecieved[], unsigned long startAddress, unsigned long byteSize);
/**
* Command AT+HTTPSTATUS
* @return true: If command successful, false: Otherwise
*/
bool atReadHttpStatus(void);
/**
* Command AT+HTTPSSL?
* @return true: If command successful, false: Otherwise
*/
bool atSslHttp(void);
/**
* Command AT+HTTPSSL=
* @param enable true: Enable, false: Disabled
* @return true: If command successful, false: Otherwise
*/
bool atSslHttp(bool enable);
/**
* Get current HTTP Status
* @return HttpStatus Struct
*/
struct HttpStatus getStatus(void);
/**
* Initialize HTTP
* @param timeout Set timeout in seconds, default: 30 (minimum)
* @param cid Context Identifier, default: 1
* @return true: If initialize, false: Otherwise
*/
bool initialize(unsigned int timeout = 30, unsigned char cid = 1);
/**
* Set User Agent
* @param userAgent User Agent string
* @return true: If success, false: Otherwise
*/
bool setUserAgent(const char userAgent[]);
bool setUserAgent(const __FlashStringHelper *userAgent);
/**
* Set Header
* @param header Header string with semicolon demiliter
* @return true: If success, false: Otherwise
*/
bool setHeaders(const char header[], const char userdataDelimiter[] = "");
bool setHeaders(const __FlashStringHelper *header, const char userdataDelimiter[] = "");
bool setHeaders(const char header[], const __FlashStringHelper *userdataDelimiter);
bool setHeaders(const __FlashStringHelper *header, const __FlashStringHelper *userdataDelimiter);
/**
* Submit HTTP Action
* @param method Method "GET", "POST", or "HEAD"
* @param url HTTP Client URL
* @param data POST data, if action is POST
* @return true: If success, false: Otherwise
*/
bool action(const char method[], const char url[], const char data[] = NULL);
bool action(const __FlashStringHelper *method, const char url[], const char data[] = NULL);
bool action(const char method[], const __FlashStringHelper *url, const char data[] = NULL);
bool action(const __FlashStringHelper *method, const __FlashStringHelper *url, const char data[] = NULL);
bool action(const char method[], const char url[], const __FlashStringHelper *data);
bool action(const __FlashStringHelper *method, const char url[], const __FlashStringHelper *data);
bool action(const char method[], const __FlashStringHelper *url, const __FlashStringHelper *data);
bool action(const __FlashStringHelper *method, const __FlashStringHelper *url, const __FlashStringHelper *data);
/**
* Read HTTP Server Response
* @param buffer Buffer to store the data, buffer size should be edaquate
* @param length Length data to be read
* @param startAddress Read data output from start address, default: 0 (beginning)
* @return true: If success, false: Otherwise
*/
bool readDataReceived(char buffer[], unsigned long length, unsigned long startAddress = 0);
/**
* Terminate HTTP
* @return true: If success, false: Otherwise
*/
bool terminate(void);
};
#endif