Error using Wifi.begin


I tried to implement on a SAMD51 microcontroller, and using a (WiFi ESP Click) from MikroE the following code:

#include <ESP8266_Lib.h>
#undef max
#undef min
#include "FTTech_SAMD51Clicks.h"
#include "WiFiEsp.h"

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial SERIALCLICK     // the serial relative to the socket where your WiFi click is locates

ESP8266 wifi(&EspSerial);

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

// Initialize the Ethernet client object
WiFiEspClient client;

* Function Prototypes
void WiFiESPClick_Init(void);
void printWifiStatus(void);
* Function Definitions

// Define EN and RST pins
#define EN  ENSOCKET

void setup()
  // This will initiate the board
  // Enable 5V
  // Enable the power output of Click 2
  // Define Enable and Reset Pins of Click 2 as outputs
  pinMode(EN, OUTPUT);
  pinMode(RST, OUTPUT);  
  // Initialize serial for debugging and waits for console
  // Puts a space in debug window and hard resets WiFi module
  // initialize serial for ESP module and waits
  // initialize ESP module

  // 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 WPA SSID: ");
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);

  Serial.println("You're connected to the network");

void loop()

void printWifiStatus()
  // print the SSID of the network you're attached to
  Serial.print("SSID: ");

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

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

void WiFiESPClick_Init(){
  Serial.print("Reseting module");
  digitalWrite(EN, HIGH);
  digitalWrite(RST, LOW);
  digitalWrite(RST, HIGH);
  Serial.println(" Reseted!\n");

The issue I'm facing is about the connection with the Wifi.begin, it doesn't succeed and keep trying a connection indefinitely (as supposed to do, actually). Keep in mind that:

*The code used to work fine just a while ago (maybe I'm missing something that went wrong between updates).
*The connection with a cellphone hotspot works (and this is the strangest fact about this).

Thank you for your help.

In this case check your WiFi access point. You probably changed something. One fact to check is the chosen channel. Is it possible that your access point uses a channel which isn't allowed everywhere in the world (p.e. 13)?

Beforehand, I already checked the router for any IP blocking that could be happening. There are other devices connected to it also: notebooks, cellphones and other microcontrollers.

WiFi.begin(...) can return other things than WL_CONNECTED and these can be informative. What do you get?

I've done this:

It doesn't seem right, as stated here, 3 should be the same as WL_CONNECTED.

I printed WL_CONNECTED and it is 3. Sorry that you are having this issue. Does WiFi.printDiag(Serial) help?
Also, I am expecting this #include to look like

#include <ESP8266WiFi.h>

Hi again guys, and thank you for your interest,


My click isn't working anymore.
Possibly it was already malfunctioning when this first problem appeared as an indicative.
Now something else happened, and it works like a flute (emits a faint beep continuously).

As this issue can't be repaired as is, I'm waiting for a new click to arrive.