forked from RomeHein/ESPecial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MqttHandler.h
40 lines (37 loc) · 1007 Bytes
/
MqttHandler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once
#ifndef MqttHandler_h
#define MqttHandler_h
#include <Arduino.h>
#include "PreferenceHandler.h"
#include <WiFiClient.h>
#include <PubSubClient.h>
typedef struct
{
char debug[TOPIC_MAX_SIZE];
char gpio[TOPIC_MAX_SIZE];
char automation[TOPIC_MAX_SIZE];
char config[TOPIC_MAX_SIZE];
} MqttTopics;
class MqttHandler
{
private:
unsigned long lastSend = 0;
MqttTopics topics;
PreferenceHandler &preference;
WiFiClient &client;
PubSubClient* mqtt_client;
bool isInit = false;
void handleNewMessages(int numNewMessages);
void connect();
void callback(char* topic, byte* payload, unsigned int length);
public:
~MqttHandler() { delete mqtt_client; };
MqttHandler(PreferenceHandler& preference, WiFiClient &client) : preference(preference), client(client) {};
int automationsQueued[MAX_AUTOMATIONS_NUMBER] = {};
void begin();
void handle();
void disconnect();
void publish(int pin);
void publishConfig();
};
#endif