如何修复 ESP8266 或 ESP32 上的 error: invalid conversion from 'int' to 'esp_mqtt_event_id_t'

如果你看到类似这样的错误消息

compile_error.txt
src/main.cpp: In function 'void InitMQTT()':
/home/uli/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/esp_event/include/esp_event_base.h:37:32: error: invalid conversion from 'int' to 'esp_mqtt_event_id_t' [-fpermissive]
 #define ESP_EVENT_ANY_ID       -1               /**< register handler for any event id */

src/main.cpp:80:44: note: in expansion of macro 'ESP_EVENT_ANY_ID'
    esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, client);
                                    ^~~~~~~~~~~~~~~~

ESP_EVENT_ANY_ID 替换为 MQTT_EVENT_ANY 并重新编译。这将修复问题。使用 ESP_EVENT_ANY_ID 在过时版本的 MQTT 库中是可能的。


Check out similar posts by category: Arduino, Embedded, ESP8266/ESP32, MQTT, Networking, PlatformIO