Rework setHostname for WiFi STA

Fixes: https://github.com/espressif/arduino-esp32/issues/2537
This commit is contained in:
me-no-dev 2021-02-03 13:17:49 +02:00
parent 5de03a3918
commit ad4cf1461b
3 changed files with 4 additions and 1 deletions

View File

@ -379,6 +379,7 @@ esp_err_t WiFiGenericClass::_eventCallback(void *arg, system_event_t *event, wif
} else if(event->event_id == SYSTEM_EVENT_STA_START) { } else if(event->event_id == SYSTEM_EVENT_STA_START) {
WiFiSTAClass::_setStatus(WL_DISCONNECTED); WiFiSTAClass::_setStatus(WL_DISCONNECTED);
setStatusBits(STA_STARTED_BIT); setStatusBits(STA_STARTED_BIT);
tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, WiFiSTAClass::_hostname.c_str());
} else if(event->event_id == SYSTEM_EVENT_STA_STOP) { } else if(event->event_id == SYSTEM_EVENT_STA_STOP) {
WiFiSTAClass::_setStatus(WL_NO_SHIELD); WiFiSTAClass::_setStatus(WL_NO_SHIELD);
clearStatusBits(STA_STARTED_BIT | STA_CONNECTED_BIT | STA_HAS_IP_BIT | STA_HAS_IP6_BIT); clearStatusBits(STA_STARTED_BIT | STA_CONNECTED_BIT | STA_HAS_IP_BIT | STA_HAS_IP6_BIT);

View File

@ -71,6 +71,7 @@ static bool sta_config_equal(const wifi_config_t& lhs, const wifi_config_t& rhs)
bool WiFiSTAClass::_autoReconnect = true; bool WiFiSTAClass::_autoReconnect = true;
bool WiFiSTAClass::_useStaticIp = false; bool WiFiSTAClass::_useStaticIp = false;
String WiFiSTAClass::_hostname = "esp32-arduino";
static wl_status_t _sta_status = WL_NO_SHIELD; static wl_status_t _sta_status = WL_NO_SHIELD;
static EventGroupHandle_t _sta_status_group = NULL; static EventGroupHandle_t _sta_status_group = NULL;
@ -283,7 +284,6 @@ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subne
} }
tcpip_adapter_ip_info_t info; tcpip_adapter_ip_info_t info;
log_d("STA IP uint32_t: %u.%u.%u.%u\n", local_ip[0], local_ip[1], local_ip[2], local_ip[3]);
if(local_ip != (uint32_t)0x00000000 && local_ip != INADDR_NONE){ if(local_ip != (uint32_t)0x00000000 && local_ip != INADDR_NONE){
info.ip.addr = static_cast<uint32_t>(local_ip); info.ip.addr = static_cast<uint32_t>(local_ip);
@ -637,6 +637,7 @@ const char * WiFiSTAClass::getHostname()
*/ */
bool WiFiSTAClass::setHostname(const char * hostname) bool WiFiSTAClass::setHostname(const char * hostname)
{ {
_hostname = hostname;
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){ if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
return false; return false;
} }

View File

@ -86,6 +86,7 @@ public:
int8_t RSSI(); int8_t RSSI();
static void _setStatus(wl_status_t status); static void _setStatus(wl_status_t status);
static String _hostname;
protected: protected:
static bool _useStaticIp; static bool _useStaticIp;
static bool _autoReconnect; static bool _autoReconnect;