From a63da92e822f1b73fe873194c0b2c69d16951bd1 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Wed, 4 Apr 2018 09:09:41 +0200 Subject: [PATCH] set auto_connect before station configuration idf 3.1 connects automatically upon esp_wifi_sta_config() --- components/modules/wifi_sta.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/components/modules/wifi_sta.c b/components/modules/wifi_sta.c index 6cdf6f5e..d2848eea 100644 --- a/components/modules/wifi_sta.c +++ b/components/modules/wifi_sta.c @@ -214,18 +214,18 @@ static int wifi_sta_config (lua_State *L) bool auto_conn = luaL_optbool (L, -1, true); SET_SAVE_MODE(save); - esp_err_t err = esp_wifi_set_config (WIFI_IF_STA, &cfg); + esp_err_t err = esp_wifi_set_auto_connect (auto_conn); + if (err != ESP_OK) + return luaL_error (L, "failed to set wifi auto-connect, code %d", err); + + err = esp_wifi_set_config (WIFI_IF_STA, &cfg); if (err != ESP_OK) return luaL_error (L, "failed to set wifi config, code %d", err); if (auto_conn) err = esp_wifi_connect (); - if (err != ESP_OK) - return luaL_error (L, "failed to begin connect, code %d", err); - - err = esp_wifi_set_auto_connect (auto_conn); return (err == ESP_OK) ? - 0 : luaL_error (L, "failed to set wifi auto-connect, code %d", err); + 0 : luaL_error (L, "failed to begin connect, code %d", err); }