Skip to content

Commit 1e6725a

Browse files
committed
Switch AP to the new interface
1 parent 1f5b81d commit 1e6725a

13 files changed

+424
-323
lines changed

CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ set(ARDUINO_LIBRARY_WiFi_SRCS
218218
libraries/WiFi/src/WiFiMulti.cpp
219219
libraries/WiFi/src/WiFiScan.cpp
220220
libraries/WiFi/src/WiFiSTA.cpp
221-
libraries/WiFi/src/STA.cpp)
221+
libraries/WiFi/src/STA.cpp
222+
libraries/WiFi/src/AP.cpp)
222223

223224
set(ARDUINO_LIBRARY_WiFiProv_SRCS libraries/WiFiProv/src/WiFiProv.cpp)
224225

libraries/Networking/src/ESP_Network_Events.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
16
#include "ESP_Network_Events.h"
27
#include "ESP_Network_Manager.h"
38
#include "esp_task.h"

libraries/Networking/src/ESP_Network_Events.h

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
16
#pragma once
27

38
#include "soc/soc_caps.h"
@@ -156,6 +161,7 @@ class ESP_Network_Events {
156161
friend class ETHClass;
157162
#if SOC_WIFI_SUPPORTED
158163
friend class STAClass;
164+
friend class APClass;
159165
friend class WiFiGenericClass;
160166
#endif
161167

libraries/Networking/src/ESP_Network_Interface.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
16
#include "ESP_Network_Interface.h"
27
#include "esp_netif.h"
38
#include "esp_netif_defaults.h"
@@ -366,12 +371,14 @@ bool ESP_Network_Interface::config(IPAddress local_ip, IPAddress gateway, IPAddr
366371
}
367372

368373
// Set DNS Server
369-
esp_netif_set_dns_info(_esp_netif, ESP_NETIF_DNS_MAIN, &d1);
374+
if(d2.ip.u_addr.ip4.addr != 0){
375+
esp_netif_set_dns_info(_esp_netif, ESP_NETIF_DNS_MAIN, &d2);
376+
}
370377

371378
dhcps_lease_t lease;
372379
lease.enable = true;
373380
uint8_t CIDR = calculateSubnetCIDR(subnet);
374-
log_v("SoftAP: %s | Gateway: %s | DHCP Start: %s | Netmask: %s", local_ip.toString().c_str(), gateway.toString().c_str(), dns2.toString().c_str(), subnet.toString().c_str());
381+
log_v("SoftAP: %s | Gateway: %s | DHCP Start: %s | Netmask: %s", local_ip.toString().c_str(), gateway.toString().c_str(), dns1.toString().c_str(), subnet.toString().c_str());
375382
// netmask must have room for at least 12 IP addresses (AP + GW + 10 DHCP Leasing addresses)
376383
// netmask also must be limited to the last 8 bits of IPv4, otherwise this function won't work
377384
// IDF NETIF checks netmask for the 3rd byte: https://github.com/espressif/esp-idf/blob/master/components/esp_netif/lwip/esp_netif_lwip.c#L1857-L1862
@@ -383,7 +390,7 @@ bool ESP_Network_Interface::config(IPAddress local_ip, IPAddress gateway, IPAddr
383390
// The code below is ready for any netmask, not limited to 255.255.255.0
384391
uint32_t netmask = _byte_swap32(info.netmask.addr);
385392
uint32_t ap_ipaddr = _byte_swap32(info.ip.addr);
386-
uint32_t dhcp_ipaddr = _byte_swap32(static_cast<uint32_t>(dns2));
393+
uint32_t dhcp_ipaddr = _byte_swap32(static_cast<uint32_t>(dns1));
387394
dhcp_ipaddr = dhcp_ipaddr == 0 ? ap_ipaddr + 1 : dhcp_ipaddr;
388395
uint32_t leaseStartMax = ~netmask - 10;
389396
// there will be 10 addresses for DHCP to lease

libraries/Networking/src/ESP_Network_Interface.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
16
#pragma once
27

38
#include "esp_netif_types.h"
@@ -30,7 +35,7 @@ class ESP_Network_Interface: public Printable {
3035
ESP_Network_Interface();
3136
virtual ~ESP_Network_Interface();
3237

33-
// For server interfaces (WiFi AP), dns1 is the DNS and dns2 is the lease range start
38+
// For server interfaces (WiFi AP), dns1 is the DHCP lease range start and dns2 is the DNS. dns3 is not used
3439
bool config(IPAddress local_ip = (uint32_t)0x00000000, IPAddress gateway = (uint32_t)0x00000000, IPAddress subnet = (uint32_t)0x00000000, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000, IPAddress dns3 = (uint32_t)0x00000000);
3540
bool dnsIP(uint8_t dns_no, IPAddress ip);
3641

libraries/Networking/src/ESP_Network_Manager.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
16
#include "ESP_Network_Manager.h"
27
#include "esp_netif.h"
38
#include "lwip/ip_addr.h"

libraries/Networking/src/ESP_Network_Manager.h

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
16
#pragma once
27

38
#include "ESP_Network_Events.h"

libraries/Networking/src/Networking.h

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
16
#pragma once
27

38
#include "ESP_Network_Interface.h"

0 commit comments

Comments
 (0)