Set gateway IP address (AP mode)

arao23
Posts: 30
Joined: Tue Dec 13, 2016 4:44 pm

Set gateway IP address (AP mode)

Postby arao23 » Wed Dec 21, 2016 6:30 pm

Hey, I'm trying to set the gateway IP, and after scouring the forums and docs, this is what I came up with, but for some reason DHCP is still active and sets the gw IP to 192.168.4.1 instead of 192.168.1.1. Any ideas? Thanks! :)

Code: Select all

	tcpip_adapter_init();

	tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_AP);

	tcpip_adapter_ip_info_t ipInfo;
	IP4_ADDR(&ipInfo.ip, 192,168,1,99);
	IP4_ADDR(&ipInfo.gw, 192,168,1,1);
	IP4_ADDR(&ipInfo.netmask, 255,255,255,0);
	tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &ipInfo);

	ESP_ERROR_CHECK( esp_event_loop_init(wifi_event_handler, NULL) );

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

	ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
	ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_AP) );

	wifi_config_t apConfig = {
			.ap = {
					.ssid="TestController",
					.password=WIFI_PASS,
					.ssid_len = 0,
					.channel = 0,
					.authmode = WIFI_AUTH_OPEN,
					.ssid_hidden = 0,
					.max_connection=4,
					.beacon_interval = 100
			}
	};

	ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_AP, &apConfig) );
	ESP_ERROR_CHECK( esp_wifi_start() );

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Set gateway IP address (AP mode)

Postby kolban » Wed Dec 21, 2016 9:46 pm

In your code fragment, your are switching off the DHCP client code ... i.e. tcpip_adapter_dhcpc_stop(). In that API, "dhcpc" is DHCP Client. You might need to switch off the DHCP server code ... i.e. tcpip_adapter_dhcps_stop(). This will prevent any connecting stations negotiating as DHCP clients.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

arao23
Posts: 30
Joined: Tue Dec 13, 2016 4:44 pm

Re: Set gateway IP address (AP mode)

Postby arao23 » Mon Dec 26, 2016 5:46 pm

Hi kolban, thanks for your reply, hope you had a wonderful holiday. I'm trying to set the gateway's IP to 192.168.1.1, as it currently assigns some arbitrary value 192.168.4.1. Essentially, I want all connected clients to be able to send messages to the ESP32, hence I need the ESP32 to have a "static" IP address so it can act as a server.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Set gateway IP address (AP mode)

Postby kolban » Mon Dec 26, 2016 5:54 pm

No problems ... see the following post and let's follow up there is something isn't crystal clear.

http://esp32.com/viewtopic.php?f=18&t=4 ... =static+ip
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

arao23
Posts: 30
Joined: Tue Dec 13, 2016 4:44 pm

Re: Set gateway IP address (AP mode)

Postby arao23 » Tue Dec 27, 2016 4:53 pm

Awesome, thanks. Looks like it sets a static IP for the ESP32 when it is in station mode, did I get that right? I wanted to give clients a "static" IP address (gateway IP) to the ESP32 when other clients connect to it. What I did for now is let the ESP32 give itself whatever gateway IP it wants, and then from the client program, I got the gateway IP dynamically. Seems to be working good. Thanks again!

preetam
Posts: 49
Joined: Thu Jan 26, 2017 2:31 pm
Location: Germany

Re: Set gateway IP address (AP mode)

Postby preetam » Wed Feb 15, 2017 11:42 am

Hi,

Can we set the hostname using mdns API and other clients resolve it and connect ?

Thanks
Paul

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Set gateway IP address (AP mode)

Postby kolban » Thu Feb 16, 2017 4:25 am

Howdy Paul,
You might want to follow on in this thread:

https://esp32.com/viewtopic.php?f=13&t=986&p=5147

The mDNS technology isn't about setting the hostname of your ESP32 but rather it is about other clients finding your ESP32 using the mDNS technology. At a high level, as I understand it, when a client application wishes to know what devices are "out there" it broadcasts using UDP. Any host that wishes to advertize itself (eg. your ESP32) responds with an mDNS response. The result is that clients can determine who/what is out there to be connected to. The mDNS response contains information about the device that is advertizing itself such as text identity (a name) and an IP address (how to connect to it).
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

preetam
Posts: 49
Joined: Thu Jan 26, 2017 2:31 pm
Location: Germany

Re: Set gateway IP address (AP mode)

Postby preetam » Tue Feb 21, 2017 11:26 am

Hi Kolban,

Thank you for the info.
As an experiment i tried to setup 2 ESP32 using mdns.
I set up the mdns hostname (without any services) in one esp32 and resolved the hostname (obtained Ip address) on the second esp32.

Thank you
Paul

Who is online

Users browsing this forum: bushpulbek and 124 guests