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);
}
}
change dnsName
Re: change dnsName
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.MalteJ wrote: ↑Fri Mar 10, 2017 2:03 pmI think it's defined here:
https://github.com/espressif/esp-idf/bl ... nif.c#L205
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.
Re: change dnsName
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.preetam wrote: ↑Wed Mar 15, 2017 10:05 amThank 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
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.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();
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: MicroController and 134 guests