Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit efbfe56

Browse files
added a sample for REST API HTTP Request GET METHOD
1 parent c83e16e commit efbfe56

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

‎REST-API-GET/REST-API-GET.ino

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include <SPI.h>
2+
#include <Ethernet.h>
3+
4+
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
5+
IPAddress my_ip(192,168,1,75);
6+
IPAddress server(192,168,1,201);
7+
8+
EthernetClient client;
9+
10+
String temp = "data=5";
11+
bool printWebData = true;
12+
13+
void setup() {
14+
int monitor_serial = 9600;
15+
Serial.begin(monitor_serial);
16+
17+
// wait for serial port to connect
18+
while(!Serial) {
19+
;
20+
}
21+
22+
Ethernet.begin(mac, my_ip);
23+
24+
Serial.print("My IP Address : ");
25+
Serial.println(my_ip);
26+
Serial.print("Destination Server : ");
27+
Serial.println(server);
28+
Serial.println("Connecting ...");
29+
delay(3000);
30+
31+
// connect to server with standard port 80
32+
if(client.connect(server, 80)) {
33+
Serial.println("Connected to server.");
34+
Serial.println();
35+
delay(1000);
36+
Serial.println("Requesting Data from server ...");
37+
// client.println("GET /epass-passenger/api/test?data=5 HTTP/1.1");
38+
// Serial.println("GET /epass-passenger/api/test?data=5 HTTP/1.1");
39+
client.print("GET /epass-passenger/api/test?");
40+
Serial.print("GET /epass-passenger/api/test?");
41+
client.print(temp);
42+
Serial.print(temp);
43+
client.println(" HTTP/1.1");
44+
Serial.println(" HTTP/1.1");
45+
client.print("Host : ");
46+
client.println(server);
47+
client.println("Content Type : application/x-www-form-urlencoded");
48+
client.println("Connection : close");
49+
client.println("User-Agent : Arduino/1.0");
50+
client.println();
51+
} else {
52+
Serial.print("Cannot connect to ");
53+
Serial.println(server);
54+
}
55+
}
56+
57+
void loop() {
58+
if(client.available()) {
59+
char c = client.read();
60+
Serial.print(c);
61+
}
62+
63+
if(!client.connected()) {
64+
Serial.println();
65+
Serial.println("Disconnecting ...");
66+
delay(3000);
67+
client.stop();
68+
Serial.println("Disconnected.");
69+
while(true) {
70+
delay(1);
71+
}
72+
}
73+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /