Connect to WiFi

esp8266

Connect to WiFi given ssid and password

Code

Download code
#include <ESP8266WiFi.h>

// Edit "secret" ssid and password below
const char* ssid = "secret";
const char* password = "secret";

void setup() {
  pinMode(2, OUTPUT);  // GPIO02 on ESP-12 module is linked to on-board LED

  Serial.begin(115200);
  delay(10);

  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());

  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(2, HIGH);
  Serial.println(WiFi.localIP());
  delay(1000);
  digitalWrite(2, LOW);
  delay(1000);
}