From 195fdc17d3db303c9ab6ce6cb35c9dedda29374d Mon Sep 17 00:00:00 2001 From: Michal Paszta Date: Tue, 31 Mar 2020 21:56:32 +0300 Subject: [PATCH] ESP8266: initialize ESP before setting DHCP or static IP address --- components/wifi/esp8266-driver/ESP8266Interface.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/components/wifi/esp8266-driver/ESP8266Interface.cpp b/components/wifi/esp8266-driver/ESP8266Interface.cpp index bb6d1f9e5e..2cd7d14716 100644 --- a/components/wifi/esp8266-driver/ESP8266Interface.cpp +++ b/components/wifi/esp8266-driver/ESP8266Interface.cpp @@ -409,6 +409,11 @@ int ESP8266Interface::set_channel(uint8_t channel) nsapi_error_t ESP8266Interface::set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway) { + nsapi_error_t init_result = _init(); + if (NSAPI_ERROR_OK != init_result) { + return init_result; + } + // netmask and gateway switched on purpose. ESP takes different argument order. if (_esp.set_ip_addr(ip_address.get_ip_address(), gateway.get_ip_address(), netmask.get_ip_address())) { _dhcp = false; @@ -420,6 +425,11 @@ nsapi_error_t ESP8266Interface::set_network(const SocketAddress &ip_address, con nsapi_error_t ESP8266Interface::set_dhcp(bool dhcp) { + nsapi_error_t init_result = _init(); + if (NSAPI_ERROR_OK != init_result) { + return init_result; + } + _dhcp = dhcp; if (_esp.dhcp(dhcp, 1)) { return NSAPI_ERROR_OK;