Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WiFi and Ethernet - config static IP auto gw,mask,dns as in Arduino libs #1862

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions libraries/WiFi/src/WiFiClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ bool WiFiClass::connected() {
param local_ip: Static ip configuration
*/
void WiFiClass::config(IPAddress local_ip) {
ip4_addr_set_u32(ip_2_ip4(&_wifi.getNetIf()->ip_addr), local_ip.v4());
_wifi.config(local_ip);
}

/* Change Ip configuration settings disabling the dhcp client
Expand All @@ -202,8 +202,7 @@ void WiFiClass::config(IPAddress local_ip) {
param dns_server: IP configuration for DNS server 1
*/
void WiFiClass::config(IPAddress local_ip, IPAddress dns_server) {
ip4_addr_set_u32(ip_2_ip4(&_wifi.getNetIf()->ip_addr), local_ip.v4());
dns_setserver(0, dns_server);
_wifi.config(local_ip, dns_server);
}

/* Change Ip configuration settings disabling the dhcp client
Expand All @@ -213,9 +212,7 @@ void WiFiClass::config(IPAddress local_ip, IPAddress dns_server) {
param gateway : Static gateway configuration
*/
void WiFiClass::config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway) {
ip4_addr_set_u32(ip_2_ip4(&_wifi.getNetIf()->ip_addr), local_ip.v4());
dns_setserver(0, dns_server);
ip4_addr_set_u32(ip_2_ip4(&_wifi.getNetIf()->gw), gateway.v4());
_wifi.config(local_ip, dns_server, gateway);
}

/* Change Ip configuration settings disabling the dhcp client
Expand Down
23 changes: 23 additions & 0 deletions libraries/lwIP_Ethernet/src/LwipIntfDev.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ class LwipIntfDev: public LwipIntf, public RawDev {
memset(&_netif, 0, sizeof(_netif));
}

//The argument order for ESP is not the same as for Arduino. However, there is compatibility code under the hood
//to detect Arduino arg order, and handle it correctly.
bool config(const IPAddress& local_ip, const IPAddress& arg1, const IPAddress& arg2,
const IPAddress& arg3 = IPADDR_NONE, const IPAddress& dns2 = IPADDR_NONE);

// two and one parameter version. 2nd parameter is DNS like in Arduino. IPv4 only
boolean config(IPAddress local_ip, IPAddress dns = IPADDR_NONE);

// default mac-address is inferred from esp8266's STA interface
bool begin(const uint8_t* macAddress = nullptr, const uint16_t mtu = DEFAULT_MTU);

Expand Down Expand Up @@ -264,6 +269,24 @@ bool LwipIntfDev<RawDev>::config(const IPAddress& localIP, const IPAddress& gate
}
return true;
}

template<class RawDev>
boolean LwipIntfDev<RawDev>::config(IPAddress local_ip, IPAddress dns) {

if (!local_ip.isSet()) {
return config(INADDR_ANY, INADDR_ANY, INADDR_ANY);
}
if (!local_ip.isV4()) {
return false;
}
IPAddress gw(local_ip);
gw[3] = 1;
earlephilhower marked this conversation as resolved.
Show resolved Hide resolved
if (!dns.isSet()) {
dns = gw;
}
return config(local_ip, gw, IPAddress(255, 255, 255, 0), dns);
}

extern char wifi_station_hostname[];
template<class RawDev>
bool LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu) {
Expand Down