Fix SmartConfig not saving the correct config
Fixes: https://github.com/espressif/arduino-esp32/issues/275
This commit is contained in:
parent
dda89947a7
commit
a07f9842af
@ -41,6 +41,7 @@ extern "C" {
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/dns.h"
|
||||
#include <esp_smartconfig.h>
|
||||
#include <tcpip_adapter.h>
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------
|
||||
@ -524,6 +525,7 @@ bool WiFiSTAClass::beginSmartConfig() {
|
||||
return false;
|
||||
}
|
||||
|
||||
esp_wifi_disconnect();
|
||||
|
||||
esp_err_t err;
|
||||
err = esp_smartconfig_start(reinterpret_cast<sc_callback_t>(&WiFiSTAClass::_smartConfigCallback), 1);
|
||||
@ -556,17 +558,39 @@ bool WiFiSTAClass::smartConfigDone() {
|
||||
return _smartConfigDone;
|
||||
}
|
||||
|
||||
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
|
||||
const char * sc_status_strings[] = {
|
||||
"WAIT",
|
||||
"FIND_CHANNEL",
|
||||
"GETTING_SSID_PSWD",
|
||||
"LINK",
|
||||
"LINK_OVER"
|
||||
};
|
||||
|
||||
const char * sc_type_strings[] = {
|
||||
"ESPTOUCH",
|
||||
"AIRKISS",
|
||||
"ESPTOUCH_AIRKISS"
|
||||
};
|
||||
#endif
|
||||
|
||||
void WiFiSTAClass::_smartConfigCallback(uint32_t st, void* result) {
|
||||
smartconfig_status_t status = (smartconfig_status_t) st;
|
||||
if (status == SC_STATUS_LINK) {
|
||||
log_d("Status: %s", sc_status_strings[st % 5]);
|
||||
if (status == SC_STATUS_GETTING_SSID_PSWD) {
|
||||
smartconfig_type_t * type = (smartconfig_type_t *)result;
|
||||
log_d("Type: %s", sc_type_strings[*type % 3]);
|
||||
} else if (status == SC_STATUS_LINK) {
|
||||
wifi_sta_config_t *sta_conf = reinterpret_cast<wifi_sta_config_t *>(result);
|
||||
|
||||
esp_wifi_set_config(WIFI_IF_AP, (wifi_config_t *)sta_conf);
|
||||
esp_wifi_disconnect();
|
||||
log_d("SSID: %s", (char *)(sta_conf->ssid));
|
||||
esp_wifi_set_config(WIFI_IF_STA, (wifi_config_t *)sta_conf);
|
||||
esp_wifi_connect();
|
||||
|
||||
_smartConfigDone = true;
|
||||
} else if (status == SC_STATUS_LINK_OVER) {
|
||||
if(result){
|
||||
ip4_addr_t * ip = (ip4_addr_t *)result;
|
||||
log_d("Sender IP: " IPSTR, IP2STR(ip));
|
||||
}
|
||||
WiFi.stopSmartConfig();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user