Built-in project · ESP32-C3-DevKitM-1

WiFi: join the network, on an ESP32-C3

The connect loop every ESP32 tutorial opens with, on a simulated network: no 802.11, no real internet, and the address a simulated DHCP hands out. The whole build, an ESP32-C3, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

BeginnerRuns in your browser. Free, and no account needed.

WiFi: join the network · ESP32-C3-DevKitM-1live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · ESP32-C3-DevKitM-1
/*
 * WiFi: join the network.
 *
 * The radio here is SIMULATED. There is no 802.11, no real access point and no
 * real internet: the network this joins is Mokxi's own, and the SSID and
 * password it wants are properties of the board (click the board, look for
 * wifiSsid and wifiPassword). Everything else (the calls, the status codes,
 * the one to three seconds it takes) is what an ESP32-C3 on a desk does.
 *
 * Try it wrong on purpose: change the password below and watch WL_CONNECT_FAILED
 * arrive five seconds later, which is what a real board does too.
 */
#include <WiFi.h>

const char *SSID = "Mokxi-Lab";
const char *PASSWORD = "breadboard";

void printStatus(wl_status_t status) {
  switch (status) {
    case WL_CONNECTED: Serial.println("connected"); break;
    case WL_CONNECT_FAILED: Serial.println("connect failed: wrong password"); break;
    case WL_NO_SSID_AVAIL: Serial.println("no network with that name"); break;
    case WL_DISCONNECTED: Serial.println("still connecting"); break;
    default: Serial.println("idle"); break;
  }
}

void setup() {
  Serial.begin(115200);
  Serial.println("WiFi on Mokxi: the radio is simulated, there is no 802.11.");
  Serial.print("joining ");
  Serial.println(SSID);

  WiFi.mode(WIFI_STA);
  WiFi.begin(SSID, PASSWORD);

  unsigned long started = millis();
  while (WiFi.status() != WL_CONNECTED && millis() - started < 12000) {
    Serial.print(".");
    delay(250);
    if (WiFi.status() == WL_CONNECT_FAILED || WiFi.status() == WL_NO_SSID_AVAIL) break;
  }
  Serial.println();

  Serial.print("status: ");
  printStatus(WiFi.status());

  if (WiFi.status() == WL_CONNECTED) {
    Serial.print("took ");
    Serial.print((long)(millis() - started));
    Serial.println(" ms");
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
    Serial.print("gateway: ");
    Serial.println(WiFi.gatewayIP());
    Serial.print("RSSI: ");
    Serial.print(WiFi.RSSI());
    Serial.println(" dBm (a setting on the board, not a measurement)");
    Serial.print("MAC: ");
    Serial.println(WiFi.macAddress());
  }
}

void loop() {
  delay(1000);
}

Parts list

2 parts, plus the jumper wires. Every one is in the editor's parts bin.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.