Connected ESP32 · Lesson
10 min read
Joining Wi-Fi
Connect to a network and print the board's IP address.
What You Will Learn
- Use WiFi.begin()
- Wait for a connection with a timeout
- Keep passwords out of shared code
Arduino C++
#include <WiFi.h>
const char* SSID = "your-network";
const char* PASS = "your-password";
void setup() {
Serial.begin(115200);
WiFi.begin(SSID, PASS);
unsigned long start = millis();
while (WiFi.status() != WL_CONNECTED && millis() - start < 15000) {
delay(250);
Serial.print(".");
}
Serial.println();
Serial.println(WiFi.status() == WL_CONNECTED ? WiFi.localIP() : "failed");
}
void loop() {}Don't share sketches that contain your real Wi-Fi password. Put credentials in a separate secrets.h file that you don't publish.
Radio isn't simulated. The Playground recognises Wi-Fi sketches and shows them as 'needs real hardware'.
Check Your Understanding
Test what you learned in this lesson