Fix setHostname API
Slightly modified version of the upstream fix to the set hostname API,
found here: f63b70aa3d
Sets the custom hostname in the system STA_START event, rather than directly. Falls back to "defaultHostname"
Allows a custom client-mode hostname to be set.
Co-authored-by: Riccardo Rizzo <r.rizzo@arduino.cc>
This commit is contained in:
@@ -44,6 +44,7 @@ WiFiClass::WiFiClass() :
|
||||
memset(&_apRecord, 0x00, sizeof(_apRecord));
|
||||
memset(&_ipInfo, 0x00, sizeof(_ipInfo));
|
||||
memset(&_dnsServers, 0x00, sizeof(_dnsServers));
|
||||
memset(&_hostname, 0x00, sizeof(_hostname));
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::status()
|
||||
@@ -320,7 +321,7 @@ void WiFiClass::setDNS(/*IPAddress*/uint32_t dns_server1, /*IPAddress*/uint32_t
|
||||
|
||||
void WiFiClass::hostname(const char* name)
|
||||
{
|
||||
tcpip_adapter_set_hostname(_interface == ESP_IF_WIFI_AP ? TCPIP_ADAPTER_IF_AP : TCPIP_ADAPTER_IF_STA, name);
|
||||
strncpy(_hostname, name, HOSTNAME_MAX_LENGTH);
|
||||
}
|
||||
|
||||
void WiFiClass::disconnect()
|
||||
@@ -604,7 +605,12 @@ void WiFiClass::handleSystemEvent(system_event_t* event)
|
||||
|
||||
esp_wifi_get_mac(ESP_IF_WIFI_STA, mac);
|
||||
sprintf(defaultHostname, "arduino-%.2x%.2x", mac[4], mac[5]);
|
||||
tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, defaultHostname);
|
||||
//tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, defaultHostname);
|
||||
if (strlen(_hostname) == 0) {
|
||||
sprintf(_hostname, "%s", defaultHostname);
|
||||
}
|
||||
tcpip_adapter_set_hostname(_interface == ESP_IF_WIFI_AP ? TCPIP_ADAPTER_IF_AP : TCPIP_ADAPTER_IF_STA, _hostname);
|
||||
|
||||
|
||||
if (tcpip_adapter_get_netif(TCPIP_ADAPTER_IF_STA, (void**)&staNetif) == ESP_OK) {
|
||||
if (staNetif->input != WiFiClass::staNetifInputHandler) {
|
||||
|
||||
@@ -44,6 +44,7 @@ typedef enum {
|
||||
} wl_status_t;
|
||||
|
||||
#define MAX_SCAN_RESULTS 10
|
||||
#define HOSTNAME_MAX_LENGTH 32
|
||||
|
||||
class WiFiClass
|
||||
{
|
||||
@@ -119,6 +120,7 @@ private:
|
||||
tcpip_adapter_ip_info_t _ipInfo;
|
||||
uint32_t _dnsServers[2];
|
||||
|
||||
char _hostname[HOSTNAME_MAX_LENGTH+1];
|
||||
netif_input_fn _staNetifInput;
|
||||
netif_input_fn _apNetifInput;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user