Reference   Language | Libraries | Comparison | Changes

WiFi

WiFi.status()

Description

Return the connection status.

Syntax

WiFi.status();

Parameters

none

Returns

  • WL_CONNECTED: assigned when connected to a WiFi network;

  • WL_NO_SHIELD: assigned when no WiFi shield is present;

  • WL_IDLE_STATUS: it is a temporary status assigned when WiFi.begin() is called and remains active until the number of attempts expires (resulting in WL_CONNECT_FAILED) or a connection is established (resulting in WL_CONNECTED);

  • WL_NO_SSID_AVAIL: assigned when no SSID are available;

  • WL_SCAN_COMPLETED: assigned when the scan networks is completed;

  • WL_CONNECT_FAILED: assigned when the connection fails for all the attempts;

  • WL_CONNECTION_LOST: assigned when the connection is lost;

  • WL_DISCONNECTED: assigned when disconnected from a network;

Example


#include <SPI.h>
#include <WiFi.h>

char ssid[] = "yourNetwork";                     // your network SSID (name)
char key[] = "D0D0DEADF00DABBADEAFBEADED";       // your network key
int keyIndex = 0;                                // your network key Index number
int status = WL_IDLE_STATUS;                     // the Wifi radio's status

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WEP network, SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, keyIndex, key);

    // wait 10 seconds for connection:
    delay(10000);
  }

  // once you are connected :
  Serial.print("You're connected to the network");
}

void loop() {
  // check the network status connection once every 10 seconds:
  delay(10000);
 Serial.println(WiFi.status());
}

 
Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.