Skip to content

Commit f14a853

Browse files
committed
get smart config to work as well
1 parent 92db973 commit f14a853

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

libraries/WiFi/src/ETH.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ extern void tcpipInit();
6969
//}
7070

7171

72+
7273
// Event handler for Ethernet
7374
void ETHClass::eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
7475
{
@@ -118,6 +119,7 @@ static void _eth_phy_power_enable(bool enable)
118119
ETHClass::ETHClass()
119120
:initialized(false)
120121
,staticIP(false)
122+
,eth_handle(NULL)
121123
,started(false)
122124
,eth_link(ETH_LINK_DOWN)
123125
{
@@ -131,7 +133,6 @@ bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_typ
131133

132134
tcpipInit();
133135

134-
esp_event_loop_create_default();
135136
tcpip_adapter_set_default_eth_handlers();
136137
esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, eth_event_handler, this);
137138
//ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL));

libraries/WiFi/src/WiFiGeneric.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ void tcpipInit(){
128128
if(esp_efuse_mac_get_default(mac) == ESP_OK){
129129
esp_base_mac_addr_set(mac);
130130
}
131+
esp_event_loop_create_default();
131132
#endif
132133
tcpip_adapter_init();
133134
}

libraries/WiFi/src/WiFiSTA.cpp

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
726766
const 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

741775
void 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

libraries/WiFi/src/WiFiSTA.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
#include "WiFiType.h"
2828
#include "WiFiGeneric.h"
29+
#ifdef ESP_IDF_VERSION_MAJOR
30+
#include "esp_event.h"
31+
#endif
2932

3033

3134
class WiFiSTAClass
@@ -98,7 +101,11 @@ class WiFiSTAClass
98101
protected:
99102
static bool _smartConfigStarted;
100103
static bool _smartConfigDone;
104+
#ifdef ESP_IDF_VERSION_MAJOR //todo
105+
static void _smartConfigCallback(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
106+
#else
101107
static void _smartConfigCallback(uint32_t status, void* result);
108+
#endif
102109

103110
};
104111

0 commit comments

Comments
 (0)