espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.55k stars 7.39k forks source link

3.0.0 version Migration related issues #8796

Closed VojtechBartoska closed 4 months ago

VojtechBartoska commented 1 year ago

Hello,

purpose of this issue is to cover problems related to migration from 2.X (at the moment of writing the latest version is 2.0.14) to 3.X version.

💥 If you have any problems, please add comment to this issue. :boom:

3.0.0 version introduces breaking changes in those APIs:

🎉 For more details plese take a look on MIGRATION GUIDE FROM 2.X TO 3.X. 🎉


List of all related issues: (will be updated)

Please take a look on those issue before adding comment to this ticket.

TD-er commented 1 year ago

I think this is also related: #8774

everslick commented 1 year ago

The OneWire lib does not compile anymore, because GPIO is not defined.

libs/OneWire/OneWire.h:167:17: error: 'GPIO' was not declared in this scope; did you mean 'PI'?
  167 |         return (GPIO.in >> pin) & 0x1;
      |                 ^~~~
      |                 PI

~This can be fixed by including:~

#if ESP_ARDUINO_VERSION_MAJOR >= 3
#include <driver/gpio.h>
#include <hal/rtc_io_ll.h>
#else
#include <driver/rtc_io.h>
#endif

~And then using the functions:~

~rtcio_ll_get_level, rtcio_ll_set_level, rtcio_ll_input_enable and rtcio_ll_output_enable~

~where appropriate.~

Real fix is:

#if ESP_ARDUINO_VERSION_MAJOR >= 3
#include <soc/gpio_struct.h>
#else
#include <driver/rtc_io.h>
#endif
me-no-dev commented 1 year ago

The OneWire lib does not compile anymore, because GPIO is not defined.

Probably needs particular include. Some have changed in IDF5

everslick commented 1 year ago

I have difficulty porting the following code to IDF5. Please look at the line below FIXME! HELP NEEDED!.

error: cannot convert 'wifi_interface_t' to 'esp_netif_t*' {aka 'esp_netif_obj*'}
  esp_netif_get_ip_info(WIFI_IF_AP, &info);

Snippet:

#ifdef ESP32
#ifdef IDF5
  typedef esp_netif_ip_info_t ip_info_t;
#else
  typedef tcpip_adapter_ip_info_t ip_info_t;
#endif
#endif
#ifdef ESP8266
  typedef struct ip_info ip_info_t;
#endif

static ip_info_t ap_ip_info(void) {
  ip_info_t info = { 0 };

#ifdef ESP32
#ifdef IDF5
  // FIXME! HELP NEEDED!
  // esp_netif_get_ip_info(WIFI_IF_AP, &info);
#else // !IDF5
  tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &info);
#endif // !IDF5
#endif // ESP32

#ifdef ESP8266
  wifi_get_ip_info(SOFTAP_IF, &info);
#endif

  return (info);
}

Are wifi_interface_t and esp_netif_t incompatible types or can I just take the address of the former and cast it to the latter?

lbernstone commented 1 year ago

@everslick https://github.com/espressif/esp-idf/blob/v5.1/examples/protocols/http_server/captive_portal/main/dns_server.c#L152

everslick commented 12 months ago

One VERY peculiar thing I just witnessed: Calling yield() in a very tight loop seems to crash with exception 29 (LoadProhibited), while PC points to a few lines above the call to yield() which makes it especially difficult to debug. Luckily I have yield() wrapped in my own system_yield() so I can switch codepaths between versions (and work around the bug). Like:

void system_yield(void) {
#ifdef IDF5
  delay(1);
#else
  yield();
#endif

#ifdef HAVE_WATCHDOG
  watchdog_feed();
#endif
}

When the tight loop, yield() is called in, gets slowed down enough (with e.g. debug prints) it does not crash.

me-no-dev commented 12 months ago

@everslick I am rewriting/restructuring the whole network stack in order to decouple WiFi from the rest of the network functions. Many things have changed and will be fixed/rewritten to work. Some APIs will change/get deprecated, but it's for the better.

everslick commented 12 months ago

@everslick I am rewriting/restructuring the whole network stack in order to decouple WiFi from the rest of the network functions. Many things have changed and will be fixed/rewritten to work. Some APIs will change/get deprecated, but it's for the better.

Yes, I've seen the issue for it. I'm very much looking forward to it!

While we are at it. One of the things I do not really like about the Arduino API is the omnipresent instantiation of singleton like APIs. We have NO_GLOBAL_INSTANCES for that, but this is not always implemented for all interfaces. In case of WiFi, it is so baked in, that nothing works anymore if the global WiFi object is not there. Maybe, if possible, this is something to consider, when reworking the API.

me-no-dev commented 12 months ago

WiFi would be able to not be global, but beware a new Network class will be, though it's very light and has only events and dns queries.

Jason2866 commented 12 months ago

@me-no-dev Are you going to implement IPv6 with the rework of the network / wifi part? Nice to have a working DNS when Ethernet and WiFi is used together in the future;-)

me-no-dev commented 12 months ago

@Jason2866 IPv6 is planned for 3.0.0/1 it's coming for sure :)

kapyaar commented 9 months ago

Not sure if this belongs here, w5500+ETH using latest git version, installed manually on windows 11. Running Example ETH_W5500_Arduino_SPI. I have two boards, very possible they have two different versions of W5500. One works fine, but one gives the following very randomly.

