Initialisation depot
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
#include <PubSubClient.h>
|
||||
#include <WiFiClient.h>
|
||||
|
||||
class MqttManager {
|
||||
public:
|
||||
using MessageCallback = std::function<void(char*, uint8_t*, unsigned int)>;
|
||||
MqttManager();
|
||||
void begin(const char* server, uint16_t port, MessageCallback cb);
|
||||
void loop();
|
||||
bool publish(const char* topic, const char* payload);
|
||||
bool subscribe(const char* topic);
|
||||
bool connected();
|
||||
private:
|
||||
WiFiClient espClient;
|
||||
PubSubClient client{espClient};
|
||||
MessageCallback messageCb;
|
||||
const char* serverAddr = nullptr;
|
||||
uint16_t serverPort = 0;
|
||||
static MqttManager* instance;
|
||||
static void staticCallback(char* topic, byte* payload, unsigned int length);
|
||||
void connect();
|
||||
};
|
||||
Reference in New Issue
Block a user