@@ -40,6 +40,7 @@ extern "C" void esp_yield();
40
40
ESP8266WiFiClass::ESP8266WiFiClass ()
41
41
: _useApMode(false )
42
42
, _useClientMode(false )
43
+ , _useStaticIp(false )
43
44
{
44
45
}
45
46
@@ -100,7 +101,8 @@ int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase, int32_t ch
100
101
wifi_set_channel (channel);
101
102
}
102
103
103
- wifi_station_dhcpc_start ();
104
+ if (!_useStaticIp)
105
+ wifi_station_dhcpc_start ();
104
106
return status ();
105
107
}
106
108
@@ -112,6 +114,8 @@ uint8_t ESP8266WiFiClass::waitForConnectResult(){
112
114
return status ();
113
115
}
114
116
117
+
118
+ // You will have to set the DNS-Server manually later since this will not enable DHCP
115
119
void ESP8266WiFiClass::config (IPAddress local_ip, IPAddress gateway, IPAddress subnet)
116
120
{
117
121
struct ip_info info;
@@ -121,6 +125,26 @@ void ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress s
121
125
122
126
wifi_station_dhcpc_stop ();
123
127
wifi_set_ip_info (STATION_IF, &info);
128
+
129
+ _useStaticIp = true ;
130
+ }
131
+
132
+ void ESP8266WiFiClass::config (IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns)
133
+ {
134
+ struct ip_info info;
135
+ info.ip .addr = static_cast <uint32_t >(local_ip);
136
+ info.gw .addr = static_cast <uint32_t >(gateway);
137
+ info.netmask .addr = static_cast <uint32_t >(subnet);
138
+
139
+ wifi_station_dhcpc_stop ();
140
+ wifi_set_ip_info (STATION_IF, &info);
141
+
142
+ // Set DNS-Server
143
+ ip_addr_t d;
144
+ d.addr = static_cast <uint32_t >(dns);
145
+ dns_setserver (0 ,&d);
146
+
147
+ _useStaticIp = true ;
124
148
}
125
149
126
150
int ESP8266WiFiClass::disconnect ()
0 commit comments