Connecting via WiFi
OK once you've got the LED blinking, lets go straight to the fun part, connecting to a
webserver. Create a new sketch with this code:
/*
* Simple HTTP get webclient test
*/
#include <ESP8266WiFi.h>
const char* ssid = "yourssid";
const char* password = "yourpassword";
const char* host = "wifitest.adafruit.com";
void setup() {
Serial.begin(115200);
delay(100);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop() {
delay(5000);
++value;
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
String url = "/testwifi/index.html";
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
©Adafruit Industries
Page 38 of 53
Содержание Feather HUZZAH ESP8266
Страница 4: ...Adafruit Industries Page 4 of 53...