arduino-esp32
arduino-esp32 copied to clipboard
ESP32 C3 S2 softap fails to start with no error condition
Board
esp32 c3 devkit
Device Description
espressif devkit tested G3v01 tested Possible also an ESP-Sx issue
Hardware Configuration
nothing special
Version
v2.0.4
IDE Name
pio
Operating System
macos
Flash frequency
40
PSRAM enabled
no
Upload speed
921600
Description
For some reason if you toggle sta on and off, softap fails to start an AP, but everything in code appears to start successfully..
I imagine there is some event missing in arduino or a state in IDF that is not returning properly.
I am not sure exactly how many times once or twice toggling sta back or the sta state when begin is called..
Sketch
// wifi_basic.ino
#include <arduino.h>
#include <WiFi.h>
#include <esp_wifi.h>
void setup(){
Serial.begin(115200);
delay(2000);
Serial.println("Startup....");
Serial.setDebugOutput(true);
WiFi.begin("hellowifi","noonehere");
while (WiFi.status() != WL_CONNECTED && millis()<10000) {
delay(500);
Serial.print(".");
}
if(WiFi.status() == WL_CONNECTED){
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
else {
Serial.println("WiFi NOT CONNECTED, starting ap");
// WiFi.mode(WIFI_AP_STA); // <------- WORKAROUND SET AP MODE FIRST ?????
WiFi.enableSTA(false); // < ------ BUG BREAKS SOFTAP
delay(2000);
WiFi.softAP("espsoftap","12345678"); // no errors that I can see, but ap never shows up
}
}
void loop(){
}
Debug Message
Startup....
[ 2160][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY
[ 2189][V][WiFiGeneric.cpp:338] _arduino_event_cb(): STA Started
[ 2190][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 2 - STA_START
[ 2192][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
[ 2194][E][WiFiSTA.cpp:317] begin(): connect failed! 0x300a
................WiFi NOT CONNECTED, starting ap
[ 10195][V][WiFiGeneric.cpp:341] _arduino_event_cb(): STA Stopped
[ 10196][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 3 - STA_STOP
[ 12205][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY
[ 12215][V][WiFiGeneric.cpp:390] _arduino_event_cb(): AP Started
[ 12216][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 10 - AP_START
Other Steps to Reproduce
Cannot test in 2.0.3 due to bootloader crashes
I have checked existing issues, online documentation and the Troubleshooting Guide
- [X] I confirm I have checked existing issues, online documentation and Troubleshooting guide.
AP doesn't fire up on my S2.
Minimalized test example even more
// wifi_basic.ino #include <arduino.h> #include <WiFi.h> #include <esp_wifi.h> void setup(){ Serial.begin(115200); delay(2000); Serial.println("Startup...."); Serial.setDebugOutput(true); WiFi.begin(); while (WiFi.status() != WL_CONNECTED && millis()<10000) { delay(500); Serial.print("."); } if(WiFi.status() == WL_CONNECTED){ Serial.println(""); Serial.println("WiFi connected."); Serial.println("IP address: "); Serial.println(WiFi.localIP()); } else { Serial.println("WiFi NOT CONNECTED, starting ap"); WiFi.enableSTA(false); // BREAKING delay(2000); WiFi.softAP("espsoftap","12345678"); } } void loop(){ }
I had to increase the delay to 5s and decrease millis()<5000 because my S2 was always successfuly connecting to WiFi. After that no AP started...
I can't get AP on ESP32-C3
lol @cniedzi erase your credentials or put junk in there
Confirmed same issue on S2, I might escalate this to espressif. Its possible already fixed in IDF.. not tested yet
- [x] arduino esp32 C3
- [x] arduino esp32 S2
- [ ] IDF C3
- [ ] IDF S2
- [ ] * S3
I have been trying to fix this and nothing I do fixes it, no workaround yet other that the one mentioned before
bool _disableSTAConn = false; // disable sta when starting ap, if sta is not connected ( stability )
seems to help avoid whatever gets stuck in the IDF
Did you report this issue to Espressif? Did they say something?
I will post this to IDF as an issue, as I do not think it is an arduino issue
UPDATE: added a workaround to the test sketch, no idea whats going on
If I had to guess, [ 12205][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY is in error state and wifi is not in fact ready when starting ap
@tablatronix Try this. I get a working AP with your test sketch (without the workaround). Latest IDF and Arduino.
[env:esp32-c3-devkitm-1]
platform = https://github.com/jason2866/platform-espressif32.git#Tasmota/205
platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/996/framework-arduinoespressif32-IDF_Arduino-cd58a68f7.zip
board = esp32-c3-devkitm-1
framework = arduino
Adding WiFi.setAutoReconnect(false);
before WiFi.begin();
also helps. I think the problem is caused by the constant attempts to reconnect, which interfere with the SoftAP and the software is not able to handle everything. With the original sketch on S3 I could see the AP, but could rarely be able to connect to it, or get IP. As soon as I made sure that before starting AP the station is no longer trying to connect, everything started working normally. This is with ESP-IDF 4.4.2. I will later check with te latest 4.4 branch.
Here is the log:
Startup....
[ 2180][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY
[ 2216][V][WiFiGeneric.cpp:338] _arduino_event_cb(): STA Started
[ 2217][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
[ 2218][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 2 - STA_START
....[ 4639][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: hellowifi, BSSID: 00:00:00:00:00:00, Reason: 201
[ 4640][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 4647][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
[ 4654][D][WiFiGeneric.cpp:966] _eventCallback(): WiFi Reconnect Running
[ 4662][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
.....[ 7081][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: hellowifi, BSSID: 00:00:00:00:00:00, Reason: 201
[ 7082][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 7089][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
.......WiFi NOT CONNECTED, starting ap
[ 12237][V][WiFiGeneric.cpp:390] _arduino_event_cb(): AP Started
[ 12238][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 10 - AP_START
[ 41170][V][WiFiGeneric.cpp:405] _arduino_event_cb(): AP Station Connected: MAC: f4:d4:88:61:42:78, AID: 1
[ 41171][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 12 - AP_STACONNECTED
[ 42313][V][WiFiGeneric.cpp:419] _arduino_event_cb(): AP Station IP Assigned:192.168.4.2
[ 42314][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 14 - AP_STAIPASSIGNED
[ 51607][V][WiFiGeneric.cpp:412] _arduino_event_cb(): AP Station Disconnected: MAC: f4:d4:88:61:42:78, AID: 1
[ 51608][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 13 - AP_STADISCONNECTED
@me-no-dev that is a different issue, AP instability with STA in disconnected mode
I have that also if I leave mode as STA+AP.
However setAutoReconnect has no effect on this particular issue
In fact you do not need wifi.begin()
and replace it and the bug is still valid
// WiFi.begin("none","12345678");
WiFi.mode(WIFI_STA);
This is specifically NO softap at all, untested on S3 ( i dont have one)
I am only testing on stable arduino, I have not tested on IDF versions yet
Just tested on C3 with what will be in 2.0.5 and here is your sketch with all options to make AP work commented and explained. While STA is trying to reconnect, it switches channels while scanning and that causes AP to lose communication (it works only on one channel).
#include <WiFi.h>
#include <esp_wifi.h>
void setup(){
Serial.begin(115200);
Serial.setDebugOutput(true);
Serial.setDebugOutput(true);
delay(2000);
Serial.println("Startup....");
//WiFi.setAutoReconnect(false); // < ------ WORKS BUT YOU SHOULD KNOW THE IMPLICATIONS
WiFi.begin("hellowifi","noonehere");
while (WiFi.status() != WL_CONNECTED && millis()<10000) {
delay(500);
Serial.print(".");
}
if(WiFi.status() == WL_CONNECTED){
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
else {
Serial.println("WiFi NOT CONNECTED, starting ap");
//WiFi.disconnect(); // < ------ WORKS AND JUST STOPS STA RECONNECT ATTEMPTS
//WiFi.enableSTA(false); // < ------ WORKS AND TURNS WIFI OFF (AP NOT YET ENABLED)
delay(2000);
WiFi.softAP("espsoftap","12345678"); // no errors that I can see, but ap never shows up
//WiFi.enableSTA(false); // < ------ WORKS AND TURNS STA OFF
}
}
void loop(){
}
Tested working on all chips. To not see AP at all, I would guess was an issue in IDF that was since fixed. We will release any day now, so following the above notes, you should be fine.
Awesome, I did not expect a new release for a bit since 2.0.4 is still very new.
@tablatronix Can you please help testing this under 2.0.5? Thanks!
Will do, I am on platformio or i would have already
Is there a
Just tested on C3 with what will be in 2.0.5 and here is your sketch with all options to make AP work commented and explained. While STA is trying to reconnect, it switches channels while scanning and that causes AP to lose communication (it works only on one channel).
#include <WiFi.h> #include <esp_wifi.h> void setup(){ Serial.begin(115200); Serial.setDebugOutput(true); Serial.setDebugOutput(true); delay(2000); Serial.println("Startup...."); //WiFi.setAutoReconnect(false); // < ------ WORKS BUT YOU SHOULD KNOW THE IMPLICATIONS WiFi.begin("hellowifi","noonehere"); while (WiFi.status() != WL_CONNECTED && millis()<10000) { delay(500); Serial.print("."); } if(WiFi.status() == WL_CONNECTED){ Serial.println(""); Serial.println("WiFi connected."); Serial.println("IP address: "); Serial.println(WiFi.localIP()); } else { Serial.println("WiFi NOT CONNECTED, starting ap"); //WiFi.disconnect(); // < ------ WORKS AND JUST STOPS STA RECONNECT ATTEMPTS //WiFi.enableSTA(false); // < ------ WORKS AND TURNS WIFI OFF (AP NOT YET ENABLED) delay(2000); WiFi.softAP("espsoftap","12345678"); // no errors that I can see, but ap never shows up //WiFi.enableSTA(false); // < ------ WORKS AND TURNS STA OFF } } void loop(){ }
- Does the two delay(2000) importants?
- Can i also uncomment the line "WiFi.setAutoReconnect(false);" and leave the line: WiFi.begin("hellowifi","noonehere"); ?
@roysG
1. Does the two delay(2000) importants?
The first delay of 2000 pauses program startup to allow USB port to connect. I have that in my code as well for debugging so I don't miss the first few messages. I'm guessing the second delay allows the WiFi connection to fail before starting SoftAP. In our code we make sure to turn off STA before starting AP mode. AP+STA didn't seem to work well.
2. Can i also uncomment the line "WiFi.setAutoReconnect(false);" and leave the line: WiFi.begin("hellowifi","noonehere"); ?
Yes. You will have to write code to manually connect to WiFi (STA mode) if you lose connection.
Board esp32 c3 devkit-02 both Hardware Configuration nothing special Arduino IDE 1.8.19 (Windows Store 1.8.57.0) Library esp32 v 2.0.6 - softAp not work by standart example for FTM. The access point does not connect to the second esp 32, nor the Samsung Note. There are no errors in first and second esp32. Library esp32 v 2.0.3 - softAp work by standart example for FTM.
Take a look at reducing the transmit power after WiFi has started.
The transmit power mappings can be found here.
WiFi.softAP("espsoftap", "12345678");
WiFi.setTxPower(WIFI_POWER_15dBm);
int txPower = WiFi.getTxPower();
Serial.print("TX power: ");
Serial.println(txPower);
Check the getTxPower() value to confirm that the setting is being applied. I could not get anything to work until the power was reduced. Try different values and see what works for you.
Take a look at reducing the transmit power after WiFi has started.
The transmit power mappings can be found here.
WiFi.softAP("espsoftap", "12345678"); WiFi.setTxPower(WIFI_POWER_15dBm); int txPower = WiFi.getTxPower(); Serial.print("TX power: "); Serial.println(txPower);
Check the getTxPower() value to confirm that the setting is being applied. I could not get anything to work until the power was reduced. Try different values and see what works for you.
Setting the power like this makes it work on ESP32 Lolin S2 mini.
Thanks for the tip!