led_ctrl/include/LedMqttSubscriber.h

33 lines
637 B
C
Raw Normal View History

2025-06-05 09:24:58 +08:00
#pragma once
#include <string>
#include <mqtt/async_client.h>
class MqttClient
{
public:
MqttClient(const std::string &configPath);
2025-06-05 09:42:09 +08:00
~MqttClient();
bool start(); // 连接并订阅
void disconnect(); // 断开连接
2025-06-05 09:24:58 +08:00
private:
std::string broker;
std::string clientId;
std::string username;
std::string password;
std::string topic;
int qos;
class Callback : public virtual mqtt::callback
{
public:
void message_arrived(mqtt::const_message_ptr msg) override;
};
mqtt::async_client *client = nullptr;
mqtt::connect_options connOpts;
Callback callback;
};