What error did you get?
Did you use a string literal as in my snippet, or the NVS-loaded value? If the latter are you sure it's valid?
Did you remove tcpip_adapter_set_hostname from the event handler?
Code: Select all
esp_err_t Wifi::setHostname()
{
string s;
esp_err_t err;
char hostname[32] = { NULL_CHAR }; // can't find a macro for this length in a header file.
char *p = hostname;
do
{
s = m_tasks->flash->get(NVS_KEY_DEVICE_NAME);
strcpy(p, s.c_str());
ESP_LOGI(TAG, "setHostname(): setting hostname to \"%s\".", p);
if ((err = esp_netif_set_hostname(m_netif, p)) != ESP_OK)
{
ESP_LOGE(TAG, "setHostname(): set_hostname() returned %s.",
esp_err_to_name(err));
continue;
}
memset(hostname, NULL_CHAR, 32);
err = esp_netif_get_hostname(m_netif, const_cast<const char **>(&p));
if (err == ESP_OK)
{
ESP_LOGI(TAG, "setHostname(): get_hostname returned \"%s\".", hostname);
}
else
{
ESP_LOGE(TAG, "setHostname(): get_hostname returned %s.",
esp_err_to_name(err));
}
}
while (false);
return err;
}
Code: Select all
I (6472) Wifi: setHostname(): setting hostname to "WiFi Button".
I (6472) Wifi: setHostname(): get_hostname returned "".
Code: Select all
ESP_LOGI(TAG, "setHostname(): get_hostname returned \"%s\".", p);
Code: Select all
I (7839) Wifi: setHostname(): setting hostname to "WiFi Button".
I (7839) Wifi: setHostname(): get_hostname returned "WiFi Button".
Users browsing this forum: Google [Bot] and 108 guests