-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmqtt.h
54 lines (46 loc) · 1.59 KB
/
mqtt.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <PubSubClient.h>
#include <WiFi.h>
#include "constants.h"
#include "lightbar.h"
#include "remote.h"
#ifndef MQTT_H
#define MQTT_H
class Remote;
class Lightbar;
class MQTT
{
public:
MQTT(WiFiClient *wifiClient, const char *mqttServer, int mqttPort, const char *mqttUser, const char *mqttPassword, const char *mqttRootTopic, bool homeAssistantAutoDiscovery, const char *homeAssistantAutoDiscoveryPrefix);
~MQTT();
void setup();
void loop();
bool addLightbar(Lightbar *lightbar);
bool removeLightbar(Lightbar *lightbar);
bool addRemote(Remote *remote);
bool removeRemote(Remote *remote);
void onMessage(char *topic, byte *payload, unsigned int length);
void sendAction(Remote *remote, byte command, byte options);
const String getCombinedRootTopic();
const String getClientId();
private:
WiFiClient *wifiClient;
PubSubClient *client;
String clientId;
Lightbar *lightbars[constants::MAX_LIGHTBARS];
int lightbarCount = 0;
Remote *remotes[constants::MAX_REMOTES];
int remoteCount = 0;
const char *mqttServer;
int mqttPort = 1883;
const char *mqttUser = "";
const char *mqttPassword = "";
String mqttRootTopic = "lightbar2mqtt";
bool homeAssistantDiscovery = true;
String homeAssistantDiscoveryPrefix = "homeassistant";
String combinedRootTopic;
std::function<void(Remote *, byte, byte)> remoteCommandHandler;
void sendAllHomeAssistantDiscoveryMessages();
void sendHomeAssistantLightbarDiscoveryMessages(Lightbar *lightbar);
void sendHomeAssistantRemoteDiscoveryMessages(Remote *remote);
};
#endif