how to config my own ip address during accesspoint mode

davidItaly
Posts: 3
Joined: Wed Apr 24, 2024 4:22 pm

how to config my own ip address during accesspoint mode

Postby davidItaly » Wed Apr 24, 2024 5:56 pm

wifi_driver.set_configuration(&wifiConfiguration::AccessPoint(AccessPointConfiguration{
ssid: nome_wifi,//"mySSID".into(),
password: pass_wifi,//"myPASSWORD".into(),
auth_method: AuthMethod::WPA,
..Default::default()
})).unwrap();

my code works well but the ip address to access the wifi esp32 is the one chooses from board, i want to set my own
what i'm wondering is how to set my ip address 192.168.1.1 when i program my board esp32 i tyed with routerconfig bu not work.

mikemoy
Posts: 627
Joined: Fri Jan 12, 2018 9:10 pm

Re: how to config my own ip address during accesspoint mode

Postby mikemoy » Thu Apr 25, 2024 9:24 pm

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

// Configure a static IP for the AP interface
esp_netif_ip_info_t ip_info;
IP4_ADDR(&ip_info.ip, 192, 168, 1, 1); // IP address
IP4_ADDR(&ip_info.gw, 192, 168, 1, 1); // Gateway address
IP4_ADDR(&ip_info.netmask, 255, 255, 255, 0); // Netmask
esp_netif_t* netif = esp_netif_get_handle_from_ifkey("WIFI_AP_DEF");
ESP_ERROR_CHECK(esp_netif_dhcps_stop(netif)); // Stop DHCP server
ESP_ERROR_CHECK(esp_netif_set_ip_info(netif, &ip_info));
ESP_ERROR_CHECK(esp_netif_dhcps_start(netif)); // Start DHCP server

davidItaly
Posts: 3
Joined: Wed Apr 24, 2024 4:22 pm

Re: how to config my own ip address during accesspoint mode

Postby davidItaly » Fri Apr 26, 2024 11:43 am

thanks mikemoy , your code put me on right way, i adapt your code on rist with unsafe and everything works well, a problem that i face was a loop when wifi connected, connect , leave, connect,leave and so on. I fix this with erase nvs partition.

Who is online

Users browsing this forum: No registered users and 11 guests