Esp32 Wifi error 254

Hello good afternoon, my brother and I decided to make a project with the Esp32-C3-Mini1 module, with our own PCB.

The problem we have is that when running any program that has a wifi function, it executes all the lines until it arrives to any of the wifi functions and then it stops executing.

The only Wifi function that works for us is the wifi.status and it returns the code "254". We have searched for this code but we have not found anything.

The board we are using is the: ESP32C3 Dev Module

Has anyone had or knows how to solve this problem?

Thank you very much,

Ferran Serra

The wifi scan example shows the mode like this:
WiFi.mode(WIFI_STA);

Thank you very much for your answer, but I just tried what you told me and it didn't do the same.

Please do not post pictures of code

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

1 Like

Thank you very much for your answer and my apologies for the photos, I'm new here.

escribe o pega el cĂłdigo aquĂ­
````/ Incluimos primero la librerĂ­a /
#include <WiFi.h>

  void setup() {
  Serial.begin(115200);
  Serial.println("#########################################################################################################################################################");
  Serial.println(WiFi.status());
  try {
    WiFi.mode(WIFI_STA);
    Serial.println("Hola");
    WiFi.disconnect();
    delay(100);
    int n = WiFi.scanNetworks();
    if (n == WIFI_SCAN_FAILED) {
      throw std::runtime_error("Error al escanear redes Wi-Fi.");
    }
    // ContinĂșa con el cĂłdigo
  } catch (const std::exception& e) {
    Serial.print("ExcepciĂłn: ");
    Serial.println(e.what());
  }
}

void loop() {
  // No se requiere cĂłdigo en el loop
}

Try using the WifiScan example that comes with the ESP32 board package.

I used the Wifi Scan example and added 2 prints. “Start” and ‘Pass 2’, as you can see in the serial monitor message, the first print is done correctly but when passing Wifi.mode(WIFI_STA); it stops executing and tries to execute again, but it never gets to do the second print.

Serial Monitor:

22:46:13.268 -> ESP-ROM:esp32c3-api1-20210207
22:46:19.535 -> #### Start
22:46:19.535 -> ESP-ROM:esp32c3-api1-20210207
22:46:19.535 -> Build:Feb 7 2021
22:46:19.581 -> rst:0x3 (RTC_SW_SYS_RST),boot:0xf (SPI_FAST_FLASH_BOOT)
22:46:19.581 -> Saved PC:0x40048b82
22:46:19.581 -> SPIWP:0xee
22:46:19.581 -> mode:DIO, clock div:1
22:46:19.581 -> load:0x3fcd5820,len:0x458
22:46:19.581 -> load:0x403cc710,len:0x814
22:46:19.581 -> load:0x403ce710,len:0x2880
22:46:19.581 -> entry 0x403cc710
22:46:19.706 -> #### Start

/*
 *  This sketch demonstrates how to scan WiFi networks.
 *  The API is based on the Arduino WiFi Shield library, but has significant changes as newer WiFi functions are supported.
 *  E.g. the return value of encryptionType() different because more modern encryption is supported.
 */
#include "WiFi.h"

void setup() {
  Serial.begin(115200);

  // Set WiFi to station mode and disconnect from an AP if it was previously connected.
  Serial.println("#### Start");
  WiFi.mode(WIFI_STA);
  Serial.println("#### Pass 2");
  WiFi.disconnect();
  delay(100);

  Serial.println("Setup done");
}

void loop() {
  Serial.println("Scan start");

  // WiFi.scanNetworks will return the number of networks found.
  int n = WiFi.scanNetworks();
  Serial.println("Scan done");
  if (n == 0) {
    Serial.println("no networks found");
  } else {
    Serial.print(n);
    Serial.println(" networks found");
    Serial.println("Nr | SSID                             | RSSI | CH | Encryption");
    for (int i = 0; i < n; ++i) {
      // Print SSID and RSSI for each network found
      Serial.printf("%2d", i + 1);
      Serial.print(" | ");
      Serial.printf("%-32.32s", WiFi.SSID(i).c_str());
      Serial.print(" | ");
      Serial.printf("%4ld", WiFi.RSSI(i));
      Serial.print(" | ");
      Serial.printf("%2ld", WiFi.channel(i));
      Serial.print(" | ");
      switch (WiFi.encryptionType(i)) {
        case WIFI_AUTH_OPEN: Serial.print("open"); break;
        case WIFI_AUTH_WEP: Serial.print("WEP"); break;
        case WIFI_AUTH_WPA_PSK: Serial.print("WPA"); break;
        case WIFI_AUTH_WPA2_PSK: Serial.print("WPA2"); break;
        case WIFI_AUTH_WPA_WPA2_PSK: Serial.print("WPA+WPA2"); break;
        case WIFI_AUTH_WPA2_ENTERPRISE: Serial.print("WPA2-EAP"); break;
        case WIFI_AUTH_WPA3_PSK: Serial.print("WPA3"); break;
        case WIFI_AUTH_WPA2_WPA3_PSK: Serial.print("WPA2+WPA3"); break;
        case WIFI_AUTH_WAPI_PSK: Serial.print("WAPI"); break;
        default: Serial.print("unknown");
      }
      Serial.println();
      delay(10);
    }
  }
  Serial.println("");

  // Delete the scan result to free memory for code below.
  WiFi.scanDelete();

  // Wait a bit before scanning again.
  delay(5000);
}

