ESP-AT Lib Initialisation Failure

With help from this Forum, I have been able to flash my Wio Terminal and and spent some time trying a number of sketches to try and get networking to work.

The scanner generates error messages but detects a network.

I tried using this program

#include “AtWiFi.h”

const char* ssid = “REMOVED”;
const char* password = “REMOVED”;

void setup() {
Serial.begin(115200);
while(!Serial); // Wait for Serial to be ready
delay(1000);

// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(2000);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
Serial.print("IP Address: ");
Serial.println (WiFi.localIP()); // prints out the device's IP address
}

It generates messages typical of the other sketches I have run. It all seems to start with a failure to initialise WSP-AT Lib.

Device reset sequence finished!
Cannot initialize ESP-AT Lib!
[E][esp_event_loop.c:99] at_unified_cb(): at_unified evt: 4

[E][WiFiGeneric.cpp:477] mode(): Could not set mode! -1
[E][esp_event_loop.c:99] at_unified_cb(): at_unified evt: 4

[E][esp_event_loop.c:99] at_unified_cb(): at_unified evt: 4

[E][esp_event_loop.c:99] at_unified_cb(): at_unified evt: 4

[E][esp_event_loop.c:99] at_unified_cb(): at_unified evt: 4

[E][WiFiGeneric.cpp:477] mode(): Could not set mode! -1
[E][WiFiSTA.cpp:107] begin(): STA enable failed!
Connecting to WiFi…
Connecting to WiFi…
Connecting to WiFi…

Based on other postings, I have erased and reflashed the core several times. Each time it completes successfully but the wifi never works.

Is there a solution to these problems?

Thanks for all your help.

Allan

yes I’ve seen that too :face_with_raised_eyebrow:
you don’t have to reflash the wifi chip… these are lib errrors.

first I checked if this code worked, just to see the networks around you

WiFi scanner code - click

#include "AtWiFi.h"
   
  void setup() {
      Serial.begin(115200);
      while(!Serial); // Wait for Serial to be ready
      delay(1000);
   
      // Set WiFi to station mode and disconnect from an AP if it was previously connected
      WiFi.mode(WIFI_STA);
      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");
          for (int i = 0; i < n; ++i) {
              // Print SSID and RSSI for each network found
              Serial.print(i + 1);
              Serial.print(": ");
              Serial.print(WiFi.SSID(i));
              Serial.print(" (");
              Serial.print(WiFi.RSSI(i));
              Serial.print(")");
              Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*");
              delay(10);
          }
      }
      Serial.println("");
   
      // Wait a bit before scanning again
      delay(5000);
  }

source

when uploaded to the WIO, just open IDE serial monitor.
You should see something like this

That means the wifi chip seems to work… part 2 follows for that you have to manual install 5/6 libs

BoRRoz

I get this output. It spots the networks but doesn’t list the SSIDs.

Device reset sequence finished!
Cannot initialize ESP-AT Lib!
[E][esp_event_loop.c:99] at_unified_cb(): at_unified evt: 4

[E][WiFiGeneric.cpp:477] mode(): Could not set mode! -1
[E][esp_event_loop.c:99] at_unified_cb(): at_unified evt: 4

Setup done
scan start
[E][esp_event_loop.c:99] at_unified_cb(): at_unified evt: 4

[E][esp_event_loop.c:99] at_unified_cb(): at_unified evt: 4

[E][esp_event_loop.c:99] at_unified_cb(): at_unified evt: 4

[E][WiFiGeneric.cpp:477] mode(): Could not set mode! -1
scan done
-2 networks found

scan start
scan done
-1 networks found

scan start
scan done
-1 networks found

Thanks for all your help.

Allan

see problem Cannot initialize ESP-AT Lib

(your logs shows it isn’t working :wink:)

try installing older esp-at lib from a different source
I did, but I didn’t saved all the links :pensive: were I found them
this is what I have installed (zipfiles) and added to the library and most wifi demo’s worked
libs

https://github.com/Seeed-Studio/Seeed_Arduino_atWiFi
https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS
https://github.com/Seeed-Studio/Seeed_Arduino_atUnified

https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls
https://github.com/Seeed-Studio/Seeed_Arduino_atWiFiClientSecure
https://github.com/Seeed-Studio/Seeed_Arduino_LCD
https://github.com/knolleary/pubsubclient

BoRRoZ

Thanks - I deleted the libraries from the IDE and then added them again from the links thta you provided.

I tried to run the scanning program but I get a compilation error. I don’t think it is a missing file.

Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: “Seeeduino Wio Terminal, Enabled, 120 MHz (standard), Small (-Os) (standard), 50 MHz (standard), Arduino, Off”

In file included from C:\Users\allan\Documents\Arduino\libraries\esp-at-lib-develop\src/esp_config.h:73:0,

             from C:\Users\allan\Documents\Arduino\libraries\esp-at-lib-develop\src/esp_at_lib.h:10,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atUnified-master\src/Seeed_atUnified.h:12,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atWiFi-master\src/WiFiGeneric.h:26,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atWiFi-master\src/WiFiSTA.h:28,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atWiFi-master\src/WiFi.h:32,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atWiFi-master\src/AtWiFi.h:1,

             from C:\Users\allan\Documents\Arduino\2 Temporary\sketch_wio_BoRRoZ_scan\sketch_wio_BoRRoZ_scan.ino:1:

C:\Users\allan\Documents\Arduino\libraries\esp-at-lib-develop\src/esp/esp_config_default.h:1:1: error: expected unqualified-id before ‘.’ token

