@@ -688,6 +688,7 @@ bool WiFiSTAClass::beginSmartConfig() {
688688
689689 esp_err_t err;
690690#ifdef ESP_IDF_VERSION_MAJOR
691+ esp_event_handler_register (SC_EVENT, ESP_EVENT_ANY_ID, _smartConfigCallback, this );
691692 smartconfig_start_config_t conf = SMARTCONFIG_START_CONFIG_DEFAULT ();
692693 err = esp_smartconfig_start (&conf);
693694#else
@@ -722,6 +723,45 @@ bool WiFiSTAClass::smartConfigDone() {
722723 return _smartConfigDone;
723724}
724725
726+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
727+ const char * sc_type_strings[] = {
728+ " ESPTOUCH" ,
729+ " AIRKISS" ,
730+ " ESPTOUCH_AIRKISS"
731+ };
732+ #endif
733+
734+
735+ #ifdef ESP_IDF_VERSION_MAJOR // todo
736+ void WiFiSTAClass::_smartConfigCallback (void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data){
737+ smartconfig_event_t event = (smartconfig_event_t )event_id;
738+ switch (event){
739+ case SC_EVENT_SCAN_DONE:
740+ log_d (" smartconfig has finished to scan for APs" );
741+ break ;
742+ case SC_EVENT_FOUND_CHANNEL:
743+ log_d (" smartconfig has found the channel of the target AP" );
744+ break ;
745+ case SC_EVENT_GOT_SSID_PSWD:
746+ {
747+ log_d (" smartconfig got the SSID and password" );
748+ smartconfig_event_got_ssid_pswd_t * data = (smartconfig_event_got_ssid_pswd_t *)event_data;
749+ log_d (" Type: %s" , sc_type_strings[data->type ]);
750+ log_d (" SSID: %s" , (const char *)data->ssid );
751+ log_d (" Password: %s" , (const char *)data->password );
752+ log_d (" Sender IP: " IPSTR, data->cellphone_ip [3 ], data->cellphone_ip [2 ], data->cellphone_ip [1 ], data->cellphone_ip [0 ]);
753+ WiFi.begin ((const char *)data->ssid , (const char *)data->password );
754+ }
755+ break ;
756+ case SC_EVENT_SEND_ACK_DONE:
757+ log_d (" smartconfig has sent ACK to the sender" );
758+ WiFi.stopSmartConfig ();
759+ break ;
760+ default : break ;
761+ }
762+ }
763+ #else
764+
725765#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
726766const char * sc_status_strings[] = {
727767 " WAIT" ,
@@ -730,16 +770,9 @@ const char * sc_status_strings[] = {
730770 " LINK" ,
731771 " LINK_OVER"
732772};
733-
734- const char * sc_type_strings[] = {
735- " ESPTOUCH" ,
736- " AIRKISS" ,
737- " ESPTOUCH_AIRKISS"
738- };
739773#endif
740774
741775void WiFiSTAClass::_smartConfigCallback (uint32_t st, void * result) {
742- #ifndef ESP_IDF_VERSION_MAJOR // todo
743776 smartconfig_status_t status = (smartconfig_status_t ) st;
744777 log_d (" Status: %s" , sc_status_strings[st % 5 ]);
745778 if (status == SC_STATUS_GETTING_SSID_PSWD) {
@@ -763,5 +796,5 @@ void WiFiSTAClass::_smartConfigCallback(uint32_t st, void* result) {
763796 }
764797 WiFi.stopSmartConfig ();
765798 }
766- #endif
767799}
800+ #endif
0 commit comments