WiFi gateway fixed IP as an alternative mDNS

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

WiFi gateway fixed IP as an alternative mDNS

Postby brp80000 » Tue Jan 01, 2019 8:18 pm

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:

chrismerck
Posts: 76
Joined: Tue May 29, 2018 8:00 pm

Re: WiFi gateway fixed IP as an alternative mDNS

Postby chrismerck » Fri Jan 04, 2019 2:32 pm

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.

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Re: WiFi gateway fixed IP as an alternative mDNS

Postby brp80000 » Fri Jan 04, 2019 9:26 pm

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?

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: WiFi gateway fixed IP as an alternative mDNS

Postby ESP_igrr » Sat Jan 05, 2019 9:21 am

softAP address can be set using tcpip_adapter_set_ip_info function: https://docs.espressif.com/projects/esp ... _ip_info_t

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Re: WiFi gateway fixed IP as an alternative mDNS

Postby brp80000 » Sat Jan 05, 2019 11:45 am

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));

Who is online

Users browsing this forum: Google [Bot] and 79 guests