ESP_ERR_INVALID_STATE (0x103) on the ESP32
The call was valid, but not now: the component it belongs to is not initialized yet, is already initialized, or is in the middle of something else. The log line just before it usually names which.
ESP_ERROR_CHECK failed: esp_err_t 0x103 (ESP_ERR_INVALID_STATE) at 0x400d2a4f file: "./main/main.c" line 42 func: app_main expression: …
ESP_ERR_INVALID_STATE (0x103). ESP-IDF's description: Invalid state.
Read the line before it
Most ESP-IDF drivers log why they return this code. For example, the GPIO driver logs GPIO isr service already installed when gpio_install_isr_service() is called a second time.
The usual causes
- Initializing something twice: an ISR service, a driver, an event loop. Often two libraries both do it. Treat
ESP_ERR_INVALID_STATEfrom an init call as "already done" where that is safe. - Using something before it is initialized or started: WiFi calls before
esp_wifi_start(), NVS beforenvs_flash_init(), a peripheral before its driver is installed. - Order between tasks: a task that starts using a component before the task that sets it up has finished.
Related errors: ESP_ERR_NO_MEM · ESP_ERR_NVS_NO_FREE_PAGES · esp_err_t codes. All ESP32 errors: the list. Codes and descriptions from ESP-IDF's headers; behaviour from the API documentation of the functions named. ESP-IDF's Error Handling guide.
More
- Remote access to an ESP32 without TLS: what it measured and what it costs
- Reaching an ESP32 web server from outside its network
- Updating ESP32 firmware over the internet, with rollback
- Guru Meditation Error: decoding the backtrace, and crashes from the field
- Remote logging: ESP_LOG without a serial cable
- Heap and stack monitoring in the field
- An ESP32 behind CGNAT, 4G or Starlink
- TLS memory usage on the ESP32, and how to reduce it
- Sharing an ESP32 sensor page with anyone, without port forwarding
- ArduinoOTA over the internet, with a rollback
- ESP32 remote access compared: port forwarding, ngrok, Cloudflare Tunnel, Tailscale
- esp_http_server slow? The 250 ms delay and the fix
- Before the first ESP32 ships: a field support checklist
- ESP32 exception decoder: a Guru Meditation backtrace to lines, in the browser