-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhttp.ino
32 lines (27 loc) · 802 Bytes
/
http.ino
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
// Define HTTP Request Mechanism
String http(String url, char* headerType, String params){
// Define Response
String response;
HTTPClient http;
http.begin(url);
digitalWrite(blinkPin, LOW);
// Headers Handling
http.addHeader("Accept", "application/json");
http.addHeader("Content-Type", "application/json");
if(headerType == "gizwits" || headerType == "gizwitsMove"){
http.addHeader("X-Gizwits-Application-Id", appId);
http.addHeader("X-Gizwits-User-token", token);
}
// HTTP Mechanism
int httpResponseCode = http.POST(params);
// Denug Message
Serial.println(httpResponseCode);
if(httpResponseCode == 200){
response = http.getString();
} else {
response = "error";
}
http.end();
digitalWrite(blinkPin, HIGH);
return response;
}