E (127) w5500.mac: W5500 version mismatched, expected 0x04, got 0xfe
E (128) w5500.mac: emac_w5500_init(795): vefiry chip ID failed
E (128) esp_eth: esp_eth_driver_install(228): init mac failed
E (3033) w5500.mac: w5500_send_command(204): send command timeout
E (3033) w5500.mac: emac_w5500_receive(675): issue RECV command failed
E (3034) w5500.mac: frame read from module failed
E (4139) w5500.mac: w5500_send_command(204): send command timeout
E (4139) w5500.mac: emac_w5500_receive(675): issue RECV command failed
E (4140) w5500.mac: frame read from module failed
Guru Meditation Error: Core  0 panic'ed (InstrFetchProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x00380038  PS      : 0x00060930  A0      : 0x00000000  A1      : 0x3ffb5140  
A2      : 0x3ffb4960  A3      : 0x00380038  A4      : 0x40110378  A5      : 0x3ffb5ac4  
A6      : 0x000005f2  A7      : 0x00000000  A8      : 0x80110778  A9      : 0x3ffb5100  
A10     : 0x3ffb59d0  A11     : 0x3ffb5ac4  A12     : 0x0000fffc  A13     : 0x0000fffc  
A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x0000001c  EXCCAUSE: 0x00000014  
EXCVADDR: 0x00380038  LBEG    : 0x40089948  LEND    : 0x4008995e  LCOUNT  : 0xffffffff  

Backtrace: 0x00380035:0x3ffb5140
ELF file SHA256: 2dd9d9d7fcebe907

Rebooting...
ets Jun  8 2016 00:22:57

If I repower the board, Sometimes it starts working. Other times, it may give a different set of error messages, like this one.

rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1256
load:0x40078000,len:13832
load:0x40080400,len:4
load:0x40080404,len:3048
entry 0x40080590
E (127) w5500.mac: w5500_reset(302): reset timeout
E (128) w5500.mac: emac_w5500_init(793): reset w5500 failed
E (128) esp_eth: esp_eth_driver_install(228): init mac failed
E (3033) w5500.mac: w5500_send_command(204): send command timeout
E (3033) w5500.mac: emac_w5500_receive(675): issue RECV command failed
E (3034) w5500.mac: frame read from module failed
E (4139) w5500.mac: w5500_send_command(204): send command timeout
E (4139) w5500.mac: emac_w5500_receive(675): issue RECV command failed
E (4140) w5500.mac: frame read from module failed
Guru Meditation Error: Core  0 panic'ed (InstrFetchProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x00380038  PS      : 0x00060930  A0      : 0x00000000  A1      : 0x3ffb5140  
A2      : 0x3ffb4960  A3      : 0x00380038  A4      : 0x40110378  A5      : 0x3ffb5ac4  
A6      : 0x000005f2  A7      : 0x00000000  A8      : 0x80110778  A9      : 0x3ffb5100  
A10     : 0x3ffb59d0  A11     : 0x3ffb5ac4  A12     : 0x0000fffd  A13     : 0x0000fffd  
A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x0000001c  EXCCAUSE: 0x00000014  
EXCVADDR: 0x00380038  LBEG    : 0x40089948  LEND    : 0x4008995e  LCOUNT  : 0xffffffff  

Backtrace: 0x00380035:0x3ffb5140
ELF file SHA256: 2dd9d9d7fcebe907

Rebooting...
ets Jun  8 2016 00:22:57

And when it works, it connects and works fine, goes like this.

ETH Started
ETH Connected
ETH Got IP: 'eth0'
eth0: <UP,100M,FULL_DUPLEX,AUTO>
      ether 36:AB:95:6B:07:90 phy 0x1
      inet 192.168.2.30 netmask 255.255.255.0 broadcast 192.168.2.255
      gateway 192.168.2.1 dns 192.168.2.1

1
connecting to arduino.tips
HTTP/1.1 200 OK
Date: Tue, 02 Jan 2024 18:41:16 GMT....

And the rest of the contents are printed from /asciilogo.txt. I use wificlientsecure to do https.

Does https://github.com/espressif/esp-idf/issues/11331 has any bearing on this?

me-no-dev commented 9 months ago

@kostaond could you please comment on @kapyaar issue? Here the "bad" version is 0xFE

kostaond commented 9 months ago

@kapyaar how is the W5500 to the ESP32? Is it custom board or is it connected via wires? It seems to me like some SPI connection issue. You can also try to decrease SPI CLK frequency to see if it helps.

kapyaar commented 9 months ago

@kostaond @me-no-dev Board is good, it is an assembled pcb, but the issue is totally on our side. This ETH section is part of a larger board, and the new version had a few additional SPI chips, CS of one of those chips was floating, likely responding to requests meant for W5500. Took me a while to think outside my section of the board, Fixed that part, and the ETH part works consistently. Really sorry. I have an ETH question, but unrelated to this. To keep this thread clean, let me know if you want me to delete my post and comment, I will be happy to do that.

kostaond commented 9 months ago

@kapyaar if you have Ethernet related question, please ask at forum.

TD-er commented 9 months ago

@kapyaar One tip for designing your board with Ethernet. Please include a ferrite bead in the power line to the ETH power and make sure you only have a single point where GND of Ethernet and the rest is connected. In my own designs I used a beefy 0 Ohm resistor (0805 or 1206) to connect both grounds.

