@@ -693,6 +693,7 @@ bool WiFiSTAClass::beginSmartConfig() {
693
693
694
694
esp_err_t err;
695
695
#ifdef ESP_IDF_VERSION_MAJOR
696
+ esp_event_handler_register (SC_EVENT, ESP_EVENT_ANY_ID, _smartConfigCallback, this );
696
697
smartconfig_start_config_t conf = SMARTCONFIG_START_CONFIG_DEFAULT ();
697
698
err = esp_smartconfig_start (&conf);
698
699
#else
@@ -727,6 +728,45 @@ bool WiFiSTAClass::smartConfigDone() {
727
728
return _smartConfigDone;
728
729
}
729
730
731
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
732
+ const char * sc_type_strings[] = {
733
+ " ESPTOUCH" ,
734
+ " AIRKISS" ,
735
+ " ESPTOUCH_AIRKISS"
736
+ };
737
+ #endif
738
+
739
+
740
+ #ifdef ESP_IDF_VERSION_MAJOR // todo
741
+ void WiFiSTAClass::_smartConfigCallback (void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data){
742
+ smartconfig_event_t event = (smartconfig_event_t )event_id;
743
+ switch (event){
744
+ case SC_EVENT_SCAN_DONE:
745
+ log_d (" smartconfig has finished to scan for APs" );
746
+ break ;
747
+ case SC_EVENT_FOUND_CHANNEL:
748
+ log_d (" smartconfig has found the channel of the target AP" );
749
+ break ;
750
+ case SC_EVENT_GOT_SSID_PSWD:
751
+ {
752
+ log_d (" smartconfig got the SSID and password" );
753
+ smartconfig_event_got_ssid_pswd_t * data = (smartconfig_event_got_ssid_pswd_t *)event_data;
754
+ log_d (" Type: %s" , sc_type_strings[data->type ]);
755
+ log_d (" SSID: %s" , (const char *)data->ssid );
756
+ log_d (" Password: %s" , (const char *)data->password );
757
+ log_d (" Sender IP: " IPSTR, data->cellphone_ip [3 ], data->cellphone_ip [2 ], data->cellphone_ip [1 ], data->cellphone_ip [0 ]);
758
+ WiFi.begin ((const char *)data->ssid , (const char *)data->password );
759
+ }
760
+ break ;
761
+ case SC_EVENT_SEND_ACK_DONE:
762
+ log_d (" smartconfig has sent ACK to the sender" );
763
+ WiFi.stopSmartConfig ();
764
+ break ;
765
+ default : break ;
766
+ }
767
+ }
768
+ #else
769
+
730
770
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
731
771
const char * sc_status_strings[] = {
732
772
" WAIT" ,
@@ -735,16 +775,9 @@ const char * sc_status_strings[] = {
735
775
" LINK" ,
736
776
" LINK_OVER"
737
777
};
738
-
739
- const char * sc_type_strings[] = {
740
- " ESPTOUCH" ,
741
- " AIRKISS" ,
742
- " ESPTOUCH_AIRKISS"
743
- };
744
778
#endif
745
779
746
780
void WiFiSTAClass::_smartConfigCallback (uint32_t st, void * result) {
747
- #ifndef ESP_IDF_VERSION_MAJOR // todo
748
781
smartconfig_status_t status = (smartconfig_status_t ) st;
749
782
log_d (" Status: %s" , sc_status_strings[st % 5 ]);
750
783
if (status == SC_STATUS_GETTING_SSID_PSWD) {
@@ -768,5 +801,5 @@ void WiFiSTAClass::_smartConfigCallback(uint32_t st, void* result) {
768
801
}
769
802
WiFi.stopSmartConfig ();
770
803
}
771
- #endif
772
804
}
805
+ #endif
0 commit comments