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
This commit is contained in:
parent
88293a4284
commit
21ff3d0e32
@ -122,16 +122,11 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel,
|
||||
|
||||
wifi_config_t conf_current;
|
||||
esp_wifi_get_config(WIFI_IF_AP, &conf_current);
|
||||
if(softap_config_equal(conf, conf_current)) {
|
||||
//DEBUGV("softap config unchanged");
|
||||
return true;
|
||||
if(!softap_config_equal(conf, conf_current) && esp_wifi_set_config(WIFI_IF_AP, &conf) != ESP_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret;
|
||||
|
||||
ret = esp_wifi_set_config(WIFI_IF_AP, &conf) == ESP_OK;
|
||||
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -149,12 +144,25 @@ bool WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress
|
||||
return false;
|
||||
}
|
||||
|
||||
esp_wifi_start();
|
||||
|
||||
tcpip_adapter_ip_info_t info;
|
||||
info.ip.addr = static_cast<uint32_t>(local_ip);
|
||||
info.gw.addr = static_cast<uint32_t>(gateway);
|
||||
info.netmask.addr = static_cast<uint32_t>(subnet);
|
||||
tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP);
|
||||
if(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &info) == ESP_OK) {
|
||||
dhcps_lease_t lease;
|
||||
lease.enable = true;
|
||||
lease.start_ip.addr = static_cast<uint32_t>(local_ip) + (1 << 24);
|
||||
lease.end_ip.addr = static_cast<uint32_t>(local_ip) + (11 << 24);
|
||||
|
||||
tcpip_adapter_dhcps_option(
|
||||
(tcpip_adapter_option_mode_t)TCPIP_ADAPTER_OP_SET,
|
||||
(tcpip_adapter_option_id_t)REQUESTED_IP_ADDRESS,
|
||||
(void*)&lease, sizeof(dhcps_lease_t)
|
||||
);
|
||||
|
||||
return tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_AP) == ESP_OK;
|
||||
}
|
||||
return false;
|
||||
|
@ -51,11 +51,19 @@ extern "C" {
|
||||
#undef max
|
||||
#include <vector>
|
||||
|
||||
void tcpipInit(){
|
||||
static bool initialized = false;
|
||||
if(!initialized){
|
||||
initialized = true;
|
||||
tcpip_adapter_init();
|
||||
esp_event_loop_init(&WiFiGenericClass::_eventCallback, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static bool wifiLowLevelInit(){
|
||||
static bool lowLevelInitDone = false;
|
||||
if(!lowLevelInitDone){
|
||||
tcpip_adapter_init();
|
||||
esp_event_loop_init(&WiFiGenericClass::_eventCallback, NULL);
|
||||
tcpipInit();
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
esp_err_t err = esp_wifi_init(&cfg);
|
||||
if(err){
|
||||
@ -172,7 +180,6 @@ const char * system_event_reasons[] = { "UNSPECIFIED", "AUTH_EXPIRE", "AUTH_LEAV
|
||||
esp_err_t WiFiGenericClass::_eventCallback(void *arg, system_event_t *event)
|
||||
{
|
||||
log_d("Event: %d - %s", event->event_id, system_event_names[event->event_id]);
|
||||
|
||||
if(event->event_id == SYSTEM_EVENT_SCAN_DONE) {
|
||||
WiFiScanClass::_scanDone();
|
||||
} else if(event->event_id == SYSTEM_EVENT_STA_DISCONNECTED) {
|
||||
|
@ -201,6 +201,7 @@ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subne
|
||||
if(!WiFi.enableSTA(true)) {
|
||||
return false;
|
||||
}
|
||||
esp_wifi_start();
|
||||
|
||||
tcpip_adapter_ip_info_t info;
|
||||
info.ip.addr = static_cast<uint32_t>(local_ip);
|
||||
|
Loading…
Reference in New Issue
Block a user