You can have a look at the schematics provided by Olimex to get inspiration on how to implement the power nets when using Ethernet. N.B. this is regardless of the used Ethernet chip as this is just typical for all Ethernet modules/chips.

TD-er commented 9 months ago

Found another issue, where the DHCP service doesn't seem to work when starting softAP. See: https://github.com/espressif/arduino-esp32/issues/9069

everslick commented 9 months ago

~I2C HAL fails to compile if HAL LOCKS are disabled.~ this has been fixed. See: #9073

luc-github commented 8 months ago

Hello in latest git / 3.0.0 alpha I cannot find the API equivalent API of

/**
 * @brief Compatible version of former tcpip_adapter API of esp_netif_get_sta_list
*/
esp_err_t tcpip_adapter_get_sta_list(const wifi_sta_list_t *wifi_sta_list, tcpip_adapter_sta_list_t *tcpip_sta_list);

to get IP of connected clients

It seems now a component in IDF : https://github.com/espressif/esp-idf/blob/release/v5.1/components/esp_wifi/include/esp_wifi_ap_get_sta_list.h

But cannot find it in latest arduino-esp32 git

Will this API be ported / available in esp32-arduino for final 3.0.0 ?

me-no-dev commented 8 months ago

@luc-github no. IDF 5.x has many changes since 4.x. There should be something else that would work the same way though

luc-github commented 8 months ago

so you mean esp_err_t esp_wifi_ap_get_sta_list_with_ip(const wifi_sta_list_t *wifi_sta_list, wifi_sta_mac_ip_list_t *wifi_sta_ip_mac_list); I linked ? but I cannot find it in latest git, so it is may be a miss ?

lucasssvaz commented 7 months ago

@P-R-O-C-H-Y @me-no-dev Should we add the changes of the network refactoring to the migration guide ?

Jason2866 commented 7 months ago

@lucasssvaz not one of the tagged, but from my side a clear YES. This changes have broken currently before well running Tasmota with alpha 3.0.0 completely ;-) It is by far the greatest breaking change of all.

me-no-dev commented 7 months ago

@Jason2866 can you elaborate a bit more on what actually broke on your end? We did rename a couple of IPv6 methods, but that should be mostly it. I tried to keep all other old methods working as before.

Jason2866 commented 7 months ago

@me-no-dev It crashes already at start. bootloop

Dereferencing a NULL pointer

00:00:00.061 Project tasmota - Tasmota Version 13.4.0.3(tasmota)-3_0_0(2024-03-20T18:35:13)
00:00:00.222 WIF: Attempting connection...
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

The call chain seems to be in:

NetworkEvents::removeEvent(std::function<void (arduino_event_id_t, arduino_event_info_t)>, arduino_event_id_t)
STAClass::end()
WiFiSTAClass::disconnect(bool, bool, unsigned long)
me-no-dev commented 7 months ago

@Jason2866 this is unexpected. Can you give more info on how you get to WiFi.disconnect(true)? Do you call it first on boot, or do you call other WiFi APIs before that? I want to replicate the problem.

Jason2866 commented 7 months ago

@me-no-dev
@s-hadinger is investigating this. His finding so far

struggling with the Core3 Wifi. It connects but Tasmota considers it's not connected because the status remains stuck on WL_STOPPED. It looks like the STAClass never receives WIFI_EVENT_STA_START/ARDUINO_EVENT_WIFI_STA_START that changes the status from WL_STOPPED to WL_DISCONNECTED because the STAClass is initialized too late, long after STA more was set and long after event WIFI_EVENT_STA_START.

I'm still struggling whether it uses STAClass or WiFiSTAClass (or worse both). Confirmed, WiFiGeneric mode() is triggered before STA exists

me-no-dev commented 7 months ago

@Jason2866 this is hard to believe, because event listeners are attached before STA is started. WiFiSTAClass is there just for compatibility and it always calls the STAClass in the background. STAClass is the one that manages the interface and receives and handles it's events. https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/src/STA.cpp#L293-L302

If you can provide a chain of calls that can reproduce an issue, I can investigate further as well.

Jason2866 commented 7 months ago

@me-no-dev Thx, we will do. We need some time.

s-hadinger commented 7 months ago

@me-no-dev I traced back the chain of calls (and simplified a bit).

// We have a global static singleton (actually we go through a WiFi32 wrapper but it does not change the chain of calls)
WiFiClass WiFi;

// then we make calls in this order:
WiFi.persistent(false);
WiFi.enableIPv6(true);
WiFi.hostname(TasmotaGlobal.hostname);  // ESP32 needs this here (before WiFi.mode) for core 2.0.0
WiFi.forceSleepWake(); // Make sure WiFi is really active.

WiFi.mode(WIFI_STA);
-> just after this call, the ARDUINO_EVENT_WIFI_STA_START event is fired but there is no listener because `STA` instance is not initialized yet

WiFi.setSleepMode(WIFI_NONE_SLEEP);       // Disable sleep
WiFi.setOutputPower((float)(Settings->wifi_output_power) / 10);
WiFi.setAutoReconnect(true);
WiFi.hostname(TasmotaGlobal.hostname);  // ESP8266 needs this here (after WiFi.mode)

