Add support for multiple light bars/remotes (#3), bump to version 0.2
This commit is contained in:
33
mqtt.h
33
mqtt.h
@ -1,27 +1,40 @@
|
||||
#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(Lightbar *lightbar, const char *wifiSsid, const char *wifiPassword, const char *mqttServer, int mqttPort, const char *mqttUser, const char *mqttPassword, const char *mqttRootTopic, bool homeAssistantAutoDiscovery, const char *homeAssistantAutoDiscoveryPrefix, const char *homeAssistantDeviceName);
|
||||
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(uint32_t serial, byte command, byte options);
|
||||
void sendAction(Remote *remote, byte command, byte options);
|
||||
const String getCombinedRootTopic();
|
||||
const String getClientId();
|
||||
|
||||
private:
|
||||
WiFiClient *wifiClient;
|
||||
PubSubClient *client;
|
||||
String clientId;
|
||||
Lightbar *lightbar;
|
||||
const char *wifiSsid;
|
||||
const char *wifiPassword;
|
||||
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 = "";
|
||||
@ -29,11 +42,13 @@ private:
|
||||
String mqttRootTopic = "lightbar2mqtt";
|
||||
bool homeAssistantDiscovery = true;
|
||||
String homeAssistantDiscoveryPrefix = "homeassistant";
|
||||
String homeAssistantDeviceName = "Mi Computer Monitor Light Bar";
|
||||
|
||||
void setupWifi();
|
||||
void setupMqtt();
|
||||
void sendHomeAssistantDiscoveryMessages();
|
||||
String combinedRootTopic;
|
||||
std::function<void(Remote *, byte, byte)> remoteCommandHandler;
|
||||
|
||||
void sendAllHomeAssistantDiscoveryMessages();
|
||||
void sendHomeAssistantLightbarDiscoveryMessages(Lightbar *lightbar);
|
||||
void sendHomeAssistantRemoteDiscoveryMessages(Remote *remote);
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user