The example works perfectly for me right out of the box, no changes required. Tested with ESP32 Board Package 2.17.

We have the 3.0.3 ESP32 package, which is currently the latest version, we also have the latest version of arduino ide and the ESP32 are right out of the box. We have an ESP32-C3-Mini1 without kit, it is implemented on a PCB of its own, maybe the problem is in the board we select, in this case the “Esp32C3 Dve Module”? Or in some arduino configuration?

If you hover the cursor over status

  Serial.println(WiFi.status());

you should see a tooltip. (If you don't, try to re-Verify.)

instance-method status
→ wl_status_t
STA WiFi info

// In WiFiSTAClass
public: wl_status_t status()

It says that status returns a wl_status_t. You can search for that type. You can also right-click and choose Go to Definition, which should open WiFiSTA.h

  wl_status_t status();

and do the same thing for that type, opening WiFiType.h

typedef enum {
  WL_NO_SHIELD = 255,  // for compatibility with WiFi Shield library
  WL_STOPPED = 254,
  WL_IDLE_STATUS = 0,
  WL_NO_SSID_AVAIL = 1,
  WL_SCAN_COMPLETED = 2,
  WL_CONNECTED = 3,
  WL_CONNECT_FAILED = 4,
  WL_CONNECTION_LOST = 5,
  WL_DISCONNECTED = 6
} wl_status_t;

So 254 is WL_STOPPED. If you hover over the file tab, you can see the full path to the file, which will be something like packages/esp32/hardware/esp32/3.0.4/libraries/WiFi/src/WiFiType.h. That corresponds to the file in the repository at that specific version, 3.0.4. (Note this macro constant is not defined in v2 of the library, which is still in common use.)

WL_STOPPED is entirely expected, since nothing has been done with the WiFi yet. The 254 is not a problem.

Setting the mode took about 100ms

14:43:12.763 -> #### Start
14:43:12.842 -> #### Pass 2
14:43:12.842 -> [   641][W][STA.cpp:537] disconnect(): STA already disconnected.

You might try changing the Core Debug Level, about half-way down the Tools menu, to Debug, then re-Upload. That enables output like that third line there.

Thank you very much for your help, but we have changed Core Debug Leve to Debug and it has done the same thing, it has executed the first print but when passing through the WiFi.mode(WIFI_STA); it has not continued executing.
And it enters in loop.

10:13:36.270 -> ESP-ROM:esp32c3-api1-20210207
10:13:36.317 -> Build:Feb  7 2021
10:13:36.317 -> rst:0x3 (RTC_SW_SYS_RST),boot:0xf (SPI_FAST_FLASH_BOOT)
10:13:36.317 -> Saved PC:0x40048b82
10:13:36.317 -> SPIWP:0xee
10:13:36.317 -> mode:DIO, clock div:1
10:13:36.317 -> load:0x3fcd5820,len:0x458
10:13:36.317 -> load:0x403cc710,len:0x814
10:13:36.317 -> load:0x403ce710,len:0x2880
10:13:36.317 -> entry 0x403cc710
10:13:36.650 -> =========== Before Setup Start ===========
10:13:36.650 -> Chip Info:
10:13:36.650 -> ------------------------------------------
10:13:36.650 ->   Model             : ESP32-C3
10:13:36.650 ->   Package           : 0
10:13:36.650 ->   Revision          : 4
10:13:36.650 ->   Cores             : 1
10:13:36.650 ->   CPU Frequency     : 160 MHz
10:13:36.650 ->   XTAL Frequency    : 40 MHz
10:13:36.650 ->   Embedded Flash    : No
10:13:36.650 ->   Embedded PSRAM    : No
10:13:36.650 ->   2.4GHz WiFi       : Yes
10:13:36.650 ->   Classic BT        : No
10:13:36.650 ->   BT Low Energy     : Yes
10:13:36.650 ->   IEEE 802.15.4     : No
10:13:36.650 -> ------------------------------------------
10:13:36.650 -> INTERNAL Memory Info:
10:13:36.650 -> ------------------------------------------
10:13:36.650 ->   Total Size        :   310168 B ( 302.9 KB)
10:13:36.650 ->   Free Bytes        :   281296 B ( 274.7 KB)
10:13:36.650 ->   Allocated Bytes   :    25192 B (  24.6 KB)
10:13:36.650 ->   Minimum Free Bytes:   281296 B ( 274.7 KB)
10:13:36.650 ->   Largest Free Block:   147444 B ( 144.0 KB)
10:13:36.650 -> ------------------------------------------
10:13:36.650 -> Flash Info:
10:13:36.650 -> ------------------------------------------
10:13:36.650 ->   Chip Size         :  4194304 B (4 MB)
10:13:36.650 ->   Block Size        :    65536 B (  64.0 KB)
10:13:36.650 ->   Sector Size       :     4096 B (   4.0 KB)
10:13:36.650 ->   Page Size         :      256 B (   0.2 KB)
10:13:36.650 ->   Bus Speed         : 80 MHz
10:13:36.650 ->   Bus Mode          : QIO
10:13:36.650 -> ------------------------------------------
10:13:36.650 -> Partitions Info:
10:13:36.650 -> ------------------------------------------
10:13:36.650 ->                 nvs : addr: 0x00009000, size:    20.0 KB, type: DATA, subtype: NVS
10:13:36.650 ->             otadata : addr: 0x0000E000, size:     8.0 KB, type: DATA, subtype: OTA
10:13:36.650 ->                app0 : addr: 0x00010000, size:  1280.0 KB, type:  APP, subtype: OTA_0
10:13:36.650 ->                app1 : addr: 0x00150000, size:  1280.0 KB, type:  APP, subtype: OTA_1
10:13:36.650 ->              spiffs : addr: 0x00290000, size:  1408.0 KB, type: DATA, subtype: SPIFFS
10:13:36.650 ->            coredump : addr: 0x003F0000, size:    64.0 KB, type: DATA, subtype: COREDUMP
10:13:36.650 -> ------------------------------------------
10:13:36.650 -> Software Info:
10:13:36.650 -> ------------------------------------------
10:13:36.650 ->   Compile Date/Time : Aug 23 2024 09:54:19
10:13:36.650 ->   Compile Host OS   : windows
10:13:36.650 ->   ESP-IDF Version   : v5.1.4-497-gdc859c1e67-dirty
10:13:36.650 ->   Arduino Version   : 3.0.3
10:13:36.650 -> ------------------------------------------
10:13:36.650 -> Board Info:
10:13:36.650 -> ------------------------------------------
10:13:36.650 ->   Arduino Board     : ESP32C3_DEV
10:13:36.650 ->   Arduino Variant   : esp32c3
10:13:36.650 ->   Arduino FQBN      : esp32:esp32:esp32c3:UploadSpeed=115200,CDCOnBoot=default,CPUFreq=160,FlashFreq=80,FlashMode=qio,FlashSize=4M,PartitionScheme=default,DebugLevel=debug,EraseFlash=none,JTAGAdapter=default,ZigbeeMode=default
10:13:36.650 -> ============ Before Setup End ============
10:13:36.787 -> ### Start

Unfortunately, it is crashing without any debug messages. At this point, if a basic sketch does not work, have you tried a different board? Same model or different model....

I am currently using the ESP32C2 Dev Module, since I have an Esp32-C3-Mini1 on a PCB designed by us.
I wouldn't know which other board to use.

I noticed one thing in the examples. They all include SPI.h.
Is the WiFi device using SPI? If so, the WiFi library in Github does not include that.

Sorry for the lack of knowledge but we do not know very well what SPI is. From what we have seen it is a communications protocol, but we are not sure if we are using it.
We are using a FT232RL adapter, like this one: https://www.amazon.com/-/es/ShillehTek-adaptador-convertidor-Compatible-microcontroladores/dp/B0CW258S1Y/ref=sr_1_2?__mk_es_US=ÅMĂ…ĆœĂ•Ă‘&sr=8-2

And a pogo pin like this: https://es.aliexpress.com/item/1005005832969596.html?spm=a2g0o.order_list.order_list_main.9.7d7a194dtYSYul&gatewayAdapt=glo2esp

Hello good afternoon, my brother and I decided to make a project with the Esp32-C3-Mini1 module, with our own PCB. Previously we made a query in this forum but being newbies it was not very well structured. That's why I'm doing it again.

The problem we have is that when running any program that has a wifi function, it executes all the lines until it arrives to any of the wifi functions and then it stops executing.

As you can see in the example code of wifi scan. The program executes the first print but at “WiFi.mode(WIFI_STA);” the program stops executing and then tries to execute again and loops.

The only Wifi function that works for us is the wifi.status and it returns the code "254"

Has anyone had or knows how to solve this problem?

Thank you very much,

/*
 *  This sketch demonstrates how to scan WiFi networks.
 *  The API is based on the Arduino WiFi Shield library, but has significant changes as newer WiFi functions are supported.
 *  E.g. the return value of encryptionType() different because more modern encryption is supported.
 */
#include "WiFi.h"

void setup() {
  Serial.begin(115200);

  // Set WiFi to station mode and disconnect from an AP if it was previously connected.
  Serial.println("#### Start");
  WiFi.mode(WIFI_STA);
  Serial.println("#### Pass 2");
  WiFi.disconnect();
  delay(100);

  Serial.println("Setup done");
}

void loop() {
  Serial.println("Scan start");

  // WiFi.scanNetworks will return the number of networks found.
  int n = WiFi.scanNetworks();
  Serial.println("Scan done");
  if (n == 0) {
    Serial.println("no networks found");
  } else {
    Serial.print(n);
    Serial.println(" networks found");
    Serial.println("Nr | SSID                             | RSSI | CH | Encryption");
    for (int i = 0; i < n; ++i) {
      // Print SSID and RSSI for each network found
      Serial.printf("%2d", i + 1);
      Serial.print(" | ");
      Serial.printf("%-32.32s", WiFi.SSID(i).c_str());
      Serial.print(" | ");
      Serial.printf("%4ld", WiFi.RSSI(i));
      Serial.print(" | ");
      Serial.printf("%2ld", WiFi.channel(i));
      Serial.print(" | ");
      switch (WiFi.encryptionType(i)) {
        case WIFI_AUTH_OPEN: Serial.print("open"); break;
        case WIFI_AUTH_WEP: Serial.print("WEP"); break;
        case WIFI_AUTH_WPA_PSK: Serial.print("WPA"); break;
        case WIFI_AUTH_WPA2_PSK: Serial.print("WPA2"); break;
        case WIFI_AUTH_WPA_WPA2_PSK: Serial.print("WPA+WPA2"); break;
        case WIFI_AUTH_WPA2_ENTERPRISE: Serial.print("WPA2-EAP"); break;
        case WIFI_AUTH_WPA3_PSK: Serial.print("WPA3"); break;
        case WIFI_AUTH_WPA2_WPA3_PSK: Serial.print("WPA2+WPA3"); break;
        case WIFI_AUTH_WAPI_PSK: Serial.print("WAPI"); break;
        default: Serial.print("unknown");
      }
      Serial.println();
      delay(10);
    }
  }
  Serial.println("");

  // Delete the scan result to free memory for code below.
  WiFi.scanDelete();

  // Wait a bit before scanning again.
  delay(5000);
}
10:13:36.270 -> ESP-ROM:esp32c3-api1-20210207
10:13:36.317 -> Build:Feb  7 2021
10:13:36.317 -> rst:0x3 (RTC_SW_SYS_RST),boot:0xf (SPI_FAST_FLASH_BOOT)
10:13:36.317 -> Saved PC:0x40048b82
10:13:36.317 -> SPIWP:0xee
10:13:36.317 -> mode:DIO, clock div:1
10:13:36.317 -> load:0x3fcd5820,len:0x458
10:13:36.317 -> load:0x403cc710,len:0x814
10:13:36.317 -> load:0x403ce710,len:0x2880
10:13:36.317 -> entry 0x403cc710
10:13:36.650 -> =========== Before Setup Start ===========
10:13:36.650 -> Chip Info:
10:13:36.650 -> ------------------------------------------
10:13:36.650 ->   Model             : ESP32-C3
10:13:36.650 ->   Package           : 0
10:13:36.650 ->   Revision          : 4
10:13:36.650 ->   Cores             : 1
10:13:36.650 ->   CPU Frequency     : 160 MHz
10:13:36.650 ->   XTAL Frequency    : 40 MHz
10:13:36.650 ->   Embedded Flash    : No
10:13:36.650 ->   Embedded PSRAM    : No
10:13:36.650 ->   2.4GHz WiFi       : Yes
10:13:36.650 ->   Classic BT        : No
10:13:36.650 ->   BT Low Energy     : Yes
10:13:36.650 ->   IEEE 802.15.4     : No
10:13:36.650 -> ------------------------------------------
10:13:36.650 -> INTERNAL Memory Info:
10:13:36.650 -> ------------------------------------------
10:13:36.650 ->   Total Size        :   310168 B ( 302.9 KB)
10:13:36.650 ->   Free Bytes        :   281296 B ( 274.7 KB)
10:13:36.650 ->   Allocated Bytes   :    25192 B (  24.6 KB)
10:13:36.650 ->   Minimum Free Bytes:   281296 B ( 274.7 KB)
10:13:36.650 ->   Largest Free Block:   147444 B ( 144.0 KB)
10:13:36.650 -> ------------------------------------------
10:13:36.650 -> Flash Info:
10:13:36.650 -> ------------------------------------------
10:13:36.650 ->   Chip Size         :  4194304 B (4 MB)
10:13:36.650 ->   Block Size        :    65536 B (  64.0 KB)
10:13:36.650 ->   Sector Size       :     4096 B (   4.0 KB)
10:13:36.650 ->   Page Size         :      256 B (   0.2 KB)
10:13:36.650 ->   Bus Speed         : 80 MHz
10:13:36.650 ->   Bus Mode          : QIO
10:13:36.650 -> ------------------------------------------
10:13:36.650 -> Partitions Info:
10:13:36.650 -> ------------------------------------------
10:13:36.650 ->                 nvs : addr: 0x00009000, size:    20.0 KB, type: DATA, subtype: NVS
10:13:36.650 ->             otadata : addr: 0x0000E000, size:     8.0 KB, type: DATA, subtype: OTA
10:13:36.650 ->                app0 : addr: 0x00010000, size:  1280.0 KB, type:  APP, subtype: OTA_0
10:13:36.650 ->                app1 : addr: 0x00150000, size:  1280.0 KB, type:  APP, subtype: OTA_1
10:13:36.650 ->              spiffs : addr: 0x00290000, size:  1408.0 KB, type: DATA, subtype: SPIFFS
10:13:36.650 ->            coredump : addr: 0x003F0000, size:    64.0 KB, type: DATA, subtype: COREDUMP
10:13:36.650 -> ------------------------------------------
10:13:36.650 -> Software Info:
10:13:36.650 -> ------------------------------------------
10:13:36.650 ->   Compile Date/Time : Aug 23 2024 09:54:19
10:13:36.650 ->   Compile Host OS   : windows
10:13:36.650 ->   ESP-IDF Version   : v5.1.4-497-gdc859c1e67-dirty
10:13:36.650 ->   Arduino Version   : 3.0.3
10:13:36.650 -> ------------------------------------------
10:13:36.650 -> Board Info:
10:13:36.650 -> ------------------------------------------
10:13:36.650 ->   Arduino Board     : ESP32C3_DEV
10:13:36.650 ->   Arduino Variant   : esp32c3
10:13:36.650 ->   Arduino FQBN      : esp32:esp32:esp32c3:UploadSpeed=115200,CDCOnBoot=default,CPUFreq=160,FlashFreq=80,FlashMode=qio,FlashSize=4M,PartitionScheme=default,DebugLevel=debug,EraseFlash=none,JTAGAdapter=default,ZigbeeMode=default
10:13:36.650 -> ============ Before Setup End ============
10:13:36.787 -> ### Start

@macnus ,

Your two or more topics on the same or similar subject have been merged.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

For the sake of clarity I tried to delete the previous topic but as I did not have permissions I asked the administrators to delete it.
But if you think it is better understood this way.

You had many replies to your topic, deleting it would also delete those replies and therefore the efforts of the volunteers who were helping you. For this reason deletion of topics with replies is not usually allowed.

Okay, let's wait to see if someone else has had the same problem. Thanks

1 Like