-
Notifications
You must be signed in to change notification settings - Fork 25
/
MQTTPublisher.h
38 lines (30 loc) · 915 Bytes
/
MQTTPublisher.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
#define MQTT_SOCKET_TIMEOUT 5
#pragma once
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "SettingsManager.h"
#include "GoodWeCommunicator.h"
#include <vector>
#include "PubSubClient.h"
#include "WiFiClient.h"
#include "Debug.h"
#define RECONNECT_TIMEOUT 15000
class MQTTPublisher
{
private:
SettingsManager::Settings * mqttSettings;
SettingsManager * mqttSettingsManager;
GoodWeCommunicator * goodweCommunicator;
bool isStarted;
unsigned long lastConnectionAttempt = 0; //last reconnect
unsigned long lastSentQuickUpdate = 0; //last update of the fast changing info
unsigned long lastSentRegularUpdate = 0; //last update of the regular update info
bool publishOnMQTT(String prepend, String topic, String value);
bool reconnect();
public:
MQTTPublisher(SettingsManager * settingsManager, GoodWeCommunicator *goodWe);
~MQTTPublisher();
void start();
void stop();
void handle();
};