When i trying to build the code got error
error: cannot convert 'MQTTManager::mqtt_event_handler' from type 'esp_err_t (MQTTManager::)(esp_mqtt_event_handle_t)' {aka 'int (MQTTManager::)(esp_mqtt_event_t*)'} to type 'mqtt_event_callback_t' {aka 'int (*)(esp_mqtt_event_t*)'}
i try put a MQTT manager to a class, then i use the event handle to
esp_mqtt_client_config_t.event_handle
here is the mqttmanage.h
class MQTTManager
{
public:
void begin();
private:
esp_mqtt_client_config_t mqttCfg; // MQTT
esp_mqtt_client_handle_t mqttClient; // MQTT
esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event);
}
and here is the mqtt.cpp
esp_err_t MQTTManager::mqtt_event_handler (esp_mqtt_event_handle_t event)
{
......
}
void MQTTManager::begin()
{
Serial.println("---MQTT INITIALIZATION---");
mqttCfg.host = MQTT_HOST;
mqttCfg.port = MQTT_PORT;
mqttCfg.keepalive = 60;
mqttCfg.username = MQTT_USERNAME;
mqttCfg.password = MQTT_PASSWORD;
mqttCfg.event_handle = mqtt_event_handler;
mqttCfg.lwt_topic = topicPubStatus;
mqttCfg.lwt_msg = "0";
mqttCfg.lwt_msg_len = 1;
mqttCfg.lwt_retain = 1;
.....
}
what should i do ?
Learn Class and Making some device prototype