Skip to content

Commit 51c756a

Browse files
committed
Commit new SimpleGet example
1 parent 62632fe commit 51c756a

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

examples/SimpleGet/SimpleGet.ino

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Simple GET client for RestClient library
3+
Connects to server once per second, sends a GET request
4+
5+
note: WiFi SSID and password are stored in config.h file.
6+
If it is not present, add a new tab, call it "config.h"
7+
and add the following variables:
8+
char ssid[] = "ssid"; // your network SSID (name)
9+
char pass[] = "password"; // your network password
10+
11+
created 14 Feb 2016
12+
by Tom Igoe
13+
14+
this example is in the public domain
15+
*/
16+
#include <RestClient.h>
17+
#include <WiFi101.h>
18+
#include "config.h"
19+
20+
char serverAddress[] = "192.168.0.3"; // server address
21+
int port = 8080;
22+
23+
WiFiClient wifi;
24+
RestClient client = RestClient(wifi, serverAddress, port);
25+
int status = WL_IDLE_STATUS;
26+
String response;
27+
int statusCode = 0;
28+
29+
void setup() {
30+
Serial.begin(9600);
31+
while ( status != WL_CONNECTED) {
32+
Serial.print("Attempting to connect to Network named: ");
33+
Serial.println(ssid); // print the network name (SSID);
34+
35+
// Connect to WPA/WPA2 network:
36+
status = WiFi.begin(ssid, pass);
37+
}
38+
39+
// print the SSID of the network you're attached to:
40+
Serial.print("SSID: ");
41+
Serial.println(WiFi.SSID());
42+
43+
// print your WiFi shield's IP address:
44+
IPAddress ip = WiFi.localIP();
45+
Serial.print("IP Address: ");
46+
Serial.println(ip);
47+
statusCode = client.get("/");
48+
}
49+
50+
void loop() {
51+
Serial.print("Status code: ");
52+
Serial.println(statusCode);
53+
Serial.println("making GET request");
54+
55+
statusCode = client.get("/");
56+
response = client.readResponse();
57+
Serial.print("Response: ");
58+
Serial.println(response);
59+
Serial.println("Wait five seconds");
60+
delay(5000);
61+
}

examples/SimpleGet/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
char ssid[] = "ssid"; // your network SSID (name)
2+
char pass[] = "password"; // your network password

0 commit comments

Comments
 (0)