@@ -41,6 +41,7 @@ extern "C" {
41
41
#include " lwip/err.h"
42
42
#include " lwip/dns.h"
43
43
#include < esp_smartconfig.h>
44
+ #include < tcpip_adapter.h>
44
45
}
45
46
46
47
// -----------------------------------------------------------------------------------------------------------------------
@@ -524,6 +525,7 @@ bool WiFiSTAClass::beginSmartConfig() {
524
525
return false ;
525
526
}
526
527
528
+ esp_wifi_disconnect ();
527
529
528
530
esp_err_t err;
529
531
err = esp_smartconfig_start (reinterpret_cast <sc_callback_t >(&WiFiSTAClass::_smartConfigCallback), 1 );
@@ -556,17 +558,39 @@ bool WiFiSTAClass::smartConfigDone() {
556
558
return _smartConfigDone;
557
559
}
558
560
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
+
559
577
void WiFiSTAClass::_smartConfigCallback (uint32_t st, void * result) {
560
578
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) {
562
584
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);
566
587
esp_wifi_connect ();
567
-
568
588
_smartConfigDone = true ;
569
589
} 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
+ }
570
594
WiFi.stopSmartConfig ();
571
595
}
572
596
}
0 commit comments