WiFi.begin(SettingsText(SET_STASSID1 + Settings->sta_active), SettingsText(SET_STAPWD1 + Settings->sta_active), channel, Wifi.bssid);
--> this is only now that `WiFiSTAClass::begin` and `STAClass::begin` are called and hence register the event listener

As you can see above, since we never called WiFi.begin, STAClass::begin was never called and the listener is not yet registered. When WiFi.mode(WIFI_STA); is called, the event ARDUINO_EVENT_WIFI_STA_START is lost.

Does that mean that we should call WiFi.begin() (with no parameters) before doing WiFi.mode(WIFI_STA);, and later call again WiFi.begin(...) with all STA parameters ?

s-hadinger commented 7 months ago

@me-no-dev To give more details about event handlers:

The event handler is registered only when calling STAClass::begin(bool tryConnect)

https://github.com/espressif/arduino-esp32/blob/654aeada0a4d88595c31a68c62d339a09794c381/libraries/WiFi/src/STA.cpp#L291-L294

This registers _sta_event_cb as LwIP handler, which in turns converts to Arduino event in _onStaEvent.

Since _sta_event_cb is not registered when we call WiFi.mode(WIFI_STA);, the event WIFI_EVENT_STA_START is never sent to the Network instance with type ARDUINO_EVENT_WIFI_STA_START

s-hadinger commented 7 months ago

One last thing I forgot to mention, we have a sleep(200) after WiFi.mode(WIFI_STA);.

When looking at examples like:

void setup(){
    Serial.begin(115200);
    WiFi.disconnect(true);
    WiFi.onEvent(WiFiEvent);  // Will call WiFiEvent() from another thread.
    WiFi.mode(WIFI_MODE_APSTA);
    //enable ap ipv6 here
    WiFi.softAPenableIPv6();
    WiFi.softAP(AP_SSID);
    //enable sta ipv6 here
    WiFi.enableIPv6();
    WiFi.begin(STA_SSID, STA_PASS);
}

would it be possible that WiFi.begin() is called fast enough that LwIP didn't generate before this call?

me-no-dev commented 7 months ago

let me think about it a bit. The problem is that WiFi.mode(WIFI_MODE_APSTA); would start the radio but not attach AP/STA to callbacks. If you do not use mode but call begin or softAP, then things would be OK. I'll think about how to attach also through mode

Jason2866 commented 7 months ago

another #9435

me-no-dev commented 7 months ago

@s-hadinger please try https://github.com/espressif/arduino-esp32/pull/9436

Jason2866 commented 7 months ago

@me-no-dev Currently Lib Builder is running including the PR. Will report asap

Jason2866 commented 7 months ago

@me-no-dev nope still crashes with #9436

Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x401668e9  PS      : 0x00060b30  A0      : 0x80138e54  A1      : 0x3ffb1b80  
A2      : 0x00000000  A3      : 0x0000002b  A4      : 0x00000001  A5      : 0x3ffc9790  
A6      : 0x00000020  A7      : 0x00000000  A8      : 0x4012e340  A9      : 0x3ffb1b60  
A10     : 0x3ffb1bb0  A11     : 0x3ffb1b88  A12     : 0x3ffc9790  A13     : 0x3ffd4320  
A14     : 0x00000000  A15     : 0x00060323  SAR     : 0x0000001a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x4008e691  LEND    : 0x4008e6a1  LCOUNT  : 0xfffffffd  

Backtrace: 0x401668e6:0x3ffb1b80 0x40138e51:0x3ffb1bf0 0x401635bc:0x3ffb1ce0 0x40167cd5:0x3ffb1d00 0x400e17ed:0x3ffb1d20 0x400e3769:0x3ffb1e90 0x400da4f7:0x3ffb2220 0x4015a3c3:0x3ffb2290
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x401668e9  PS      : 0x00060b30  A0      : 0x80138e54  A1      : 0x3ffb1b80  
=> 0x401668e9: _ZN13NetworkEvents11removeEventESt8functionIFv18arduino_event_id_t20arduino_event_info_tEES1_$constprop$0 at /Users/hans/.platformio/packages/framework-arduinoespressif32/libraries/Network/src/NetworkEvents.cpp:245
      (inlined by) NetworkEvents::removeEvent(std::function<void (arduino_event_id_t, arduino_event_info_t)>, arduino_event_id_t) at /Users/hans/.platformio/packages/framework-arduinoespressif32/libraries/Network/src/NetworkEvents.cpp:256
      (inlined by) _ZN13NetworkEvents11removeEventESt8functionIFv18arduino_event_id_t20arduino_event_info_tEES1_$constprop$0 at /Users/hans/.platformio/packages/framework-arduinoespressif32/libraries/Network/src/NetworkEvents.cpp:248
A2      : 0x00000000  A3      : 0x0000002b  A4      : 0x00000001  A5      : 0x3ffc9790  
A6      : 0x00000020  A7      : 0x00000000  A8      : 0x4012e340  A9      : 0x3ffb1b60  
=> 0x4012e340: std::_Function_handler<void (arduino_event_id_t, arduino_event_info_t), void (*)(arduino_event_id_t, arduino_event_info_t)>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) at /Users/hans/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/include/c++/12.2.0/bits/std_function.h:267
A10     : 0x3ffb1bb0  A11     : 0x3ffb1b88  A12     : 0x3ffc9790  A13     : 0x3ffd4320  
A14     : 0x00000000  A15     : 0x00060323  SAR     : 0x0000001a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x4008d795  LEND    : 0x4008d7a5  LCOUNT  : 0xffffffef  
=> 0x4008d795: strcmp at /Users/brnomac003/.gitlab-runner/builds/qR2TxTby/0/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/machine/xtensa/strcmp.S:533
=> 0x4008d7a5: strcmp at /Users/brnomac003/.gitlab-runner/builds/qR2TxTby/0/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/machine/xtensa/strcmp.S:544

