I am try to create a mini wifi repeater using ESP32 but I kept getting error trying to build it

1 day ago 6
ARTICLE AD BOX

I am new here, or should I say I have no idea about this HCI(Human Computer Interaction).

I am new But I wanna just create a mini router repeater/extender that:

-Lets a device connect to ESP32 hotspot
-Allow ESP32 to be a middleman between device and wifi

I know a little about programming(im an it student) but I didn't dig too deep in it. I have made ChatGPT write me a code for the ESP32 to do this.
The problem is;
-Arduino IDE doesn't support NAT(Network Address Translation). -ChatGPT
-ESP-IDF always sends me errors that confuses ChatGPT.
-I don't understand it so I can't debug it myself.
I will paste the codes that ChatGPT wrote below:

C:\Espressif\frameworks\esp-idf-v5.5.1\examples\get-started\wifi_hotspot\main\wifi_hotspot.c:

#include <string.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_wifi.h" #include "esp_event.h" #include "esp_log.h" #include "esp_netif.h" #include "nvs_flash.h" #include "esp_netif_nat.h" #define AP_SSID "ESP32_Hotspot" #define AP_PASSWORD "1111" // empty for open hotspot #define AP_MAX_CONN 4 #define STA_SSID "eren nova" #define STA_PASSWORD "12453wtewd" //please note that this information is edited to not match the real one I put in the real code #define STATUS_LED_PIN 2 // Built-in LED (change if your board differs) static const char *TAG = "wifi_ap_sta_nat_led"; static void wifi_init(void) { ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_event_loop_create_default()); esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta(); esp_netif_t *ap_netif = esp_netif_create_default_wifi_ap(); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); wifi_config_t sta_config = { .sta = { .ssid = STA_SSID, .password = STA_PASSWORD, .threshold.authmode = WIFI_AUTH_WPA2_PSK, }, }; wifi_config_t ap_config = { .ap = { .ssid = AP_SSID, .ssid_len = strlen(AP_SSID), .channel = 1, .password = AP_PASSWORD, .max_connection = AP_MAX_CONN, .authmode = WIFI_AUTH_OPEN }, }; ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA)); ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &sta_config)); ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &ap_config)); ESP_ERROR_CHECK(esp_wifi_start()); ESP_LOGI(TAG, "AP+STA initialized: AP SSID:%s | STA SSID:%s", AP_SSID, STA_SSID); esp_netif_nat_enable(sta_netif, ap_netif); ESP_LOGI(TAG, "NAT enabled: devices on AP will have internet through STA"); } void led_task(void *pvParameter) { gpio_reset_pin(STATUS_LED_PIN); gpio_set_direction(STATUS_LED_PIN, GPIO_MODE_OUTPUT); while (1) { wifi_sta_list_t sta_list; esp_err_t err = esp_wifi_ap_get_sta_list(&sta_list); if (err != ESP_OK) { vTaskDelay(pdMS_TO_TICKS(500)); continue; } int num_devices = sta_list.num; if (num_devices == 0) { // No devices: LED ON gpio_set_level(STATUS_LED_PIN, 1); vTaskDelay(pdMS_TO_TICKS(500)); } else { // Blink pattern based on connected devices for (int i = 0; i < num_devices && i < 4; i++) { // max 4 blinks gpio_set_level(STATUS_LED_PIN, 1); vTaskDelay(pdMS_TO_TICKS(100)); gpio_set_level(STATUS_LED_PIN, 0); vTaskDelay(pdMS_TO_TICKS(100)); } // Long pause after the blink sequence vTaskDelay(pdMS_TO_TICKS(3000)); } } } void app_main(void) { esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { ESP_ERROR_CHECK(nvs_flash_erase()); ret = nvs_flash_init(); } ESP_ERROR_CHECK(ret); wifi_init(); xTaskCreate(&led_task, "led_task", 2048, NULL, 5, NULL); while (1) { vTaskDelay(pdMS_TO_TICKS(1000)); } }

C:\Espressif\frameworks\esp-idf-v5.5.1\examples\get-started\wifi_hotspot\main\CMakeList.txt:

idf_component_register( SRCS "wifi_hotspot.c" INCLUDE_DIRS "." REQUIRES esp_wifi esp_netif nvs_flash )

C:\Espressif\frameworks\esp-idf-v5.5.1\examples\get-started\wifi_hotspot\CMakeList.txt:

cmake_minimum_required(VERSION 3.16) include($ENV{IDF_PATH}/tools/cmake/project.cmake) # Minimal build to speed things up idf_build_set_property(MINIMAL_BUILD OFF) project(wifi_hotspot)

There are a lot of error after running

C:\Espressif\frameworks\esp-idf-v5.5.1\examples\get-started\wifi_hotspot>idf.py build

that is where I am having trouble.

Hope anyone can help me with this.
I also hope that no one would be disappointed if I don't understand instructions.

Read Entire Article