diff --git a/cores/esp8266/LwipIntfDev.h b/cores/esp8266/LwipIntfDev.h index 94e3e71c63..610c9d7249 100644 --- a/cores/esp8266/LwipIntfDev.h +++ b/cores/esp8266/LwipIntfDev.h @@ -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(); @@ -209,6 +214,24 @@ boolean LwipIntfDev::config(const IPAddress& localIP, const IPAddress& g return true; } +template +boolean LwipIntfDev::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 boolean LwipIntfDev::begin(const uint8_t* macAddress, const uint16_t mtu) { @@ -336,9 +359,6 @@ template void LwipIntfDev::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(); } diff --git a/libraries/lwIP_Ethernet/src/EthernetCompat.h b/libraries/lwIP_Ethernet/src/EthernetCompat.h index 2d635e750c..ee8d1fadc2 100644 --- a/libraries/lwIP_Ethernet/src/EthernetCompat.h +++ b/libraries/lwIP_Ethernet/src/EthernetCompat.h @@ -86,6 +86,13 @@ class ArduinoEthernet: public LwipIntfDev return ret; } + void end() + { + ip_addr_copy(LwipIntfDev::_netif.ip_addr, + ip_addr_any); // to allow DHCP at next begin + LwipIntfDev::end(); + } + HardwareStatus hardwareStatus() const { return _hardwareStatus;