PlatformIO Community

Problem with esp_wifi_init() -> ESP_ERROR_CHECK failed: esp_err_t 0x102 (ESP_ERR_INVALID_ARG) at 0x40086df4

Hi All!
I have strange problem with function esp_wifi_init().
When I call this function directly in main.c file after startup like this:

void app_main(void)
{
ESP_ERROR_CHECK(nvs_flash_init());
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());

wifi_init_config_t temp = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&temp));

setup();

while (true)
{
    vTaskDelay(portMAX_DELAY);
}

}

everything is ok. But i want to wrap wifi C API into some convienient C++ set of classes and when I write something like this:

WiFiError WiFi::init(void)
{
ESP_ERROR_CHECK(nvs_flash_init());
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());

wifi_init_config_t temp = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&temp));

auto netif_handle = esp_netif_create_default_wifi_sta();
esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, WiFi::eventHandler, this, &m_instance_any_id);
esp_event_handler_instance_register(IP_EVENT, ESP_EVENT_ANY_ID, WiFi::eventHandler, this, &m_instance_any_id);
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_start());
m_wifi_state = WiFiStaState::STARTING;

return WiFiError::WIFI_OK;

}

i get:

ESP_ERROR_CHECK failed: esp_err_t 0x102 (ESP_ERR_INVALID_ARG) at 0x40086df4
file: “lib/WiFi/WiFi.cpp” line 46
func: WiFiError WiFi::init()
expression: esp_wifi_init(&temp)

abort() was called at PC 0x40086df7 on core 1

Can someone tell me what is going on? I have spent all day on this…
This WiFi C++ class is compiled as library because it’s placed in lib folder.