Backtrace: 0x401668e6:0x3ffb1b80 0x40138e51:0x3ffb1bf0 0x401635bc:0x3ffb1ce0 0x40167cd5:0x3ffb1d00 0x400e17ed:0x3ffb1d20 0x400e3769:0x3ffb1e90 0x400da4f7:0x3ffb2220 0x4015a3c3:0x3ffb2290
=> 0x401668e6: _ZN13NetworkEvents11removeEventESt8functionIFv18arduino_event_id_t20arduino_event_info_tEES1_$constprop$0 at /Users/hans/.platformio/packages/framework-arduinoespressif32/libraries/Network/src/NetworkEvents.cpp:245
      (inlined by) NetworkEvents::removeEvent(std::function<void (arduino_event_id_t, arduino_event_info_t)>, arduino_event_id_t) at /Users/hans/.platformio/packages/framework-arduinoespressif32/libraries/Network/src/NetworkEvents.cpp:256
      (inlined by) _ZN13NetworkEvents11removeEventESt8functionIFv18arduino_event_id_t20arduino_event_info_tEES1_$constprop$0 at /Users/hans/.platformio/packages/framework-arduinoespressif32/libraries/Network/src/NetworkEvents.cpp:248
=> 0x40138e51: STAClass::onDisable() at /Users/hans/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/STA.cpp:306
      (inlined by) WiFiGenericClass::mode(wifi_mode_t) at /Users/hans/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiGeneric.cpp:481
=> 0x401635bc: _ZN16WiFiGenericClass9enableSTAEb$constprop$0 at /Users/hans/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiGeneric.cpp:576
=> 0x40167cd5: STAClass::end() at /Users/hans/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/STA.cpp:348
      (inlined by) _ZN12WiFiSTAClass10disconnectEbbm$constprop$0$isra$0 at /Users/hans/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiSTA.cpp:139
=> 0x400e17ed: WifiBegin(unsigned char, unsigned char) at tasmota/tasmota_support/support_wifi.ino:215
=> 0x400e3769: WifiBeginAfterScan() at tasmota/tasmota_support/support_wifi.ino:362
      (inlined by) WifiBeginAfterScan() at tasmota/tasmota_support/support_wifi.ino:272
      (inlined by) WifiCheck(unsigned char) at tasmota/tasmota_support/support_wifi.ino:973
      (inlined by) Every250mSeconds() at tasmota/tasmota_support/support_tasmota.ino:1568
=> 0x400da4f7: Scheduler() at tasmota/tasmota.ino:882
      (inlined by) loop() at tasmota/tasmota.ino:913
=> 0x4015a3c3: loopTask(void*) at /Users/hans/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:80
me-no-dev commented 7 months ago

@Jason2866 this is a different issue than what @s-hadinger outlined above. I have an idea for the one you are testing, but I need to first reproduce it. I'm starting/stopping/deleting... I can not get into your situation

Jason2866 commented 7 months ago

@me-no-dev Before the PR #9436 addingWiFi.begin(); before WifiSetMode(WIFI_STA); was a workaround to get it going. With the PR this workaround isn't working anymore (tested with and without) and the crash i posted happens. So the PR introduces somehow this behaviour.

me-no-dev commented 7 months ago

@Jason2866 please try the PR again. just pushed something to help this exact problem. Here is what I am testing and is not failing:

  WiFi.mode(WIFI_MODE_STA);
  WiFi.disconnect(true);
  WiFi.enableIPv6();
  WiFi.begin("ssid","pass");
  delay(1000);
  WiFi.disconnect(true);

What is WifiSetMode(WIFI_STA)?

Jason2866 commented 7 months ago

WifiSetMode(WIFI_STA) == WiFi.mode(WIFI_STA); We use a wrapper... Will test with the change.

@me-no-dev EDIT with the change. No more crash. But it doesnt connect anymore.

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:344
load:0x40078000,len:14216
load:0x40080400,len:4
load:0x40080404,len:3232
entry 0x4008057c

