tzapu / WiFiManager

ESP8266 WiFi Connection manager with web captive portal
http://tzapu.com/esp8266-wifi-connection-manager-library-arduino-ide/
MIT License
6.57k stars 1.97k forks source link

ESP32-S2 crashes instantly on autoConnect() ? #1478

Closed nullstalgia closed 2 years ago

nullstalgia commented 2 years ago

Basic Infos

Hardware

WiFimanager Branch/Release: Master

Esp8266/Esp32: ESP32-S2

Hardware: ESP32-S2 Mini (Wemos/Lolin board)

Core Version: 5.0.0

Description

Chip instantly crashes upon using autoConnect().

Sketch

#include <Arduino.h>
#include <WiFiManager.h>
WiFiManager wifiManager;
#include "USB.h"

#if ARDUINO_USB_CDC_ON_BOOT
#define HWSerial Serial0
#define USBSerial Serial
#else
#define HWSerial Serial
USBCDC USBSerial;
#endif

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

    wifiManager.setDebugOutput(true);
    wifiManager.autoConnect();

}

void loop() {}

Platformio.ini:

[env:lolin_s2_mini]
platform = espressif32
board = lolin_s2_mini
framework = arduino
monitor_speed = 115200
build_flags = 
    -D ARDUINO_USB_CDC_ON_BOOT
lib_deps = 
    https://github.com/tzapu/WiFiManager.git

USB Serial Output:

Output from above sketch:

--- Terminal on COM9 | 115200 8-N-1
--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
*wm:[1] AutoConnect 

Since I'm using the CDC, I don't get a stack trace, and I'm actually not sure if the proper UART GPIOs are broken out on this board.

Edit:

Moving some stuff around I was able to get a little more output, but still crashing instantly.

*wm:[1] AutoConnect
*wm:[1] No Credentials are Saved, skipping connect 
*wm:[2] Starting Config Portal
*wm:[2] Disabling STA
*wm:[2] Enabling AP
*wm:[1] StartAP with SSID:  ESP32_D803F784
*wm:[2] AP has anonymous access!
tablatronix commented 2 years ago

Enable esp debug, what is cdc? Does it work when you remove it?

nullstalgia commented 2 years ago

USB CDC == USB communications device class, basically the technical terms for the USB <-> UART interface.

If I remove it and all other Serial mentions, I don't get any Serial output over USB, and it still crashes.

Adding -DCORE_DEBUG_LEVEL=5 to the build flags gives no extra output over the USB Serial.

I may just have to pray and hope that the proper UART pins are broken out and hook up to them to see that extra ESP output + the stack trace.

tablatronix commented 2 years ago

hmm, never used it ill test out your basic sketch, I assumed you tried IDF stable and master?

nullstalgia commented 2 years ago

Not sure how to switch between those on PlatformIO. I'm just using the supplied ESP32 Arduino core.

I'll gladly test whatever I need to in order to get this working.

Unfortunately, it looks like I may be boned in terms of IO?

The ESP32-S2's UX0 is on GPIOs 44 and 43

image

image

But this board lacks these pins. Oh boy.

nullstalgia commented 2 years ago

Huh... I had success with the tiny sketch once when using WiFi.mode(WIFI_STA); at the very start. But this success did not carry over to any future attempts.

tablatronix commented 2 years ago

I thought the soala did not break out usb unless you move the jumpers? That is why they added 2 usb on the s3

nullstalgia commented 2 years ago

Sadly, I don't have a Saola board. I have the one below it, the LOLIN ESP32-S2 Mini. I was just using the picture as a reference for the ESP32-S2's pins.

But looking closely at it, it looks like the Saola doesn't even have jumpers for switching the USB port, just the USB pins broken out on the side.

Edit: Updating my ESP32 Core from 5.0.0 to 5.1.0 did not change anything either.

nullstalgia commented 2 years ago

So, after doing some tests and research, I have some stuff to share.

When testing the board's WiFi with a normal Wifi.begin(), it would also crash!

It turns out that the ESP32-S2 board I have is a clone of the Lolin S2 Mini, and has a flaw in the copy: the capacitor on the reset line is missing its connection to GND. Scraping the soldermask of the GND plane directly near it and using a solder blob to connect it to the capacitor works with fixing A crash when Wifi is being used.

image

Source of image and fix.

I was able to write the rest of my sketch (send a payload to my MQTT server and then go into deep sleep) to make sure it works with the capacitor fix, and it does.

However, this does not fix my issue with the library.

If I try to use autoConnect() still, it does just crash. ok or not anymore

i swear im going mad

Now it does work?? But autoConnect() consistently fails until I put WiFi.mode(WIFI_AP); before autoConnect()

By fails, I mean the AP it makes when a connection fails does not appear on my phone. And if it has credentials saved, connection attempts will fail.

tablatronix commented 2 years ago

I heard of another issue maybe with this board maybe, not sure, you have to decrease the wifi power or it wont initialize wifi, as there is not enough power or something?

Definitely get your hands on a real dev board or some others when working with this stuff, will save your days of debugging

nullstalgia commented 2 years ago

Well, part of the issue is that I already have a PCB made for this footprint in mind 😅

Was working fine in preliminary tests with RGB and deep sleep, and I guess the clone's engineers were also lulled into the false sense of security.

I'll be sure to do more robust testing in the future :P

But, it seems that the capacitor bodge+lowering WiFi power might be my best best to avoid needing to spend more money.

Thank you for bearing with me!

EDIT: But I did grab a Feather S2 Neo while debugging this! So hopefully that can be a good sanity checker.

tablatronix commented 2 years ago

Have you tried clearing and reloading the esp lib or platform in pio?

NightSkySK commented 2 years ago

