Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 21ff3d0

Browse filesBrowse files
committed
Slight rework of WiFi Class
- call esp_wifi_start() - separate tcp initialization to prepare for Ethernet - setup dhcp addresses when using custom IP config for SoftAP
1 parent 88293a4 commit 21ff3d0
Copy full SHA for 21ff3d0

File tree

Expand file treeCollapse file tree

3 files changed

+27
-11
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+27
-11
lines changed

‎libraries/WiFi/src/WiFiAP.cpp

Copy file name to clipboardExpand all lines: libraries/WiFi/src/WiFiAP.cpp
+16-8Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,11 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel,
122122

123123
wifi_config_t conf_current;
124124
esp_wifi_get_config(WIFI_IF_AP, &conf_current);
125-
if(softap_config_equal(conf, conf_current)) {
126-
//DEBUGV("softap config unchanged");
127-
return true;
125+
if(!softap_config_equal(conf, conf_current) && esp_wifi_set_config(WIFI_IF_AP, &conf) != ESP_OK) {
126+
return false;
128127
}
129128

130-
bool ret;
131-
132-
ret = esp_wifi_set_config(WIFI_IF_AP, &conf) == ESP_OK;
133-
134-
return ret;
129+
return true;
135130
}
136131

137132

@@ -149,12 +144,25 @@ bool WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress
149144
return false;
150145
}
151146

147+
esp_wifi_start();
148+
152149
tcpip_adapter_ip_info_t info;
153150
info.ip.addr = static_cast<uint32_t>(local_ip);
154151
info.gw.addr = static_cast<uint32_t>(gateway);
155152
info.netmask.addr = static_cast<uint32_t>(subnet);
156153
tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP);
157154
if(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &info) == ESP_OK) {
155+
dhcps_lease_t lease;
156+
lease.enable = true;
157+
lease.start_ip.addr = static_cast<uint32_t>(local_ip) + (1 << 24);
158+
lease.end_ip.addr = static_cast<uint32_t>(local_ip) + (11 << 24);
159+
160+
tcpip_adapter_dhcps_option(
161+
(tcpip_adapter_option_mode_t)TCPIP_ADAPTER_OP_SET,
162+
(tcpip_adapter_option_id_t)REQUESTED_IP_ADDRESS,
163+
(void*)&lease, sizeof(dhcps_lease_t)
164+
);
165+
158166
return tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_AP) == ESP_OK;
159167
}
160168
return false;

‎libraries/WiFi/src/WiFiGeneric.cpp

Copy file name to clipboardExpand all lines: libraries/WiFi/src/WiFiGeneric.cpp
+10-3Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,19 @@ extern "C" {
5151
#undef max
5252
#include <vector>
5353

54+
void tcpipInit(){
55+
static bool initialized = false;
56+
if(!initialized){
57+
initialized = true;
58+
tcpip_adapter_init();
59+
esp_event_loop_init(&WiFiGenericClass::_eventCallback, NULL);
60+
}
61+
}
62+
5463
static bool wifiLowLevelInit(){
5564
static bool lowLevelInitDone = false;
5665
if(!lowLevelInitDone){
57-
tcpip_adapter_init();
58-
esp_event_loop_init(&WiFiGenericClass::_eventCallback, NULL);
66+
tcpipInit();
5967
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
6068
esp_err_t err = esp_wifi_init(&cfg);
6169
if(err){
@@ -172,7 +180,6 @@ const char * system_event_reasons[] = { "UNSPECIFIED", "AUTH_EXPIRE", "AUTH_LEAV
172180
esp_err_t WiFiGenericClass::_eventCallback(void *arg, system_event_t *event)
173181
{
174182
log_d("Event: %d - %s", event->event_id, system_event_names[event->event_id]);
175-
176183
if(event->event_id == SYSTEM_EVENT_SCAN_DONE) {
177184
WiFiScanClass::_scanDone();
178185
} else if(event->event_id == SYSTEM_EVENT_STA_DISCONNECTED) {

‎libraries/WiFi/src/WiFiSTA.cpp

Copy file name to clipboardExpand all lines: libraries/WiFi/src/WiFiSTA.cpp
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subne
201201
if(!WiFi.enableSTA(true)) {
202202
return false;
203203
}
204+
esp_wifi_start();
204205

205206
tcpip_adapter_ip_info_t info;
206207
info.ip.addr = static_cast<uint32_t>(local_ip);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.