Sub topic 5
Checking status, IP address, and signal strength
This chapter assumes you can already upload a sketch, read Serial Monitor output, and connect a WiFiNINA board (such as the MKR WiFi 1010 or Nano 33 IoT) to a network with WiFi.begin() and an arduino_secrets.h file. It covers how to find out what state the connection is in, what address the board received, and how strong the radio link is. Later chapters rely on these checks before they send any request.
Why a successful `WiFi.begin()` is not the whole story
WiFi.begin(ssid, pass) returns a status code. It does not guarantee that the board will stay connected. The link can drop when the router restarts, when the signal weakens, or when the access point changes channel. A sketch that checks the status once in setup() and never again will keep trying to send data over a dead link.
Three questions are worth asking, and the library answers each one with a different call:
- Is the board connected right now? Use
WiFi.status(). - What address does the network know it by? Use
WiFi.localIP(). - How good is the radio link? Use
WiFi.RSSI().
Reading the connection status
WiFi.status() returns an integer constant that describes the state of the Wi-Fi module. The values you will meet most often are in this table.
| Constant | Meaning | Typical cause |
|---|---|---|
| `WL_NO_MODULE` | No Wi-Fi module was detected. | Wrong board selected, or the module's firmware is damaged. |
| `WL_IDLE_STATUS` | The module is idle and a connection attempt is not in progress. | The state before the first `WiFi.begin()` call. |
| `WL_NO_SSID_AVAIL` | The configured network was not found. | Wrong SSID, router out of range, or a 5 GHz-only network. |
| `WL_CONNECTED` | The board is connected to a network. | Normal operation. |
| `WL_CONNECT_FAILED` | The connection attempt failed. | Often a wrong password or a rejected connection. |
| `WL_CONNECTION_LOST` | An established connection was lost. | Router restart or the board moving out of range. |
| `WL_DISCONNECTED` | The board is disconnected from the network. | Router dropped the client, or the board called `WiFi.disconnect()`. |
Exact codes differ slightly between boards and library versions, so treat the table as a guide. Compare against the named constants and never against raw numbers.
The code is a number, which is awkward to read in the Serial Monitor. This helper turns it into text:
#include <WiFiNINA.h>
const char* statusName(int status) {
switch (status) {
case WL_NO_MODULE: return "NO_MODULE";
case WL_IDLE_STATUS: return "IDLE";
case WL_NO_SSID_AVAIL: return "NO_SSID_AVAIL";
case WL_CONNECTED: return "CONNECTED";
case WL_CONNECT_FAILED: return "CONNECT_FAILED";
case WL_CONNECTION_LOST: return "CONNECTION_LOST";
case WL_DISCONNECTED: return "DISCONNECTED";
default: return "UNKNOWN";
}
}
void setup() {
Serial.begin(115200);
while (!Serial && millis() < 5000) {}
Serial.print("Initial status: ");
Serial.println(statusName(WiFi.status()));
}
void loop() {}Because the output depends on the board's state, a board that has not yet called WiFi.begin() normally prints IDLE. A board with no module prints NO_MODULE.
Check for the module first
Before any connection attempt, test for WL_NO_MODULE. This is the check used in the connection sketch from the previous chapter:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Wi-Fi module not found");
while (true) {}
}The infinite loop is deliberate. Without a module, no later step can succeed, so stopping makes the failure obvious instead of letting the sketch print misleading errors.
Retry until connected
WiFi.begin() blocks while it tries to join the network and returns the status when it finishes. The usual pattern repeats the call until the status is WL_CONNECTED:
int status = WL_IDLE_STATUS;
while (status != WL_CONNECTED) {
Serial.print("Connecting to ");
Serial.println(SECRET_SSID);
status = WiFi.begin(SECRET_SSID, SECRET_PASS);
delay(10000);
}The ten-second delay gives the router time to finish the handshake. It also stops the sketch from flooding the access point with requests. This pattern is fine inside setup(). In loop() it is a problem, because it halts everything else. The chapter on non-blocking reconnection replaces it.
Reading the IP address
Once connected, the router's DHCP service assigns the board an IP address. WiFi.localIP() returns it as an IPAddress object. Serial.println() knows how to print that object in the familiar dotted form:
Serial.print("IP address: ");
Serial.println(WiFi.localIP());A typical result is 192.168.1.42. Addresses starting with 192.168., 10., or 172.16. through 172.31. are private. Only devices on your local network can reach them.
Related calls give the rest of the picture:
| Call | Returns |
|---|---|
| `WiFi.localIP()` | The board's own address. |
| `WiFi.subnetMask()` | The subnet mask, such as `255.255.255.0`. |
| `WiFi.gatewayIP()` | The router's address, which is the way out to the internet. |
| `WiFi.SSID()` | The name of the network the board is connected to. |
| `WiFi.BSSID(bssid)` | The access point's MAC address, copied into a 6-byte array. |
Treat `0.0.0.0` as a failure
If the board has not received an address, WiFi.localIP() returns 0.0.0.0. This can happen briefly right after a connection is made, or for longer if the router's DHCP service has run out of leases. A status of WL_CONNECTED together with an address of 0.0.0.0 means the radio link is up but the network layer is not ready. Check the address as well as the status before you start sending data.
Printing the MAC address
Routers that filter by MAC address need the board's hardware address. The library returns it as six bytes:
#include <WiFiNINA.h>
void printMac() {
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC address: ");
for (int i = 5; i >= 0; i--) {
if (mac[i] < 16) Serial.print('0');
Serial.print(mac[i], HEX);
if (i > 0) Serial.print(':');
}
Serial.println();
}
void setup() {
Serial.begin(115200);
while (!Serial && millis() < 5000) {}
printMac();
}
void loop() {}The library fills the array with the least significant byte first, so the loop counts down from index 5. If you print from index 0 upward, the address appears reversed.
Measuring signal strength with RSSI
WiFi.RSSI() returns the Received Signal Strength Indicator in dBm (decibels relative to one milliwatt). The value is negative. A number closer to zero means a stronger signal.
| RSSI (dBm) | Approximate quality | What to expect |
|---|---|---|
| -30 to -55 | Excellent | Very close to the router. |
| -56 to -67 | Good | Reliable for most uses, including streaming data. |
| -68 to -75 | Fair | Usable, but with occasional slow responses. |
| -76 to -85 | Weak | Frequent retries and dropped connections. |
| Below -85 | Very weak | Connection is unlikely to hold. |
These ranges are rules of thumb. Antenna design, walls, and interference all shift the practical limits. For a board that must run unattended, aim for -67 dBm or better at the installed location.
A value of 0 means no reading is available, for example when the board is not connected. Check the status first and read RSSI only when WL_CONNECTED is true.
A status report function
This sketch gathers the three checks into one function and prints a report every five seconds without blocking:
#include <WiFiNINA.h>
#include "arduino_secrets.h"
const unsigned long REPORT_INTERVAL_MS = 5000;
unsigned long lastReport = 0;
const char* statusName(int status) {
switch (status) {
case WL_NO_MODULE: return "NO_MODULE";
case WL_IDLE_STATUS: return "IDLE";
case WL_NO_SSID_AVAIL: return "NO_SSID_AVAIL";
case WL_CONNECTED: return "CONNECTED";
case WL_CONNECT_FAILED: return "CONNECT_FAILED";
case WL_CONNECTION_LOST: return "CONNECTION_LOST";
case WL_DISCONNECTED: return "DISCONNECTED";
default: return "UNKNOWN";
}
}
const char* qualityName(long rssi) {
if (rssi >= -55) return "excellent";
if (rssi >= -67) return "good";
if (rssi >= -75) return "fair";
if (rssi >= -85) return "weak";
return "very weak";
}
void printReport() {
int status = WiFi.status();
Serial.print("Status: ");
Serial.println(statusName(status));
if (status != WL_CONNECTED) return;
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
long rssi = WiFi.RSSI();
Serial.print("RSSI: ");
Serial.print(rssi);
Serial.print(" dBm (");
Serial.print(qualityName(rssi));
Serial.println(")");
}
void setup() {
Serial.begin(115200);
while (!Serial && millis() < 5000) {}
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Wi-Fi module not found");
while (true) {}
}
WiFi.begin(SECRET_SSID, SECRET_PASS);
}
void loop() {
if (millis() - lastReport >= REPORT_INTERVAL_MS) {
lastReport = millis();
printReport();
}
}A run that connects successfully produces output like this, with your own address and signal values:
Status: CONNECTED
SSID: your-network-name
IP address: 192.168.1.42
RSSI: -58 dBm (good)Notice that setup() calls WiFi.begin() once and then returns. The report keeps running while the connection is established, so you can watch the status change from IDLE or DISCONNECTED to CONNECTED. If the first call takes a while to join, the first reports show the earlier states.
Seeing the networks around you
WiFi.scanNetworks() returns the number of networks in range. For each index you can read the SSID, the signal strength, and the encryption type. A scan is useful when you cannot tell whether the board sees your network at all, which is the cause behind WL_NO_SSID_AVAIL.
#include <WiFiNINA.h>
void setup() {
Serial.begin(115200);
while (!Serial && millis() < 5000) {}
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Wi-Fi module not found");
while (true) {}
}
int count = WiFi.scanNetworks();
Serial.print("Networks found: ");
Serial.println(count);
for (int i = 0; i < count; i++) {
Serial.print(i);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" RSSI ");
Serial.print(WiFi.RSSI(i));
Serial.println(" dBm");
}
}
void loop() {}If your network is missing from the list, the board cannot see it. The usual reasons are a router broadcasting only on 5 GHz, a hidden SSID, or distance. The WiFiNINA boards support 2.4 GHz only.
How the checks fit together
A reliable sketch confirms each layer in order. The diagram shows the decision path that later chapters build on.
A weak signal does not stop the sketch in this design. It logs a warning, because a weak link is often still usable and the log gives you a record to explain later failures.
Common mistakes
- Reading RSSI while disconnected. The value is meaningless and can mislead a quality check. Gate the read on
WL_CONNECTED. - Comparing the status to a number. Codes vary across boards. Use the named constants.
- Assuming
WL_CONNECTEDmeans internet access. It means only that the board joined the access point. - Printing the MAC address in the wrong order. The array is least significant byte first.
- Calling
WiFi.begin()on every pass throughloop(). This restarts the connection attempt repeatedly and can prevent it from ever finishing. Call it once, or rate-limit it as described in the reconnection chapter. - Using a 5 GHz network. The board will report
WL_NO_SSID_AVAILbecause it never sees the network.
Exercises
Exercise
A sketch reports WL_CONNECTED, but WiFi.localIP() prints 0.0.0.0. What does this tell you, and what should the sketch do before sending data?
Show answer
The radio link to the access point is up, but the board has not received an address from the router's DHCP service yet, or DHCP failed. The sketch should wait and re-check until WiFi.localIP() returns a real address, and treat a persistent 0.0.0.0 as a connection failure (for example by retrying WiFi.begin() or checking the router's DHCP lease table).
Exercise
Your board prints an RSSI of -82 dBm at its installed location, and the connection drops every few hours. Which quality band is that, and name two practical changes that could improve it.
Show answer
-82 dBm falls in the weak band (-76 to -85 dBm), where retries and drops are common. Moving the board or the access point closer, using a board or antenna with better reception, removing obstructions such as metal or concrete, or adding a second access point or range extender near the board would all improve the signal. Reconnection code is also needed, since weak links will still drop occasionally.
Exercise
A scan lists many networks, but yours is missing, and WiFi.status() returns WL_NO_SSID_AVAIL. Give two likely causes.
Show answer
The router may broadcast only on 5 GHz, which WiFiNINA boards cannot use, or the board may be out of range of the access point. A hidden SSID or a typing error in SECRET_SSID are also possible causes.