Page 1 of 1

WiFi gateway fixed IP as an alternative mDNS

Posted: Tue Jan 01, 2019 8:18 pm
by brp80000
My device includes a softAP access point and raises a web server on it.
Tried to start mDNS. Understand that this is not workable on most devices without any additional manipulation, such as setting them Bounjour and Avahi, etc. But what about when you connect your device with Android in General is not clear.
Can I set a fixed IP address when configuring softAP and then inform users to access it?
Is there any other way for fixed access to the web server?
:shock:

Re: WiFi gateway fixed IP as an alternative mDNS

Posted: Fri Jan 04, 2019 2:32 pm
by chrismerck
I don't know of a convenient way to configure the softAP IP, but you can change the gateway address by modifying the IDF code:

Code: Select all

diff --git a/components/tcpip_adapter/tcpip_adapter_lwip.c b/components/tcpip_adapter/tcpip_adapter_lwip.c
index 8198cb344..d5ed71073 100644
--- a/components/tcpip_adapter/tcpip_adapter_lwip.c
+++ b/components/tcpip_adapter/tcpip_adapter_lwip.c
@@ -106,8 +106,8 @@ void tcpip_adapter_init(void)
         memset(esp_ip, 0, sizeof(tcpip_adapter_ip_info_t)*TCPIP_ADAPTER_IF_MAX);
         memset(esp_ip_old, 0, sizeof(tcpip_adapter_ip_info_t)*TCPIP_ADAPTER_IF_MAX);

-        IP4_ADDR(&esp_ip[TCPIP_ADAPTER_IF_AP].ip, 192, 168 , 4, 1);
-        IP4_ADDR(&esp_ip[TCPIP_ADAPTER_IF_AP].gw, 192, 168 , 4, 1);
+        IP4_ADDR(&esp_ip[TCPIP_ADAPTER_IF_AP].ip, 10, 7, 42, 1);
+        IP4_ADDR(&esp_ip[TCPIP_ADAPTER_IF_AP].gw, 10, 7, 42, 1);
         IP4_ADDR(&esp_ip[TCPIP_ADAPTER_IF_AP].netmask, 255, 255 , 255, 0);
         ret = sys_sem_new(&api_sync_sem, 0);
         if (ERR_OK != ret) {
As for how to inform the client... perhaps you can just hard-code the IP in the client? Or you can have the client check the gateway address, and assume that the ESP32 is the gateway.

Re: WiFi gateway fixed IP as an alternative mDNS

Posted: Fri Jan 04, 2019 9:26 pm
by brp80000
How can I always fix the IP address of the soft AP 192.168.4.1 (gateway address)?
Or it doesn't depend on me and it will always be 192.168.4.1?

Re: WiFi gateway fixed IP as an alternative mDNS

Posted: Sat Jan 05, 2019 9:21 am
by ESP_igrr
softAP address can be set using tcpip_adapter_set_ip_info function: https://docs.espressif.com/projects/esp ... _ip_info_t

Re: WiFi gateway fixed IP as an alternative mDNS

Posted: Sat Jan 05, 2019 11:45 am
by brp80000
OK its work
  • tcpip_adapter_init();
    ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
    ESP_ERROR_CHECK(tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP));

    tcpip_adapter_ip_info_t ip_info;
    memset(&ip_info, 0, sizeof(ip_info));
    IP4_ADDR(&(ip_info.ip), 192,168,5,1);
    IP4_ADDR(&(ip_info.gw), 192,168,5,1);
    IP4_ADDR(&(ip_info.netmask), 255,255,255,0);
    ESP_ERROR_CHECK(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &ip_info));
    ESP_ERROR_CHECK(tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_AP));

    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK(esp_wifi_init(&cfg));