0
0
Arduinoprogramming~20 mins

WiFi with ESP8266/ESP32 in Arduino - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
WiFi Master with ESP8266/ESP32
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this ESP8266 WiFi connection code?

Consider this Arduino code for ESP8266 that tries to connect to a WiFi network. What will be printed on the Serial Monitor?

Arduino
void setup() {
  Serial.begin(115200);
  WiFi.begin("MySSID", "WrongPassword");
  int attempts = 0;
  while (WiFi.status() != WL_CONNECTED && attempts < 5) {
    delay(1000);
    Serial.print(".");
    attempts++;
  }
  if (WiFi.status() == WL_CONNECTED) {
    Serial.println("Connected!");
  } else {
    Serial.println("Failed to connect");
  }
}

void loop() {}
A.....Failed to connect
B.....Connected!
CConnected!
DFailed to connect
Attempts:
2 left
💡 Hint

Think about what happens if the password is wrong and how many times the code tries to connect.

🧠 Conceptual
intermediate
1:30remaining
Which WiFi mode allows ESP32 to connect to another WiFi network?

ESP32 supports multiple WiFi modes. Which mode should you use if you want your ESP32 to connect to your home WiFi router?

AWiFi.mode(WIFI_STA);
BWiFi.mode(WIFI_AP);
CWiFi.mode(WIFI_AP_STA);
DWiFi.mode(WIFI_OFF);
Attempts:
2 left
💡 Hint

Think about the mode where the device acts as a client connecting to an access point.

🔧 Debug
advanced
2:30remaining
Why does this ESP32 code fail to connect to WiFi?

Look at this code snippet. It never prints 'Connected!'. What is the bug?

Arduino
void setup() {
  Serial.begin(115200);
  WiFi.begin("SSID", "password");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting...");
  }
  Serial.println("Connected!");
}

void loop() {}
AThe delay is too short to connect
BWiFi.begin() is missing WiFi.mode(WIFI_STA); before it
CSerial.begin() baud rate is incorrect
DWiFi.status() returns WL_DISCONNECTED instead of WL_CONNECTED
Attempts:
2 left
💡 Hint

ESP32 needs to be in the right mode before connecting.

📝 Syntax
advanced
1:30remaining
Which option correctly initializes WiFi on ESP8266 to create an access point?

Choose the correct code snippet to start an access point named "MyESP" with password "12345678" on ESP8266.

AWiFi.createAP("MyESP", "12345678");
BWiFi.beginAP("MyESP", "12345678");
CWiFi.startAP("MyESP", "12345678");
DWiFi.softAP("MyESP", "12345678");
Attempts:
2 left
💡 Hint

Check the official ESP8266 WiFi library function names.

🚀 Application
expert
3:00remaining
How many IP addresses will be assigned after this ESP32 code runs?

Consider this ESP32 code that sets up both station and access point modes. How many IP addresses will the ESP32 have after setup?

Arduino
void setup() {
  WiFi.mode(WIFI_AP_STA);
  WiFi.softAP("ESP32_AP", "password");
  WiFi.begin("HomeSSID", "homepass");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
}

void loop() {}
A1
B3
C2
D0
Attempts:
2 left
💡 Hint

Think about IP addresses for both station and access point interfaces.