Skip to content

Commit b72b705

Browse files
committed
Update example to use WiFi101
1 parent e057c07 commit b72b705

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

examples/SimpleHttpExample/SimpleHttpExample.ino

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,51 @@
66
// outputs the content to the serial port
77

88
#include <SPI.h>
9-
#include <HttpClient.h>
10-
#include <Ethernet.h>
11-
#include <EthernetClient.h>
9+
#include <ArduinoHttpClient.h>
10+
#include <WiFi101.h>
1211

1312
// This example downloads the URL "http://arduino.cc/"
1413

14+
char ssid[] = "yourNetwork"; // your network SSID (name)
15+
char pass[] = "secretPassword"; // your network password
16+
1517
// Name of the server we want to connect to
1618
const char kHostname[] = "arduino.cc";
1719
// Path to download (this is the bit after the hostname in the URL
1820
// that you want to download
1921
const char kPath[] = "/";
2022

21-
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
22-
2323
// Number of milliseconds to wait without receiving any data before we give up
2424
const int kNetworkTimeout = 30*1000;
2525
// Number of milliseconds to wait if no data is available before trying again
2626
const int kNetworkDelay = 1000;
2727

2828
void setup()
2929
{
30-
// initialize serial communications at 9600 bps:
31-
Serial.begin(9600);
30+
//Initialize serial and wait for port to open:
31+
Serial.begin(9600);
32+
while (!Serial) {
33+
; // wait for serial port to connect. Needed for native USB port only
34+
}
3235

33-
while (Ethernet.begin(mac) != 1)
34-
{
35-
Serial.println("Error getting IP address via DHCP, trying again...");
36-
delay(15000);
37-
}
36+
// attempt to connect to Wifi network:
37+
Serial.print("Attempting to connect to WPA SSID: ");
38+
Serial.println(ssid);
39+
while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
40+
// unsuccessful, retry in 4 seconds
41+
Serial.print("failed ... ");
42+
delay(4000);
43+
Serial.print("retrying ... ");
44+
}
45+
46+
Serial.println("connected");
3847
}
3948

4049
void loop()
4150
{
4251
int err =0;
4352

44-
EthernetClient c;
53+
WiFiClient c;
4554
HttpClient http(c);
4655

4756
err = http.get(kHostname, kPath);

0 commit comments

Comments
 (0)