Skip to content

Commit 2ca7822

Browse files
author
blue-2357
committed
Fix SmartConfig not saving the correct config
Fixes: espressif/arduino-esp32#275
1 parent d553d0c commit 2ca7822

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

Diff for: libraries/WiFi/src/WiFiSTA.cpp

+29-5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern "C" {
4141
#include "lwip/err.h"
4242
#include "lwip/dns.h"
4343
#include <esp_smartconfig.h>
44+
#include <tcpip_adapter.h>
4445
}
4546

4647
// -----------------------------------------------------------------------------------------------------------------------
@@ -524,6 +525,7 @@ bool WiFiSTAClass::beginSmartConfig() {
524525
return false;
525526
}
526527

528+
esp_wifi_disconnect();
527529

528530
esp_err_t err;
529531
err = esp_smartconfig_start(reinterpret_cast<sc_callback_t>(&WiFiSTAClass::_smartConfigCallback), 1);
@@ -556,17 +558,39 @@ bool WiFiSTAClass::smartConfigDone() {
556558
return _smartConfigDone;
557559
}
558560

561+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
562+
const char * sc_status_strings[] = {
563+
"WAIT",
564+
"FIND_CHANNEL",
565+
"GETTING_SSID_PSWD",
566+
"LINK",
567+
"LINK_OVER"
568+
};
569+
570+
const char * sc_type_strings[] = {
571+
"ESPTOUCH",
572+
"AIRKISS",
573+
"ESPTOUCH_AIRKISS"
574+
};
575+
#endif
576+
559577
void WiFiSTAClass::_smartConfigCallback(uint32_t st, void* result) {
560578
smartconfig_status_t status = (smartconfig_status_t) st;
561-
if (status == SC_STATUS_LINK) {
579+
log_d("Status: %s", sc_status_strings[st % 5]);
580+
if (status == SC_STATUS_GETTING_SSID_PSWD) {
581+
smartconfig_type_t * type = (smartconfig_type_t *)result;
582+
log_d("Type: %s", sc_type_strings[*type % 3]);
583+
} else if (status == SC_STATUS_LINK) {
562584
wifi_sta_config_t *sta_conf = reinterpret_cast<wifi_sta_config_t *>(result);
563-
564-
esp_wifi_set_config(WIFI_IF_AP, (wifi_config_t *)sta_conf);
565-
esp_wifi_disconnect();
585+
log_d("SSID: %s", (char *)(sta_conf->ssid));
586+
esp_wifi_set_config(WIFI_IF_STA, (wifi_config_t *)sta_conf);
566587
esp_wifi_connect();
567-
568588
_smartConfigDone = true;
569589
} else if (status == SC_STATUS_LINK_OVER) {
590+
if(result){
591+
ip4_addr_t * ip = (ip4_addr_t *)result;
592+
log_d("Sender IP: " IPSTR, IP2STR(ip));
593+
}
570594
WiFi.stopSmartConfig();
571595
}
572596
}

0 commit comments

Comments
 (0)