Change ESP32 softAP default IP address

fbautista
Posts: 3
Joined: Tue Dec 03, 2019 11:27 pm

Change ESP32 softAP default IP address

Postby fbautista » Tue Dec 03, 2019 11:38 pm

Hi,

I am new to esp32 development. Just wondering if there is a function i can use to change the default gateway ip (192.168.4.1) of the ESP32 softAP mode to something else? I only see a way to do this from the Arduino Wifi.h library, i.e. Wifi.softAPConfig(). Is there a native esp-idf function that I can use?

Thanks

ESP_Sprite
Posts: 2908
Joined: Thu Nov 26, 2015 4:08 am

Re: Change ESP32 softAP default IP address

Postby ESP_Sprite » Wed Dec 04, 2019 2:57 am

In general, ESP32 Arduino builds on esp-idf, so everything you can do in Arduino, you can somehow do in esp-idf.

In this case, I think you can set the IP with tcpip_adapter_set_ip_info. You probably want to do this before bringing up the SoftAP.

DssaTech
Posts: 1
Joined: Thu Oct 31, 2019 4:04 am

Re: Change ESP32 softAP default IP address

Postby DssaTech » Wed Dec 04, 2019 5:07 am

I am also looking for a solution to this problem.
I have tried WiFi.softAPConfig() but could not make it work.
I have tried the tcpip_adapter_set_ip_info() function, it compiles but I get Runtime errors like :-
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
=======================================
------ Version : CGMESP_191205
---------------------------------------
+++++ Enabling WIFI Access Point +++++
E (3065) tcpip_adapter: tcpip_adapter is not initialized!
abort() was called at PC 0x40103a97 on core 1

Backtrace: 0x40091f40:0x3ffcdd30 0x40092171:0x3ffcdd50 0x40103a97:0x3ffcdd70 0x400d17cd:0x3ffcddb0 0x400d961b:0x3ffcdf40 0x4008e689:0x3ffcdf60

Rebooting...
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Is it just me or is the esp-idf not well explained ?

fbautista
Posts: 3
Joined: Tue Dec 03, 2019 11:27 pm

Re: Change ESP32 softAP default IP address

Postby fbautista » Wed Dec 04, 2019 8:06 pm

ESP_Sprite wrote:
Wed Dec 04, 2019 2:57 am
In general, ESP32 Arduino builds on esp-idf, so everything you can do in Arduino, you can somehow do in esp-idf.

In this case, I think you can set the IP with tcpip_adapter_set_ip_info. You probably want to do this before bringing up the SoftAP.
Thank you sir. I got it working using esp_netif_set_ip_info().

Code: Select all

    esp_netif_init();
    ESP_ERROR_CHECK(esp_event_loop_create_default());
    esp_netif_t* wifiAP = esp_netif_create_default_wifi_ap();
    esp_netif_ip_info_t ip_info;
    esp_netif_ip_info_t ipInfo;
    IP4_ADDR(&ipInfo.ip, 192,168,2,1);
	IP4_ADDR(&ipInfo.gw, 192,168,2,1);
	IP4_ADDR(&ipInfo.netmask, 255,255,255,0);
	esp_netif_dhcps_stop(wifiAP);
	esp_netif_set_ip_info(wifiAP, &ipInfo);
	esp_netif_dhcps_start(wifiAP);


    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 = EXAMPLE_ESP_WIFI_SSID,
            .ssid_len = strlen(EXAMPLE_ESP_WIFI_SSID),
            .password = EXAMPLE_ESP_WIFI_PASS,
            .max_connection = EXAMPLE_MAX_STA_CONN,
            .authmode = WIFI_AUTH_WPA_WPA2_PSK
        },
    };
    if (strlen(EXAMPLE_ESP_WIFI_PASS) == 0) {
        wifi_config.ap.authmode = WIFI_AUTH_OPEN;
    }

    ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
    ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_config));
    ESP_ERROR_CHECK(esp_wifi_start());

Who is online

Users browsing this forum: Bing [Bot] and 13 guests