Use IDF new event

This commit is contained in:
liu zhifu 2019-08-08 09:58:26 +08:00
parent df622304c8
commit 477307ee18
1 changed files with 26 additions and 0 deletions

View File

@ -2,20 +2,46 @@
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#if ESP_IDF_VERSION_MAJOR < 4
#include "esp_event_loop.h"
#endif
#include "nvs_flash.h"
#include "driver/gpio.h"
#if ESP_IDF_VERSION_MAJOR >= 4
static void wifi_event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
}
static void ip_event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
}
#else
esp_err_t event_handler(void *ctx, system_event_t *event)
{
return ESP_OK;
}
#endif
void app_main(void)
{
nvs_flash_init();
tcpip_adapter_init();
#if ESP_IDF_VERSION_MAJOR >= 4
ESP_ERROR_CHECK(esp_event_loop_create_default());
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &ip_event_handler, NULL));
#else
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
#endif
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );