Skip to content

Latest commit

 

History

History
50 lines (37 loc) · 1.13 KB

README.md

File metadata and controls

50 lines (37 loc) · 1.13 KB

lesson 05 - connecting to WiFi

GOAL: Connecting to local wifi network and obtaining an IP number

The example below connects to local WiFi network and prints assigned IP number

  1. Rename "your-ssid" and "your-password" with real WiFi network credentials.

main.cpp:

#include <ESP8266WiFi.h>

#ifndef STASSID
#define STASSID "your-ssid"
#define STAPSK  "your-password"
#endif

const char* ssid     = STASSID;
const char* password = STAPSK;

void setup() {
  Serial.begin(9600);

  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  /* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
     would try to act as both a client and an access-point and could cause
     network-issues with your other WiFi-devices on your WiFi-network. */
  WiFi.mode(WIFI_STA);
  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());
}

void loop() {
}