c - ESP32 MQTT 事件处理
问题描述
我正在尝试将文件 mqtt_client.h 中定义的 arduino-esp32 方法用于我的ESP32/Arduino IDE项目:
我正在努力为此制作一个事件处理程序。
我目前有:
#include <mqtt_client.h>
void MQTTEvent(esp_mqtt_event_t event) {
// process event
}
void setup() {
esp_mqtt_client_config_t mqtt_cfg;
mqtt_cfg.host = "192.168.0.126";
mqtt_cfg.port = 1883;
mqtt_cfg.client_id = "ESP32";
mqtt_cfg.uri = "HOMEPC";
mqtt_cfg.event_handle = MQTTEvent;
esp_mqtt_client_handle_t mqtt_client = esp_mqtt_client_init(&mqtt_cfg);
esp_mqtt_client_start(mqtt_client);
}
void loop() {
}
...但它失败了:
*invalid conversion from 'void (*)(esp_mqtt_event_t)' to 'mqtt_event_callback_t {aka int (*)(esp_mqtt_event_t*)}' [-fpermissive]*
on line mqtt_cfg.event_handle = MQTTEvent;
我找不到任何例子。有人可以帮我吗?
解决方案
你的事件句柄的类型是错误的,它应该返回一个esp_err_t
所以而不是:
esp_err_t MQTTEvent(esp_mqtt_event_t *event) {
...
return ESP_OK; // you will need to return esp error codes
}
推荐阅读
- selenium - 如何从 Selenium 的下拉列表中选择一个值?
- python - Python tk 从组合中选择串口
- php - 更改 Wordpress 的默认分页 URL - 这可能吗?
- php - PHP警告:从空值创建默认对象
- java - Matlab 调用 Java 8 `java.time` 类
- javascript - 如果最近的 href 有某个类,则删除 Jquery 中的元素
- python - 自定义异常的单元测试(链式异常 python 3)
- html - 在卡片中添加折叠页脚(引导程序)
- regex - 如何正则表达式匹配所有情况
- firebase - Firebase BigQuery 数据范围