tcpip_adapter_set_hostname() not working

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

tcpip_adapter_set_hostname() not working

Postby mzimmers » Mon Oct 19, 2020 8:53 pm

Hi, all -

I've looked at other posts on this topic; it seems like I'm doing it correctly, but I'm getting the error:
E (7312) Wifi: event_handler(): tcpip_adapter_set_hostname() returned ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY.
This code is in my WiFi event handler:

Code: Select all

    if (l_event_base == WIFI_EVENT)
    {
        switch(l_event_id)
        {
        case WIFI_EVENT_STA_START:
            // step 3.3 in https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/wifi.html
            ESP_LOGI(TAG, "event_handler(): Wifi started at %s.", currentTime.c_str());
            tasks->wifi->setCommsState(WIFI_STATE_STARTED);

            // 2020 10 12 mzimmers: set the hostname after a start. TODO: get this working.
            s = tasks->flash->get(NVS_KEY_DEVICE_NAME);
            if ((err = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, s.c_str())) != ESP_OK)
            {
                ESP_LOGE(TAG, "event_handler(): tcpip_adapter_set_hostname() returned %s.",
                         esp_err_to_name(err));
            }
Can someone see what I'm doing wrong? Thanks. Oh: v4.0.1 of the IDF; running on a ROVER.

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: tcpip_adapter_set_hostname() not working

Postby mzimmers » Wed Oct 21, 2020 4:06 pm

BTT...anyone? Thanks.

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: tcpip_adapter_set_hostname() not working

Postby mzimmers » Fri Oct 30, 2020 7:22 pm

Migrated to v4.1. Still doesn't work.

boarchuz
Posts: 559
Joined: Tue Aug 21, 2018 5:28 am

Re: tcpip_adapter_set_hostname() not working

Postby boarchuz » Sat Oct 31, 2020 2:21 am

Is your TCPIP initialisation done before esp_wifi_start()?

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: tcpip_adapter_set_hostname() not working

Postby mzimmers » Sat Oct 31, 2020 2:48 am

Hi boarchuz -

(EDITED to avoid confustion)

Yes, it is. Here's the excerpts from my initialization:

Code: Select all

    ESP_ERROR_CHECK(esp_netif_init());       // used in 4.1.
    ESP_ERROR_CHECK(esp_event_loop_create_default()); // v4.0.
    ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, m_tasks));
    ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &event_handler, m_tasks));
    m_netif = esp_netif_create_default_wifi_sta();
    err = esp_wifi_init(&wifiInitConfig);
    esp_netif_attach_wifi_station(m_netif);
    esp_wifi_set_default_wifi_sta_handlers();
    ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
    err = esp_wifi_start();
Where in this sequence should I call esp_netif_set_hostname()?

Thanks.
Last edited by mzimmers on Tue Nov 03, 2020 2:40 pm, edited 1 time in total.

boarchuz
Posts: 559
Joined: Tue Aug 21, 2018 5:28 am

Re: tcpip_adapter_set_hostname() not working

Postby boarchuz » Sat Oct 31, 2020 4:53 am

Code: Select all

m_netif = esp_netif_create_default_wifi_sta();
esp_netif_set_hostname(m_netif, "MyHostname");
You might run into issues if you mix'n'match the tcpip and new netif apis, I'm not sure that's supported.

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: tcpip_adapter_set_hostname() not working

Postby mzimmers » Sat Oct 31, 2020 1:34 pm

boarchuz wrote:
Sat Oct 31, 2020 4:53 am
You might run into issues if you mix'n'match the tcpip and new netif apis, I'm not sure that's supported.
I assume you're referring to the line with tcpip_adapter_init() -- I shouldn't have included that in my snippet; it's currently not being compiled in. Was there anything else you saw that looked like a mix-and-match?

Thanks...

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: tcpip_adapter_set_hostname() not working

Postby mzimmers » Mon Nov 02, 2020 10:47 pm

Still not working -- any other ideas?

ESP_cermak
Posts: 69
Joined: Thu Nov 01, 2018 8:32 am

Re: tcpip_adapter_set_hostname() not working

Postby ESP_cermak » Tue Nov 03, 2020 7:37 am

Hi mzimmers,

which IDF version are you using? Is it possible to switch to v4.1 and later? Do you have to use the *tcpip_adapter* API?

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: tcpip_adapter_set_hostname() not working

Postby mzimmers » Tue Nov 03, 2020 2:42 pm

Hi cermak - I am indeed using v4.1. And, that line using tcpip_adapter was actually commented out, and not called. (I've removed it from my earlier post to avoid further confusion.)

Who is online

Users browsing this forum: Baidu [Spider] and 117 guests