arduino-esp32 icon indicating copy to clipboard operation
arduino-esp32 copied to clipboard

ESP32 C3 S2 softap fails to start with no error condition

Open tablatronix opened this issue 1 year ago • 17 comments

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.

tablatronix avatar Sep 07 '22 13:09 tablatronix

AP doesn't fire up on my S2.

cniedzi avatar Sep 07 '22 14:09 cniedzi

Minimalized test example even more

tablatronix avatar Sep 07 '22 19:09 tablatronix

// 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...

cniedzi avatar Sep 07 '22 20:09 cniedzi

I can't get AP on ESP32-C3

Miceuz avatar Sep 07 '22 21:09 Miceuz

lol @cniedzi erase your credentials or put junk in there

tablatronix avatar Sep 07 '22 21:09 tablatronix

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

tablatronix avatar Sep 07 '22 23:09 tablatronix

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?

cniedzi avatar Sep 10 '22 15:09 cniedzi

I will post this to IDF as an issue, as I do not think it is an arduino issue

tablatronix avatar Sep 10 '22 20:09 tablatronix

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 avatar Sep 12 '22 21:09 tablatronix

@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

Jason2866 avatar Sep 15 '22 18:09 Jason2866

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 avatar Sep 15 '22 19:09 me-no-dev

@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

tablatronix avatar Sep 15 '22 19:09 tablatronix

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(){

}

me-no-dev avatar Sep 16 '22 09:09 me-no-dev

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.

me-no-dev avatar Sep 16 '22 09:09 me-no-dev

Awesome, I did not expect a new release for a bit since 2.0.4 is still very new.

tablatronix avatar Sep 16 '22 15:09 tablatronix

@tablatronix Can you please help testing this under 2.0.5? Thanks!

VojtechBartoska avatar Sep 19 '22 06:09 VojtechBartoska

Will do, I am on platformio or i would have already

tablatronix avatar Sep 20 '22 23:09 tablatronix