Skip to content

Commit 195fdc1

Browse files
ESP8266: initialize ESP before setting DHCP or static IP address
1 parent 9f347c5 commit 195fdc1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

components/wifi/esp8266-driver/ESP8266Interface.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ int ESP8266Interface::set_channel(uint8_t channel)
409409

410410
nsapi_error_t ESP8266Interface::set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway)
411411
{
412+
nsapi_error_t init_result = _init();
413+
if (NSAPI_ERROR_OK != init_result) {
414+
return init_result;
415+
}
416+
412417
// netmask and gateway switched on purpose. ESP takes different argument order.
413418
if (_esp.set_ip_addr(ip_address.get_ip_address(), gateway.get_ip_address(), netmask.get_ip_address())) {
414419
_dhcp = false;
@@ -420,6 +425,11 @@ nsapi_error_t ESP8266Interface::set_network(const SocketAddress &ip_address, con
420425

421426
nsapi_error_t ESP8266Interface::set_dhcp(bool dhcp)
422427
{
428+
nsapi_error_t init_result = _init();
429+
if (NSAPI_ERROR_OK != init_result) {
430+
return init_result;
431+
}
432+
423433
_dhcp = dhcp;
424434
if (_esp.dhcp(dhcp, 1)) {
425435
return NSAPI_ERROR_OK;

0 commit comments

Comments
 (0)