…/…/esp_at_lib/src/include/esp/esp_config_default.h

^

In file included from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atUnified-master\src/Seeed_atUnified.h:18:0,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atWiFi-master\src/WiFiGeneric.h:26,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atWiFi-master\src/WiFiSTA.h:28,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atWiFi-master\src/WiFi.h:32,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atWiFi-master\src/AtWiFi.h:1,

             from C:\Users\allan\Documents\Arduino\2 Temporary\sketch_wio_BoRRoZ_scan\sketch_wio_BoRRoZ_scan.ino:1:

C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atUnified-master\src/atu_netdb.h:148:36: error: ‘esp_ip_t’ has not been declared

extern int esp_ip_2_str(char* buf, esp_ip_t ip);

                                ^~~~~~~~

exit status 1

Error compiling for board Seeeduino Wio Terminal.

In file included from C:\Users\allan\Documents\Arduino\libraries\esp-at-lib-develop\src/esp_config.h:73:0,

             from C:\Users\allan\Documents\Arduino\libraries\esp-at-lib-develop\src/esp_at_lib.h:10,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atUnified-master\src/Seeed_atUnified.h:12,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atWiFi-master\src/WiFiGeneric.h:26,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atWiFi-master\src/WiFiSTA.h:28,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atWiFi-master\src/WiFi.h:32,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atWiFi-master\src/AtWiFi.h:1,

             from C:\Users\allan\Documents\Arduino\2 Temporary\sketch_wio_BoRRoZ_scan\sketch_wio_BoRRoZ_scan.ino:1:

C:\Users\allan\Documents\Arduino\libraries\esp-at-lib-develop\src/esp/esp_config_default.h:1:1: error: expected unqualified-id before ‘.’ token

…/…/esp_at_lib/src/include/esp/esp_config_default.h

^

In file included from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atUnified-master\src/Seeed_atUnified.h:18:0,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atWiFi-master\src/WiFiGeneric.h:26,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atWiFi-master\src/WiFiSTA.h:28,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atWiFi-master\src/WiFi.h:32,

             from C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atWiFi-master\src/AtWiFi.h:1,

             from C:\Users\allan\Documents\Arduino\2 Temporary\sketch_wio_BoRRoZ_scan\sketch_wio_BoRRoZ_scan.ino:1:

C:\Users\allan\Documents\Arduino\libraries\Seeed_Arduino_atUnified-master\src/atu_netdb.h:148:36: error: ‘esp_ip_t’ has not been declared

extern int esp_ip_2_str(char* buf, esp_ip_t ip);

                                ^~~~~~~~

exit status 1

Error compiling for board Seeeduino Wio Terminal.

This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.

Any thoughts would be appreciated.

Allan

BoRRoZ

Thanks for the libraries. I deleted the old ones and added the ones that you sent but I still get the same problem.

I ordered a second unit a few days ago so I will try again when I receive the new one.

Device reset sequence finished!
Cannot initialize ESP-AT Lib!
[E][esp_event_loop.c:99] at_unified_cb(): at_unified evt: 4

[E][WiFiGeneric.cpp:477] mode(): Could not set mode! -1
[E][esp_event_loop.c:99] at_unified_cb(): at_unified evt: 4

Setup done
scan start
[E][esp_event_loop.c:99] at_unified_cb(): at_unified evt: 4

[E][esp_event_loop.c:99] at_unified_cb(): at_unified evt: 4

[E][esp_event_loop.c:99] at_unified_cb(): at_unified evt: 4

[E][WiFiGeneric.cpp:477] mode(): Could not set mode! -1
scan done
-2 networks found

scan start
scan done
-1 networks found

Thanks for all your help.

Allan

Sorry to hear that… and to be honest I don’t understand :upside_down_face:
These are the same libs I use and it works (win 10 pro / arduino ide 1.8.12)
So I can’t help you :zipper_mouth_face:

if you google for that error
[E][esp_event_loop.c:99] at_unified_cb(): at_unified evt: 4
you’ll find you are not the only one

Hi @Allan_Geekie

This error happens when the firmware in the Wireless core is not flashed properly. Can you check if you have flashed properly and have the successful message?

1 Like

And that worked - I am now seeing the SSIDs using the scan program.

I downloaded the uf2 update and firmware again as well as the flashing tool.

The uf2 update seemed to run as before.

I ran the erase again - this time it did seem to take longer than I remember from last week.

I used the command line that BoRRoZ provided, changing the directory names and COM port number.

.\amebad_flash_tool.exe flash -d C:\flash\20200730-rtl8720d-images-v2.2.0.2 -p COM8

After downloading the scanning program from the IDE, the device momentarily went into download mode (the D:Arduino popped up) and then disappeared again. Then the scan started working, showing the SSIDs in the serial monitor.

I’m not sure where I went wrong before but I am really grateful for everyone’s help and patience with this one.

For completeness, this is the log.

PS C:\flash\amebad_flash_tool_v0.1.0_windows> ./amebad_flash_tool erase -p COM8
Erasing…
All images are sent successfully!
Image tool closed!
done!
PS C:\flash\amebad_flash_tool_v0.1.0_windows> .\amebad_flash_tool.exe flash -d C:\flash\20200730-rtl8720d-images-v2.2.0.2 -p COM8
copy img to workspace…
Flashing…
All images are sent successfully!
Image tool closed!
done!
PS C:\flash\amebad_flash_tool_v0.1.0_windows>

Now for MQTT!

Allan

2 Likes

you can test the covid demo too now, just to see if the other libs and HTTPS are working :wink: