mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
Add compatibility check for ::config() method with arduino arg order (#3860)
This commit is contained in:
@ -195,6 +195,14 @@ wl_status_t ESP8266WiFiSTAClass::begin() {
|
||||
return status();
|
||||
}
|
||||
|
||||
static void
|
||||
swap(IPAddress &lhs, IPAddress &rhs)
|
||||
{
|
||||
IPAddress tmp = lhs;
|
||||
lhs = rhs;
|
||||
rhs = tmp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change IP configuration settings disabling the dhcp client
|
||||
@ -210,6 +218,22 @@ bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddres
|
||||
return false;
|
||||
}
|
||||
|
||||
//Arduino has a different arg order: ip, dns, gateway, subnet. To allow compatibility, check first octet of 3rd arg. If 255, interpret as ESP order, otherwise Arduino order.
|
||||
if(subnet[0] != 255)
|
||||
{
|
||||
//octet is not 255 => interpret as Arduino order
|
||||
|
||||
if(dns1[0] == 0)
|
||||
{
|
||||
//arg order is arduino and 4th arg not given => assign it arduino default
|
||||
dns1 = IPAddress(255,255,255,0);
|
||||
}
|
||||
|
||||
//current order is arduino: ip-dns-gway-subnet
|
||||
swap(gateway, subnet); //after this, order is ip-gway-dns-subnet
|
||||
swap(subnet, dns1); //after this, order is ip-gway-subnet-dns (correct ESP order)
|
||||
}
|
||||
|
||||
struct ip_info info;
|
||||
info.ip.addr = static_cast<uint32_t>(local_ip);
|
||||
info.gw.addr = static_cast<uint32_t>(gateway);
|
||||
|
Reference in New Issue
Block a user