-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebClient.cpp
More file actions
45 lines (37 loc) · 1.16 KB
/
WebClient.cpp
File metadata and controls
45 lines (37 loc) · 1.16 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
#include <Arduino.h>
#include <Ethernet.h>
#include "HttpClient.h"
#include "WebClient.h"
// this must be unique
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// change to your network settings
IPAddress ip(192, 168, 1, 177);
IPAddress gateway(192, 168, 1, 253);
IPAddress subnet(255, 255, 255, 0);
EthernetClient net;
const char serverAddress[] ="210.19.20.195"; //"192.168.1.138"; // server address
int port = 80;
HttpClient client = HttpClient(net, serverAddress, port);
int statusCode = 0;
String response;
void WEB_CLIENT::setup() {
Serial.println(F("Setting Up Web Client..."));
Ethernet.begin(mac, ip, gateway, gateway, subnet);
Serial.println(Ethernet.localIP());
delay(7000);
Serial.println(F("Web Client Ready..."));
}
int WEB_CLIENT::webget(const String& URLPath, String& respBody, int& respCode)
{
int ret = client.get(URLPath);
if(ret==0)
{
respBody = client.responseBody();
//respCode = client.responseStatusCode();
//Serial.println("ret: " + String(ret));
//Serial.println("respCode: " + String(respCode));
//Serial.println("respBody: " + respBody);
}
client.stop();
return ret;
}