2024-05-22 23:07:24 +08:00
|
|
|
#ifndef __MQTTCLIENT_H__
|
|
|
|
#define __MQTTCLIENT_H__
|
|
|
|
|
2024-06-01 23:47:21 +08:00
|
|
|
#include <mqtt_client.h>
|
2024-05-22 23:07:24 +08:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
class MqttClient {
|
|
|
|
public:
|
|
|
|
static MqttClient *instance();
|
2024-06-01 23:47:21 +08:00
|
|
|
bool initialize(const std::string &username, const std::string &password);
|
2024-05-22 23:07:24 +08:00
|
|
|
|
2024-06-05 22:59:04 +08:00
|
|
|
void reportLedState();
|
|
|
|
~MqttClient();
|
|
|
|
|
2024-05-22 23:07:24 +08:00
|
|
|
protected:
|
2024-06-01 23:47:21 +08:00
|
|
|
static void eventHandler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data);
|
|
|
|
void onConnected(struct esp_mqtt_client *client);
|
|
|
|
void onSetStatus(const char *data, int size);
|
2024-05-22 23:07:24 +08:00
|
|
|
MqttClient() = default;
|
2024-06-01 23:47:21 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_setStatusTopic;
|
2024-06-05 22:59:04 +08:00
|
|
|
std::string m_statusTopic;
|
|
|
|
esp_mqtt_client_handle_t m_client = nullptr;
|
2024-05-22 23:07:24 +08:00
|
|
|
};
|
|
|
|
#endif // __MQTTCLIENT_H__
|