mirror of
https://github.com/arduino-libraries/ArduinoHttpClient.git
synced 2025-04-19 21:22:15 +03:00
Update example to use WiFi101
This commit is contained in:
parent
e057c073d9
commit
b72b7056a9
@ -6,20 +6,20 @@
|
|||||||
// outputs the content to the serial port
|
// outputs the content to the serial port
|
||||||
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <HttpClient.h>
|
#include <ArduinoHttpClient.h>
|
||||||
#include <Ethernet.h>
|
#include <WiFi101.h>
|
||||||
#include <EthernetClient.h>
|
|
||||||
|
|
||||||
// This example downloads the URL "http://arduino.cc/"
|
// This example downloads the URL "http://arduino.cc/"
|
||||||
|
|
||||||
|
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||||
|
char pass[] = "secretPassword"; // your network password
|
||||||
|
|
||||||
// Name of the server we want to connect to
|
// Name of the server we want to connect to
|
||||||
const char kHostname[] = "arduino.cc";
|
const char kHostname[] = "arduino.cc";
|
||||||
// Path to download (this is the bit after the hostname in the URL
|
// Path to download (this is the bit after the hostname in the URL
|
||||||
// that you want to download
|
// that you want to download
|
||||||
const char kPath[] = "/";
|
const char kPath[] = "/";
|
||||||
|
|
||||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
|
||||||
|
|
||||||
// Number of milliseconds to wait without receiving any data before we give up
|
// Number of milliseconds to wait without receiving any data before we give up
|
||||||
const int kNetworkTimeout = 30*1000;
|
const int kNetworkTimeout = 30*1000;
|
||||||
// Number of milliseconds to wait if no data is available before trying again
|
// Number of milliseconds to wait if no data is available before trying again
|
||||||
@ -27,21 +27,30 @@ const int kNetworkDelay = 1000;
|
|||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// initialize serial communications at 9600 bps:
|
//Initialize serial and wait for port to open:
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
while (!Serial) {
|
||||||
while (Ethernet.begin(mac) != 1)
|
; // wait for serial port to connect. Needed for native USB port only
|
||||||
{
|
|
||||||
Serial.println("Error getting IP address via DHCP, trying again...");
|
|
||||||
delay(15000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// attempt to connect to Wifi network:
|
||||||
|
Serial.print("Attempting to connect to WPA SSID: ");
|
||||||
|
Serial.println(ssid);
|
||||||
|
while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
|
||||||
|
// unsuccessful, retry in 4 seconds
|
||||||
|
Serial.print("failed ... ");
|
||||||
|
delay(4000);
|
||||||
|
Serial.print("retrying ... ");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
int err =0;
|
int err =0;
|
||||||
|
|
||||||
EthernetClient c;
|
WiFiClient c;
|
||||||
HttpClient http(c);
|
HttpClient http(c);
|
||||||
|
|
||||||
err = http.get(kHostname, kPath);
|
err = http.get(kHostname, kPath);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user