Fail to connect to wifi with esp32

I am trying to wright a code to connect my esp32 to a wifi station,
But it dont seam to work since it gives back the “failed to connect error” and i dont see it in my dhcp range on my access point

Here is my code :

#include <stdio.h>
#include <esp_wifi.h>
#include <esp_log.h>
#include <esp_system.h>
#include <nvs_flash.h> // to flash the memory (Non volatile sorage = NVS)
#include <string.h>
#include <esp_check.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#define WIFI_FAILURE 1<<1
#define WIFI_SUCCESS 1<<0

#define TAG "Wifi :"


static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data){

    // wifi station start event 
    if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START){
        ESP_LOGI(TAG, "connectiong to AP ....");
        esp_wifi_connect();
        // event trigerred when the wifi sta start
        // esp_wifi_connect is use to initialise the wifi connexion
    }
    // wifi station disconnect event 
    else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED){
        for (int i=0; i < 10; i++){
            esp_wifi_connect();
            ESP_LOGI(TAG, "connecting to AP .....");
        }
        ESP_LOGI(TAG, "failed to connect");
        // trigerred when the esp is disconnected from the esp
        // here esp_wifi_connect is used to reconnect and maintain a stable connexion
    }



}

static void ip_event_handler(void* asrg, esp_event_base_t event_base, int32_t event_id, void* event_data){

    // IP got event 
     if (event_base == WIFI_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
        ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
        ESP_LOGI("WIFI_EVENT", "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
        // is trigerred when the esp get an ip via DHCP
        // the ip adresse is extracted from event data by using ESP_LOGI, it make sur that the esp has obtain an ip adress
    }

}

esp_err_t conf_wifi (){
    // initialise the networking interface
    ESP_ERROR_CHECK(esp_netif_init());
    ESP_ERROR_CHECK(esp_event_loop_create_default()); // create the event that will be used by wifi to handle the events
    // create wifi sta in the wifi drivre
    esp_netif_create_default_wifi_sta();
    // define the wifi conf with default conf 
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();

    //initialise the wifi module with the conf that we defined before
    ESP_ERROR_CHECK(esp_wifi_init(&cfg));
    

    

        // event handler register, it save it in the event handler from esp-idf and link them to the spesified callback func
        esp_event_handler_instance_t wifi_handler_event_instance;
        ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
                                                            ESP_EVENT_ANY_ID,
                                                            &wifi_event_handler,
                                                            NULL,
                                                            &wifi_handler_event_instance)); // save every WIFI_EVENT in event_handler, event_handler will be called for each wifi event
                                                                                           
        esp_event_handler_instance_t got_ip_event_instance;
        ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
                                                            IP_EVENT_STA_GOT_IP,
                                                            &ip_event_handler,
                                                            NULL,
                                                            &got_ip_event_instance));// save every IP_EVENT in event handler, call for ip event 


    // define and set the wifi conf

    wifi_config_t wifi_config_sta = {
        // use to connect to a station
        .sta ={
            .ssid = "",
        .password = "",
        .threshold.authmode = WIFI_AUTH_WPA2_PSK,
            .pmf_cfg = {
                .capable = true,
                .required = false
            },

        },
    };


    //define the wifi mod
    ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
    // set sta conf
    ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config_sta));

    // set ap conf (for later)

    // start wifi
    ESP_ERROR_CHECK(esp_wifi_start());
    
    ESP_LOGI(TAG, "STA conf initialized");

    return WIFI_SUCCESS;
}


void app_main(void) {
    // initialise nvs 
    esp_err_t ret = nvs_flash_init(); // is use to check if an error occure and then init the nvs flash
    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();
            // if the nvs is not blank erase what is written in it 
            }
    ESP_ERROR_CHECK(ret);
    

    // check if something is going wronge while connecting to the ap
    esp_err_t wifi_status = WIFI_FAILURE;

    wifi_status = conf_wifi();
    if (WIFI_SUCCESS != wifi_status){
        ESP_LOGI("WIFI ", "Failed to connect to the sta, dying ....");
        return;

    } else printf("Error 1");

}

i changed a lot the code since the first writting and separed the wifi_event_handler from the ip_event_handler

I am looking for help on understanding what is wrong with what i did and being able to fix it to understand how wifi work with the esp-idf API and going forward in my project

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật