is it a deafult ip address 192.168.4.1 ESP32 server

buddhika
Posts: 12
Joined: Tue Sep 20, 2022 8:14 am

is it a deafult ip address 192.168.4.1 ESP32 server

Postby buddhika » Tue Apr 02, 2024 11:36 am

I have a server running on ESP32 which gives me the IP address 192.168.4.1. Is it a default IP address? Can I use this IP address in my code to access the server? What I am asking is whether the IP address remains the same for any ESP32 board.

chegewara
Posts: 2332
Joined: Wed Jun 14, 2017 9:00 pm

Re: is it a deafult ip address 192.168.4.1 ESP32 server

Postby chegewara » Tue Apr 02, 2024 1:13 pm

Yes, its default and can be configured in menuconfig IIRC.

buddhika
Posts: 12
Joined: Tue Sep 20, 2022 8:14 am

Re: is it a deafult ip address 192.168.4.1 ESP32 server

Postby buddhika » Tue Apr 02, 2024 2:11 pm

Please provide a code snippet demonstrating how to change the default IP address for the gateway for newer versions of esp idf. for example change the default gateway to 192.168.8.1. without using tcpip_adapter_init because that function is deprecated.

chegewara
Posts: 2332
Joined: Wed Jun 14, 2017 9:00 pm

Re: is it a deafult ip address 192.168.4.1 ESP32 server

Postby chegewara » Tue Apr 02, 2024 3:09 pm

I believe this function should be used
https://github.com/espressif/esp-idf/bl ... tif.h#L477

https://docs.espressif.com/projects/esp ... _ip_info_t

Code: Select all

	ESP_RETURN_ON_ERROR(esp_netif_dhcps_stop(esp_netif_ap), TAG, "failed to stop DHCP");
	ESP_RETURN_ON_ERROR(esp_netif_set_ip_info(esp_netif_ap, ip_info), TAG, "failed to setup IP");
	ESP_RETURN_ON_ERROR(esp_netif_dhcps_start(esp_netif_ap), TAG, "failed to start DHCP");

buddhika
Posts: 12
Joined: Tue Sep 20, 2022 8:14 am

Re: is it a deafult ip address 192.168.4.1 ESP32 server

Postby buddhika » Tue Apr 02, 2024 4:15 pm

Can you share the full code for setting up the AP mode? Your help is highly appreciated.

buddhika
Posts: 12
Joined: Tue Sep 20, 2022 8:14 am

Re: is it a deafult ip address 192.168.4.1 ESP32 server

Postby buddhika » Tue Apr 02, 2024 5:44 pm

I figured it out. thank you chegewara. this is the working code


// Create a new netif for the access point
esp_netif_t *esp_netif_ap = esp_netif_create_default_wifi_ap();

// Set IP address for the access point
esp_netif_ip_info_t ip_info;
IP4_ADDR(&ip_info.ip, 192, 168, 4, 1);
IP4_ADDR(&ip_info.gw, 192, 168, 4, 2); // Change the default gateway IP here
IP4_ADDR(&ip_info.netmask, 255, 255, 255, 0);


wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));

wifi_config_t wifi_config = {
.ap = {
.ssid = "myHomeEVSE",
.ssid_len = strlen("myHomeEVSE"),
.password = "ABCD123*",
.max_connection = 5,
.authmode = WIFI_AUTH_WPA_WPA2_PSK,
},
};

ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
ESP_LOGI("networkTask", "ap mode initialised");


ESP_ERROR_CHECK(esp_netif_dhcps_stop(esp_netif_ap));
ESP_ERROR_CHECK(esp_netif_set_ip_info(esp_netif_ap, &ip_info));
ESP_ERROR_CHECK(esp_netif_dhcps_start(esp_netif_ap));

Who is online

Users browsing this forum: ESP_Roland and 68 guests