Unverified Commit abd35477 authored by Juraj Andrássy's avatar Juraj Andrássy Committed by GitHub

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

parent 9181ec05
......@@ -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
......@@ -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
......@@ -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
......
......@@ -61,9 +61,14 @@ public:
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);
......@@ -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;
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) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment