Communication Protocols

Lesson 102: Wi‑Fi Connect (Simulated)

Practice a Wi‑Fi connect flow conceptually: scan, connect with SSID/password, and print a mock IP address using Serial output.

Progress indicator

Lesson 102 of 102

Learning Objectives

  • Understand the basic Wi‑Fi STA connect flow (scan, connect, IP).
  • See how Serial logging documents connection steps.
  • Use a simulated IP to keep learning without real hardware.
  • Recognize that simulator Wi‑Fi is mocked, not a real radio.

Concept Explanation

What this lesson covers

A conceptual Wi‑Fi station (STA) connection: scan, authenticate, connect, and print an IP address. In the simulator this is fully mocked—no real Wi‑Fi hardware is involved.

Key steps in code

  • Serial begin for logs.
  • Scan phase (simulated delay + message).
  • Connect phase (simulated delay + SSID).
  • Success log plus mock IP address.

Why mock Wi‑Fi here?

The learning goal is the flow, not a real network. The simulator provides consistent outputs even without hardware or access points.

Example Code

Simulated Wi‑Fi scan/connect with Serial logs and a mock IP.

// Simulated Wi-Fi connect flow (no real radio)
#include <WiFi.h>

const char* ssid = "LabNet";
const char* password = "12345678";

void setup() {
  Serial.begin(115200);
  Serial.println("Scanning...");
  delay(500);

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

  Serial.println("Connected!");
  Serial.println("IP address: 192.168.4.42");
}

void loop() {
  delay(1000);
}

Example Code Explanation

  1. #include <WiFi.h> keeps the API familiar, though simulation is mocked.
  2. Serial logs document each phase (scan, connect, success).
  3. Delays simulate time spent scanning and authenticating.
  4. Mock IP shows what a success log would look like.
  5. loop() idles to keep output stable.

What Happens Inside

  1. Simulated scan step logs to Serial.
  2. Simulated connect step waits and logs target SSID.
  3. Mock success prints a fixed IP address.
  4. No real radio traffic occurs in the simulator.

Common Mistakes with Simulated Wi‑Fi

  • Expecting real network access or ping responses inside the simulator.
  • Forgetting that scan/connect delays here are just illustrative.

Best Practices for Wi‑Fi Learning

  • Use Serial logs to track each stage of connection.
  • Keep code structured: scan → connect → report IP.
  • Move to real hardware once you understand the flow.

Try it now

Open the simulator and step through the mocked Wi‑Fi connect flow.

Run in Simulator