00:00:00.001-215/50 HDW: ESP32-D0WDQ6 v1.0 
00:00:00.014-213/50 UFS: FlashFS mounted with 12596 kB free
00:00:00.029 CFG: Loaded from File, Count 4
00:00:00.030 CFG: CR 392/699, Busy 0
00:00:00.032 TYA: Active=0
00:00:00.034 ROT: Mode 1
00:00:00.068 CFG: No '*.autoconf' file found
00:00:00.071 BRY: Berry initialized, RAM used 4446 bytes
00:00:00.077 BRY: No 'preinit.be'
00:00:00.078 SRC: Restart
00:00:00.080 Project sonoff - Tasmota Version 13.4.0.3(arduino30)-3_0_0(2024-03-29T15:00:43)
00:00:00.101 BRY: No 'autoexec.be'
00:00:00.282 WIF: Attempting connection...
00:00:00.360 WIF: Network (re)scan started...
00:00:01.223 WIF: Attempting connection...
00:00:02.222 WIF: Attempting connection...
00:00:03.222 WIF: Attempting connection...
00:00:04.222 WIF: Attempting connection...
00:00:05.222 WIF: Attempting connection...
00:00:06.222 WIF: Attempting connection...
00:00:07.222 WIF: Attempting connection...
00:00:07.223 WIF: Network 0, AP1, SSId Jason_Home_WLAN, Channel 11, BSSId 00:A0:57:2A:BD:19, RSSI -54, Encryption 1
00:00:07.233 WIF: Network 1, AP-, SSId AP_3916770126, Channel 9, BSSId EC:FD:F8:93:3F:0C, RSSI -62, Encryption 1
00:00:07.244 WIF: Network 2, AP1, SSId Jason_Home_WLAN, Channel 9, BSSId 8C:53:C3:85:17:96, RSSI -77, Encryption 1
00:00:07.254 WIF: Network 3, AP1, SSId Jason_Home_WLAN, Channel 1, BSSId 00:A0:F9:45:D5:F8, RSSI -87, Encryption 1
00:00:07.265 WIF: Network 4, AP-, SSId Guest_WLAN, Channel 1, BSSId 02:A0:F9:45:D5:F8, RSSI -88, Encryption 1
00:00:07.275 WIF: Network 5, AP1, SSId Jason_Home_WLAN, Channel 1, BSSId 00:09:4F:70:72:BB, RSSI -89, Encryption 1
00:00:07.275 WIF: Network 6, AP-, SSId Guest_WLAN, Channel 1, BSSId 02:09:4F:70:72:BB, RSSI -89, Encryption 1
00:00:07.286 WIF: Network 7, AP-, SSId FRITZ!Box 7272, Channel 11, BSSId 34:81:C4:B9:36:CD, RSSI -92, Encryption 1
00:00:08.310 WIF: Connecting to AP1 Jason_Home_WLAN Channel 11 BSSId 00:A0:57:2A:BD:19 in mode 11n as sonoff-000000-7272...
00:00:08.959 APP: Boot Count 3
00:00:09.478 CFG: Saved, Count 5, Bytes 4096
00:00:09.641 WIF: Attempting connection...
00:00:10.863 WIF: Attempting connection...
00:00:11.863 WIF: Attempting connection...
00:00:12.863 WIF: Attempting connection...
00:00:13.863 WIF: Attempting connection...
00:00:14.863 WIF: Attempting connection...
00:00:15.863 WIF: Connect failed with AP timeout
00:00:16.863 WIF: Attempting connection...
00:00:17.863 WIF: Attempting connection...
00:00:18.863 WIF: Attempting connection...
00:00:19.863 WIF: Attempting connection...
00:00:20.863 WIF: Attempting connection...
00:00:21.863 WIF: Attempting connection...
00:00:22.863 WIF: Attempting connection...
00:00:23.863 WIF: Attempting connection...
00:00:24.863 WIF: Attempting connection...
00:00:25.863 WIF: Attempting connection...
c00:00:26.881 WIF: Attempting connection...
00:00:27.881 WIF: Attempting connection...
00:00:28.881 WIF: Attempting connection...
00:00:29.881 WIF: Connect failed with AP timeout
00:00:30.881 WIF: Attempting connection...
00:00:30.883 WIF: Network (re)scan started...
00:00:31.881 WIF: Attempting connection...
00:00:32.881 WIF: Attempting connection...
00:00:33.881 WIF: Attempting connection...
00:00:33.881 WIF: Network 0, AP1, SSId Jason_Home_WLAN, Channel 11, BSSId 00:A0:57:2A:BD:19, RSSI -53, Encryption 1
00:00:33.892 WIF: Network 1, AP-, SSId AP_3916770126, Channel 9, BSSId EC:FD:F8:93:3F:0C, RSSI -65, Encryption 1
00:00:33.902 WIF: Network 2, AP1, SSId Jason_Home_WLAN, Channel 9, BSSId 8C:53:C3:85:17:96, RSSI -72, Encryption 1
00:00:33.913 WIF: Network 3, AP1, SSId Jason_Home_WLAN, Channel 1, BSSId 00:A0:F9:45:D5:F8, RSSI -88, Encryption 1
00:00:33.923 WIF: Network 4, AP-, SSId Guest_WLAN, Channel 1, BSSId 02:09:4F:70:72:BB, RSSI -89, Encryption 1
00:00:33.934 WIF: Network 5, AP-, SSId Guest_WLAN, Channel 1, BSSId 02:A0:F9:45:D5:F8, RSSI -89, Encryption 1
00:00:33.934 WIF: Network 6, AP-, SSId EasyBox-915513, Channel 6, BSSId 3C:98:72:9B:1E:6C, RSSI -90, Encryption 1
00:00:33.945 WIF: Network 7, AP1, SSId Jason_Home_WLAN, Channel 1, BSSId 00:09:4F:70:72:BB, RSSI -91, Encryption 1
00:00:34.969 WIF: Connecting to AP1 Jason_Home_WLAN Channel 11 BSSId 00:A0:57:2A:BD:19 in mode 11n as sonoff-000000-7272...
00:00:36.319 WIF: Attempting connection...
00:00:37.319 WIF: Attempting connection...
00:00:38.319 WIF: Attempting connection...
me-no-dev commented 7 months ago

