WiFiEsp WiFi.status()

Hi all!

I’m using an ESP8266 and Arduino Zero with the WiFiEsp library.

Don’t understand how WiFi.status() works.

It should return an int as indicated at : Arduino - WiFiStatus

I tried to force a “WL_CONNECT_FAILED” putting a wrong password for my home network, but the return

is always “WL_IDLE_STATUS” which is number 3.

I think I’m missing something…

Help is appreciated :slight_smile:

Thank you

/*
 WiFiEsp example: ConnectWPA
 
 This example connects to an encrypted WiFi network using an ESP8266 module.
 Then it prints the  MAC address of the WiFi shield, the IP address obtained
 and other network details.

 For more details see: http://yaab-arduino.blogspot.com/p/wifiesp-example-connect.html
*/

#include "WiFiEsp.h"

char ssid[] = "SSID";                  // your network SSID (name)
char pass[] = "password";        // your network password
int status = WL_IDLE_STATUS;              // the Wifi radio's status
int i = 0;

void setup()
{
  // initialize serial for debugging
  Serial.begin(115200);
  while(!SerialUSB){;}
  // initialize serial for ESP module
  Serial1.begin(115200);
  // initialize ESP module
  WiFi.init(&Serial1);  
}

void loop()
{ 
  status = WiFi.status();
  Serial.print("WIFISTATUS.:");
  Serial.println(WiFi.status());
  Serial.print("I.:");
  Serial.println(i);
   while((status != WL_CONNECTED) && (i<5))
    {
      WiFi.begin(ssid, pass); 
      i++;
      Serial.println("Trying to Reconnect to WiFi Network ");
      delay(5000);
      status = WiFi.status();
      //Serial.println(status);
    }
 
    Serial.println();
   // printCurrentNet();
   // printWifiData();

  delay(5000);
}

void printWifiData()
{
  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print your MAC address
  byte mac[6];
  WiFi.macAddress(mac);
  char buf[20];
  sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
  Serial.print("MAC address: ");
  Serial.println(buf);
}

void printCurrentNet()
{
  // print the SSID of the network you're attached to
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print the MAC address of the router you're attached to
  byte bssid[6];
  WiFi.BSSID(bssid);
  char buf[20];
  sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", bssid[5], bssid[4], bssid[3], bssid[2], bssid[1], bssid[0]);
  Serial.print("BSSID: ");
  Serial.println(buf);

  // print the received signal strength
  long rssi = WiFi.RSSI();
  Serial.print("Signal strength (RSSI): ");
  Serial.println(rssi);

  Serial.print("WiFi Status.:");
  Serial.println(WiFi.status());
}

Found on the WiFiEsp library this:

typedef enum {
	WL_NO_SHIELD = 255,
	WL_IDLE_STATUS = 0,
	//WL_NO_SSID_AVAIL,
	//WL_SCAN_COMPLETED,
	WL_CONNECTED,
	WL_CONNECT_FAILED,
	//WL_CONNECTION_LOST,
	WL_DISCONNECTED
} wl_status_t;