change dnsName

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: change dnsName

Postby snahmad75 » Thu May 03, 2018 5:36 pm

Hi,

I tried out

esp_err_t err = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_AP, "testing");
printf("tcpip_adapter_set_hostname with err=%d\n", (int)err);

I get error. I need to set my esp32 device unique name. which can be use access my web pages on esp32 using browser.

I also tied below no error. still cannot ping using testing name

esp_err_t err = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, "testing");

class MyWiFiEventHandler: public WiFiEventHandler {
public:
esp_err_t staGotIp(system_event_sta_got_ip_t event_sta_got_ip)
{
esp_err_t err = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_AP, "testing");
printf("tcpip_adapter_set_hostname with err=%d\n", (int)err);

ACDTRACE(ES_NoError, "staGotIp\n");
main_task = new MainTask();
main_task->setStackSize(12000);
main_task->start();
return ESP_OK;
}

esp_err_t apStart()
{
ACDTRACE(ES_NoError, "apStart\n");
return ESP_OK;
}
};


void app_main(void)
{
ACCDebug_InstallCallback (ACCDebugOut_Callback, 100);

// Initialize NVS.

esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
ESP_ERROR_CHECK(nvs_flash_erase());
err = nvs_flash_init();
}
ESP_ERROR_CHECK( err );

MyWiFiEventHandler *eventHandler = new MyWiFiEventHandler();

wifi = new WiFi();
wifi->setWifiEventHandler(eventHandler);

for (int i = 10; i >= 0; i--) {
printf("Restarting in %d seconds...\n", i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}

bool is_connected = wifi->connectAP("??", "??");

ACDTRACEF(ES_NoError, "is_connected=%d second\n", (int)is_connected);

tcpip_adapter_ip_info_t ip_info = wifi->getStaIpInfo();

char* ipv4_address = ip4addr_ntoa(&ip_info.ip);

ACDTRACEF(ES_NoError, "Ipv4 address(%s)\n", ipv4_address);

while(1)
{
ACDTRACEF(ES_NoError,"is_connected=%d second\n", (int)is_connected);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: change dnsName

Postby jcsbanks » Mon Jan 14, 2019 11:43 pm

MalteJ wrote:
Fri Mar 10, 2017 2:03 pm
I think it's defined here:
https://github.com/espressif/esp-idf/bl ... nif.c#L205
https://github.com/espressif/esp-idf/bl ... nif.c#L205 now but changing this does work. No need for mDNS, works on Android, Windows without Bonjour. Might be my router doing it.

http://espressif.lan does the trick or whatever you change espressif to.

The .lan bit doesn't seem adjustable and users might mistake it for the name "Ian", but better than a DHCP IP address on Android by far if it works with most routers. Would be interesting to see if this works for others. Unlike mDNS it seems much faster, but does not work for AP, only STA.

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: change dnsName

Postby jcsbanks » Tue Jan 15, 2019 12:20 pm

preetam wrote:
Wed Mar 15, 2017 10:05 am
Thank you for the information.

I did follow an example from https://github.com/espressif/arduino-es ... v6.ino#L78

and changed the same in the event handler

Code: Select all

 switch(event->event_id) {
    case SYSTEM_EVENT_STA_START:
        ESP_ERROR_CHECK(tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, "testing"));	
        esp_wifi_connect();
Now i can ping with testing and the reply comes from the router (testing.<routername>.com). As there are no ping echo's in my code.
Also finding this works, thanks, saves changes to esp-idf/lwip. Interestingly, the name on my network is "testing.lan" - I think the relevant router module is dnsmasq used with OpenWRT.

Interested to hear what other people find about the hostname suffix on different routers.

Edit with more info: when my Android makes a hotspot, I can connect to it with a PC and do "ipconfig" from a cmd window and see that Connection specific DNS suffix is empty, whereas it is lan on my OpenWRT router. So I can access the ESP32 with http://testing. when it is connected to the Android hotspot, and http://testing.lan or whatever I change it to on the OpenWRT router n the dnsmasq settings.

Who is online

Users browsing this forum: asargent and 161 guests