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

LwipIntfDev - config static IP auto gw,mask,dns as in Arduino libraries #9040

Merged
merged 2 commits 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
26 changes: 23 additions & 3 deletions cores/esp8266/LwipIntfDev.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,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.
boolean 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 = INADDR_ANY);

// default mac-address is inferred from esp8266's STA interface
boolean begin(const uint8_t* macAddress = nullptr, const uint16_t mtu = DEFAULT_MTU);
void end();
Expand Down Expand Up @@ -209,6 +214,24 @@ boolean LwipIntfDev<RawDev>::config(const IPAddress& localIP, const IPAddress& g
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;
if (!dns.isSet())
{
dns = gw;
}
return config(local_ip, gw, IPAddress(255, 255, 255, 0), dns);
}

template<class RawDev>
boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu)
{
Expand Down Expand Up @@ -336,9 +359,6 @@ template<class RawDev>
void LwipIntfDev<RawDev>::end()
{
netif_remove(&_netif);
ip_addr_copy(_netif.ip_addr, ip_addr_any); // to allow DHCP at next begin
ip_addr_copy(_netif.netmask, ip_addr_any);
ip_addr_copy(_netif.gw, ip_addr_any);
_started = false;
RawDev::end();
}
Expand Down
7 changes: 7 additions & 0 deletions libraries/lwIP_Ethernet/src/EthernetCompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ class ArduinoEthernet: public LwipIntfDev<RawDev>
return ret;
}

void end()
{
ip_addr_copy(LwipIntfDev<RawDev>::_netif.ip_addr,
ip_addr_any); // to allow DHCP at next begin
LwipIntfDev<RawDev>::end();
}

HardwareStatus hardwareStatus() const
{
return _hardwareStatus;
Expand Down