@Jason2866 please enable verbose debug. I really can not tell what is going on. BTW all fine on my end

[   784][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 9 - WIFI_READY
[   857][W][STA.cpp:571] disconnect(): STA already disconnected.
[   858][V][STA.cpp:210] _onStaEvent(): STA Started
[   867][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 11 - STA_START
[   875][D][STA.cpp:133] _onStaArduinoEvent(): Arduino STA Event: 11 - STA_START
STA Started
E (1758) wifi:NAN WiFi stop
[   887][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 8 - WIFI_OFF
[   919][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 9 - WIFI_READY
[   940][V][STA.cpp:210] _onStaEvent(): STA Started
[   945][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 11 - STA_START
[   952][D][STA.cpp:133] _onStaArduinoEvent(): Arduino STA Event: 11 - STA_START
STA Started
[   999][V][STA.cpp:227] _onStaEvent(): STA Connected: SSID: nbis-test, BSSID: 74:4d:28:c6:7a:fc, Channel: 8, Auth: WPA_WPA2_PSK
[  1012][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 13 - STA_CONNECTED
[  1022][D][STA.cpp:133] _onStaArduinoEvent(): Arduino STA Event: 13 - STA_CONNECTED
[  1025][V][NetworkInterface.cpp:65] _onIpEvent(): sta Got New IP: 192.168.254.84 MASK: 255.255.255.0 GW: 192.168.254.1
[  1041][V][STA.cpp:149] _onStaArduinoEvent(): Enabled IPv6 Link Local on sta
STA Connected
[  1051][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 16 - STA_GOT_IP
[  1060][D][STA.cpp:133] _onStaArduinoEvent(): Arduino STA Event: 16 - STA_GOT_IP
[  1067][D][STA.cpp:194] _onStaArduinoEvent(): STA IP: 192.168.254.84, MASK: 255.255.255.0, GW: 192.168.254.1
sta: <UP,nbis-test,CH:8,RSSI:-41,N,WPA_WPA2_PSK>
      ether 30:C6:F7:F4:2F:8C
      inet 192.168.254.84 netmask 255.255.255.0 broadcast 192.168.254.255
      gateway 192.168.254.1 dns 192.168.254.3
      inet6 fe80::32c6:f7ff:fef4:2f8c%st2 type LINK_LOCAL

[  2758][V][NetworkInterface.cpp:107] _onIpEvent(): IF sta Got IPv6: Interface: 0, IP Index: 0, Type: LINK_LOCAL, Zone: 3 (st2), Address: fe80:0000:0000:0000:32c6:f7ff:fef4:2f8c
[  2774][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 17 - STA_GOT_IP6
[  2782][D][STA.cpp:133] _onStaArduinoEvent(): Arduino STA Event: 17 - STA_GOT_IP6
sta: <UP,nbis-test,CH:8,RSSI:-41,N,WPA_WPA2_PSK>
      ether 30:C6:F7:F4:2F:8C
      inet 192.168.254.84 netmask 255.255.255.0 broadcast 192.168.254.255
      gateway 192.168.254.1 dns 192.168.254.3
      inet6 fe80::32c6:f7ff:fef4:2f8c%st2 type LINK_LOCAL

[  9013][V][STA.cpp:235] _onStaEvent(): STA Disconnected: SSID: nbis-test, BSSID: 74:4d:28:c6:7a:fc, Reason: 8
[  9023][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 14 - STA_DISCONNECTED
[  9031][D][STA.cpp:133] _onStaArduinoEvent(): Arduino STA Event: 14 - STA_DISCONNECTED
[  9039][W][STA.cpp:157] _onStaArduinoEvent(): Reason: 8 - ASSOC_LEAVE
STA Disconnected
E (9921) wifi:NAN WiFi stop
[  9051][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 8 - WIFI_OFF
Jason2866 commented 7 months ago

okay that helps

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:344
load:0x40078000,len:14216
load:0x40080400,len:4
load:0x40080404,len:3232
entry 0x4008057c
[     1][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_RX (2) successfully set to 0x40161d94
[    12][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_TX (3) successfully set to 0x40161db0
[    26][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_CTS (4) successfully set to 0x40161dcc
[    39][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_RTS (5) successfully set to 0x40161de8
[    53][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_RX (2) successfully set to 0x40161d94
[    66][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_TX (3) successfully set to 0x40161db0
[    79][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_CTS (4) successfully set to 0x40161dcc
[    93][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_RTS (5) successfully set to 0x40161de8
[   106][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_RX (2) successfully set to 0x40161d94
[   120][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_TX (3) successfully set to 0x40161db0
[   133][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_CTS (4) successfully set to 0x40161dcc
[   147][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_RTS (5) successfully set to 0x40161de8
[   162][D][esp32-hal-cpu.c:259] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
[   171][W][esp32-hal-psram.c:67] psramInit(): PSRAM init failed!
[   189][V][esp32-hal-periman.c:154] perimanSetPinBus(): Pin 3 successfully set to type UART_RX (2) with bus 0x3ffbdf84
[   199][V][esp32-hal-periman.c:154] perimanSetPinBus(): Pin 1 successfully set to type UART_TX (3) with bus 0x3ffbdf84
[   212][V][esp32-hal-uart.c:396] uartBegin(): UART0 baud(115200) Mode(800001c) rxPin(3) txPin(1)
[   223][V][esp32-hal-uart.c:482] uartBegin(): UART0 not installed. Starting installation
[   234][V][esp32-hal-uart.c:525] uartBegin(): UART0 initialization done.

00:00:00.037 HDW: ESP32-D0WDQ6 v1.0 
00:00:00.050 UFS: FlashFS mounted with 12596 kB free
00:00:00.062 CFG: Loaded from File, Count 12
[   287][E][vfs_api.cpp:105] open(): /debug does not exist, no permits for creation
[   296][E][vfs_api.cpp:105] open(): /debug does not exist, no permits for creation
[   306][E][vfs_api.cpp:105] open(): /debug.bec does not exist, no permits for creation
[   315][E][vfs_api.cpp:105] open(): /debug.bec does not exist, no permits for creation
[   325][E][vfs_api.cpp:105] open(): /debug.be does not exist, no permits for creation
[   334][E][vfs_api.cpp:105] open(): /debug.be does not exist, no permits for creation
00:00:00.144 BRY: Berry initialized, RAM used 4446 bytes
[   359][E][vfs_api.cpp:105] open(): /preinit.be does not exist, no permits for creation
[   370][E][vfs_api.cpp:105] open(): /preinit.bec does not exist, no permits for creation
00:00:00.169 Project sonoff - Tasmota Version 13.4.0.3(arduino30)-3_0_0(2024-03-29T15:39:33)
[   395][E][vfs_api.cpp:105] open(): /autoexec.be does not exist, no permits for creation
[   405][E][vfs_api.cpp:105] open(): /autoexec.bec does not exist, no permits for creation
[   541][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 9 - WIFI_READY
[   618][V][STA.cpp:210] _onStaEvent(): STA Started
[   623][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 11 - STA_START
[   630][D][STA.cpp:133] _onStaArduinoEvent(): Arduino STA Event: 11 - STA_START
[  7025][V][WiFiGeneric.cpp:77] _arduino_event_cb(): SCAN Done: ID: 128, Status: 0, Results: 9
[  7034][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 10 - SCAN_DONE
[  7513][W][STA.cpp:571] disconnect(): STA already disconnected.
[  7524][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 8 - WIFI_OFF
[  7737][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 9 - WIFI_READY
[  7747][V][STA.cpp:210] _onStaEvent(): STA Started
[  7752][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 11 - STA_START
[  7759][D][STA.cpp:133] _onStaArduinoEvent(): Arduino STA Event: 11 - STA_START
[  8046][E][STA.cpp:406] connect(): STA not started! You must call begin() first.
00:00:08.277 WIF: Connecting to AP1 Jason_Home_WLAN Channel 11 BSSId 00:A0:57:2A:BD:19 in mode 11n as sonoff-000000-7272...
00:00:15.819 WIF: Connect failed with AP timeout
00:00:29.824 WIF: Connect failed with AP timeout
[ 37509][V][WiFiGeneric.cpp:77] _arduino_event_cb(): SCAN Done: ID: 129, Status: 0, Results: 8
[ 37518][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 10 - SCAN_DONE
[ 38101][W][STA.cpp:571] disconnect(): STA already disconnected.
[ 38112][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 8 - WIFI_OFF
[ 38325][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 9 - WIFI_READY
[ 38335][V][STA.cpp:210] _onStaEvent(): STA Started
[ 38340][V][NetworkEvents.cpp:125] checkForEvent(): Network Event: 11 - STA_START
[ 38347][D][STA.cpp:133] _onStaArduinoEvent(): Arduino STA Event: 11 - STA_START
[ 38634][E][STA.cpp:406] connect(): STA not started! You must call begin() first.
00:00:38.865 WIF: Connecting to AP1 Jason_Home_WLAN Channel 11 BSSId 00:A0:57:2A:BD:19 in mode 11n as sonoff-000000-7272...
s-hadinger commented 7 months ago

@Jason2866 I'm curious how you enable this detailed logging in Tasmota builds

Jason2866 commented 7 months ago

@s-hadinger You will get maaany warnings but it works with adding to the env build_flags -DCORE_DEBUG_LEVEL=5 I have this env

[env:tasmota32-arduino30]
extends                 = env:arduino30
board                   = esp32
board_build.f_flash     = 80000000L
board_build.f_cpu       = 240000000L
board_build.flash_mode  = qio
build_unflags           = ${env:arduino30.build_unflags}
build_flags             = ${env:arduino30.build_flags}
                          -DFIRMWARE_ARDUINO30
                          -DCORE_DEBUG_LEVEL=5
monitor_filters         = esp32_exception_decoder
lib_ignore              = ${env:arduino30.lib_ignore}

We call begin(). So curious what is now going to the south

me-no-dev commented 7 months ago

yup. I see where it fails. just a sec

me-no-dev commented 7 months ago

ok... how did you get to call WiFi.STA.connect(), without calling WiFi.STA.begin(), or WiFi.mode(WIFI_STA) before that... you are not calling some IDF APIs directly, are you?

s-hadinger commented 7 months ago

Let me try with some Tasmota logs in between to see why this happens.

me-no-dev commented 7 months ago

@s-hadinger in a mean time I pushed an update to the PR that makes sure that STA and AP receive the STOP event. Don't know if this helps you