mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
Add function overload to config to include DNS
Disable DHCP if using static IP With dhcp disabled, I noticed about 50% less conncection time
This commit is contained in:
parent
3e04989902
commit
7daa6c6b69
@ -40,6 +40,7 @@ extern "C" void esp_yield();
|
||||
ESP8266WiFiClass::ESP8266WiFiClass()
|
||||
: _useApMode(false)
|
||||
, _useClientMode(false)
|
||||
, _useStaticIp(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -100,7 +101,8 @@ int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase, int32_t ch
|
||||
wifi_set_channel(channel);
|
||||
}
|
||||
|
||||
wifi_station_dhcpc_start();
|
||||
if(!_useStaticIp)
|
||||
wifi_station_dhcpc_start();
|
||||
return status();
|
||||
}
|
||||
|
||||
@ -112,6 +114,8 @@ uint8_t ESP8266WiFiClass::waitForConnectResult(){
|
||||
return status();
|
||||
}
|
||||
|
||||
|
||||
// You will have to set the DNS-Server manually later since this will not enable DHCP
|
||||
void ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet)
|
||||
{
|
||||
struct ip_info info;
|
||||
@ -121,6 +125,26 @@ void ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress s
|
||||
|
||||
wifi_station_dhcpc_stop();
|
||||
wifi_set_ip_info(STATION_IF, &info);
|
||||
|
||||
_useStaticIp = true;
|
||||
}
|
||||
|
||||
void ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns)
|
||||
{
|
||||
struct ip_info info;
|
||||
info.ip.addr = static_cast<uint32_t>(local_ip);
|
||||
info.gw.addr = static_cast<uint32_t>(gateway);
|
||||
info.netmask.addr = static_cast<uint32_t>(subnet);
|
||||
|
||||
wifi_station_dhcpc_stop();
|
||||
wifi_set_ip_info(STATION_IF, &info);
|
||||
|
||||
// Set DNS-Server
|
||||
ip_addr_t d;
|
||||
d.addr = static_cast<uint32_t>(dns);
|
||||
dns_setserver(0,&d);
|
||||
|
||||
_useStaticIp = true;
|
||||
}
|
||||
|
||||
int ESP8266WiFiClass::disconnect()
|
||||
|
@ -75,7 +75,6 @@ public:
|
||||
*/
|
||||
void softAP(const char* ssid, const char* passphrase, int channel = 1);
|
||||
|
||||
|
||||
/* Change Ip configuration settings disabling the dhcp client
|
||||
*
|
||||
* param local_ip: Static ip configuration
|
||||
@ -84,6 +83,15 @@ public:
|
||||
*/
|
||||
void config(IPAddress local_ip, IPAddress gateway, IPAddress subnet);
|
||||
|
||||
/* Change Ip configuration settings disabling the dhcp client
|
||||
*
|
||||
* param local_ip: Static ip configuration
|
||||
* param gateway: Static gateway configuration
|
||||
* param subnet: Static Subnet mask
|
||||
* param dns: Defined DNS
|
||||
*/
|
||||
void config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns);
|
||||
|
||||
/* Configure access point
|
||||
*
|
||||
* param local_ip: access point IP
|
||||
@ -310,7 +318,8 @@ protected:
|
||||
|
||||
bool _useApMode;
|
||||
bool _useClientMode;
|
||||
|
||||
bool _useStaticIp;
|
||||
|
||||
static size_t _scanCount;
|
||||
static void* _scanResult;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user