You can see what ESP_ERROR_CHECK does in esp-idf/components/esp32/include/esp_err.h
Code: Select all
#ifdef NDEBUG
#define ESP_ERROR_CHECK(x) do { \
esp_err_t rc = (x); \
(void) sizeof(rc); \
} while(0);
#else
#define ESP_ERROR_CHECK(x) do { \
esp_err_t rc = (x); \
if (rc != ESP_OK) { \
_esp_error_check_failed(rc, __FILE__, __LINE__, \
__ASSERT_FUNC, #x); \
} \
} while(0);
#endif
in the examples you can see multiple error checks, it checks if the function returns ESP_OK, otherwise it will take action.
Code: Select all
tcpip_adapter_init();
wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
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) );
wifi_config_t wifi_config = {
.sta = {
.ssid = EXAMPLE_WIFI_SSID,
.password = EXAMPLE_WIFI_PASS,
},
};
ESP_LOGI(TAG, "Setting WiFi configuration SSID %s...", wifi_config.sta.ssid);
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
ESP_ERROR_CHECK( esp_wifi_start() );
This initializes your event handler, and error check checks if that function returns succesfully.
Code: Select all
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
There are many event that can be handled by the event handler. see esp-idf/components/esp32/include/esp_event.h and the event_handler functions in the examples.
https://github.com/espressif/esp-idf/bl ... ple_main.c