You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从Arduino IDE迁移到PlatformIO后,esp_task_wdt_config_t未声明的问题求助

从Arduino IDE迁移到PlatformIO后,esp_task_wdt_config_t未声明的问题求助

大家好,我最近从Arduino IDE切换到PlatformIO开发ESP32项目,碰到了一个棘手的问题:明明已经在代码里引入了esp_task_wdt.h库,却还是不断报错"esp_task_wdt_config_t" was not declared in this scope,连代码里的&wdt_config也报同样的未声明错误。

我已经尝试了几种方法,但都没解决问题:

  • 一开始我把esp_task_wdt.h文件放到了项目的lib文件夹里,没用;
  • 后来又在platformio.ini中添加了编译标志build_flags = -DCONFIG_ESP_TASK_WDT_EN,还是不行。

下面是我调用看门狗配置的代码片段:

void setupWatchdog() {
    // Define a configuration for the WDT
    esp_task_wdt_config_t wdt_config = {
        .timeout_ms = 30000, // Timeout in milliseconds (30 seconds)
        .idle_core_mask = (1 << portNUM_PROCESSORS) - 1, // Watchdog for all cores
        .trigger_panic = true // Trigger panic on WDT timeout
    };
    // Initialize the WDT with the new configuration
    esp_task_wdt_init(&wdt_config); // Pass the pointer to the configuration
    esp_task_wdt_add(NULL); // Add the current task to the WDT
}

我的platformio.ini配置如下:

[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200
build_flags = -DCONFIG_ESP_TASK_WDT_EN
lib_deps = 
    SPI @ ^2.0.0
    featherfly/SoftwareSerial @ ^1.0
    bblanchon/ArduinoJson @ ^7.4.2

另外要说明的是,这个库的其他函数在项目的另一个实例里调用是正常工作的,而且我确实已经在代码头部添加了#include "esp_task_wdt.h",但就是搞不定这个类型未声明的问题。有没有朋友能帮忙看看,怎么才能让esp_task_wdt_config_t像在Arduino IDE里一样正常使用呢?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 10:48:10