I have ESP32-S2-Soala board, and also have problems with WiFi autoConnect(). In my case it doesn't crash, but even if logs show that AccessPoint is created I can't detect it by any device:

*wm:[1] AutoConnect 
*wm:[2] ESP32 event handler enabled 
*wm:[2] Connecting as wifi client... 
*wm:[2] setSTAConfig static ip not set, skipping 
*wm:[1] Connecting to SAVED AP: espressif

*wm:[1] connectTimeout not set, ESP waitForConnectResult... 
*wm:[2] [EVENT] WIFI_REASON:  201
*wm:[2] [EVENT] WIFI_REASON: NO_AP_FOUND 
*wm:[2] Connection result: WL_NO_SSID_AVAIL
*wm:[1] AutoConnect: FAILED 
*wm:[2] Starting Config Portal 
*wm:[2] Disabling STA 
*wm:[2] Enabling AP 
*wm:[1] StartAP with SSID:  AutoConnectAP
*wm:[2] AP has anonymous access! 
*wm:[1] AP IP address: 192.168.4.1
*wm:[1] Starting Web Portal 
*wm:[2] HTTP server started 
*wm:[2] Config Portal Running, blocking, waiting for clients... 
*wm:[2] NUM CLIENTS:  0
*wm:[2] NUM CLIENTS:  0
*wm:[2] NUM CLIENTS:  0

The same code works at ESP32-CAM module flawlessly.

tablatronix commented 2 years ago

1482 - see this issue for this specific issue

Crashes are due to bad chips, bad boards, bad power supply, I cannot get them to work with esp lib at all, there does seem to be some fixes in IDF 4.4.2 or 4.4.3 for this, but it is not easy to use.

Vangreen commented 1 year ago

So, after doing some tests and research, I have some stuff to share.

When testing the board's WiFi with a normal Wifi.begin(), it would also crash!

It turns out that the ESP32-S2 board I have is a clone of the Lolin S2 Mini, and has a flaw in the copy: the capacitor on the reset line is missing its connection to GND. Scraping the soldermask of the GND plane directly near it and using a solder blob to connect it to the capacitor works with fixing A crash when Wifi is being used.

image

Source of image and fix.

I was able to write the rest of my sketch (send a payload to my MQTT server and then go into deep sleep) to make sure it works with the capacitor fix, and it does.

However, this does not fix my issue with the library.

~If I try to use autoConnect() still, it does just crash.~ ok or not anymore

i swear im going mad

Now it does work?? But autoConnect() consistently fails until I put WiFi.mode(WIFI_AP); before autoConnect()

By fails, I mean the AP it makes when a connection fails does not appear on my phone. And if it has credentials saved, connection attempts will fail.

Thanks, works for me

Aggeloz commented 11 months ago

So, after doing some tests and research, I have some stuff to share.

When testing the board's WiFi with a normal Wifi.begin(), it would also crash!

It turns out that the ESP32-S2 board I have is a clone of the Lolin S2 Mini, and has a flaw in the copy: the capacitor on the reset line is missing its connection to GND. Scraping the soldermask of the GND plane directly near it and using a solder blob to connect it to the capacitor works with fixing A crash when Wifi is being used.

image

Source of image and fix.

I was able to write the rest of my sketch (send a payload to my MQTT server and then go into deep sleep) to make sure it works with the capacitor fix, and it does.

However, this does not fix my issue with the library.

~If I try to use autoConnect() still, it does just crash.~ ok or not anymore

i swear im going mad

Now it does work?? But autoConnect() consistently fails until I put WiFi.mode(WIFI_AP); before autoConnect()

By fails, I mean the AP it makes when a connection fails does not appear on my phone. And if it has credentials saved, connection attempts will fail.

Funny thing is, my clone board has all its connections correct. I tested with a multimeter and even did the fix and it still gives me the same problem, i even added a capacitor between the reset button and GND and it still has the same issues. I dont understand what else could be causing this.

tablatronix commented 10 months ago

What is the exact crash? Could still be bad power, or memory issue, try full erase and power with an actual power supply. There can also be crashes if your flash mode is set wrong

Aggeloz commented 10 months ago

What is the exact crash? Could still be bad power, or memory issue, try full erase and power with an actual power supply. There can also be crashes if your flash mode is set wrong

I get no messages from the monitor cause im using CDC for console output but its none of those things you mentioned. My boards crash as soon as i get my fingers close to the antenna or i put it on a breadboard, also if its already sitting on a breadboard it either crashes the CDC output or the board basically never boots.

tablatronix commented 10 months ago

You will have to use a serial adapter to get logs probably

Aggeloz commented 10 months ago

I'll set it up to keep the core dump on flash memory and read it after, it's kind of impossible to connect a serial adapter to it since the rx/tx pins are not broken out.

Aggeloz commented 10 months ago

Im getting no errors at all, the chip just hangs and then restarts. Its really weird behavior. Im gonna attempt to attach an external serial to the chip but i doubt im going to manage it because the solder points for the cpu are minuscule.

Edit: I think i managed to get this Core Dump https://pastebin.com/fUk8zfyj

tablatronix commented 10 months ago

Yeah you can output serial on any pins

Do you know which core the exception was throw on ?

Sure looks like that mqttclient stuff is suspect, if it is that thread, could try disabling that or sending static data could be reading from unsafe memory pointer, clientid, hostname, user input?

VaAndCob commented 10 months ago

From my experience, ESP32-S2 Lolin have trouble with WiFi, I have more than 10 modules and they have the same behaviour. I found that you must throttle wifi transmit power down after the first time wifi connected.
default tx power is max, that makes wifi unstable and hot. Connecting other sensors or modules directly to the Vbus (5V) pin could also make wifi unstable.

Aggeloz commented 10 months ago

I know, ive tried setting the tx power alot lower but it didnt help at all.