forked from MTJoker/HomeStatusDisplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HSDMqtt.hpp
42 lines (30 loc) · 810 Bytes
/
HSDMqtt.hpp
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
41
#pragma once
#include "HSDConfig.hpp"
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
class HSDMqtt
{
public:
HSDMqtt(const HSDConfig& config, MQTT_CALLBACK_SIGNATURE);
static const uint32_t MAX_IN_TOPICS = 10;
void begin();
void handle();
void publish(String topic, String msg);
bool reconnect();
bool addTopic(const char* topic);
bool connected() const;
private:
void initTopics();
void subscribe(const char* topic);
bool isTopicValid(const char* topic);
WiFiClient m_wifiClient;
mutable PubSubClient m_pubSubClient;
const HSDConfig& m_config;
const char* m_inTopics[MAX_IN_TOPICS];
uint32_t m_numberOfInTopics;
bool m_connectFailure;
int m_maxConnectRetries;
int m_numConnectRetriesDone;
int m_retryDelay;
unsigned long m_millisLastConnectTry;
};