This commit is contained in:
Tobias Blum 2018-02-17 23:30:43 +01:00
parent 191c45f014
commit 5fed3a4651
3 changed files with 7 additions and 7 deletions

View file

@ -27,7 +27,7 @@
// MQTT
#ifdef ENABLE_MQTT
#include <PubSubClient.h>
#ifdef ENABLE_HOMEASISTANT
#ifdef ENABLE_HOMEASSISTANT
#include <ArduinoJson.h>
#endif

View file

@ -8,7 +8,7 @@ const char HOSTNAME[] = "McLighting01"; // Friedly hostname
#define ENABLE_OTA // If defined, enable Arduino OTA code.
#define ENABLE_MQTT // If defined, enable MQTT client code, see: https://github.com/toblum/McLighting/wiki/MQTT-API
#define ENABLE_HOMEASISTANT // If defined, enable Homeassistant integration
#define ENABLE_HOMEASSISTANT // If defined, enable Homeassistant integration, ENABLE_MQTT must be active
// #define ENABLE_BUTTON // If defined, enable button handling code, see: https://github.com/toblum/McLighting/wiki/Button-control
// parameters for automatically cycling favorite patterns
@ -27,7 +27,7 @@ uint32_t autoParams[][4] = { // color, speed, mode, duration (seconds)
char mqtt_intopic[strlen(HOSTNAME) + 4 + 5]; // Topic in will be: <HOSTNAME>/in
char mqtt_outtopic[strlen(HOSTNAME) + 5 + 5]; // Topic out will be: <HOSTNAME>/out
#ifdef ENABLE_HOMEASISTANT
#ifdef ENABLE_HOMEASSISTANT
String mqtt_ha = "home/" + String(HOSTNAME) + "_ha/";
String mqtt_ha_state_in = mqtt_ha + "state/in";
String mqtt_ha_state_out = mqtt_ha + "state/out";

View file

@ -460,7 +460,7 @@ void checkForRequests() {
// ***************************************************************************
#ifdef ENABLE_MQTT
#ifdef ENABLE_HOMEASISTANT
#ifdef ENABLE_HOMEASSISTANT
char* removeSpaces(char* input) {
int i, j;
char *output = input;
@ -739,7 +739,7 @@ void checkForRequests() {
payload[length] = NULL;
DBG_OUTPUT_PORT.printf("MQTT: Message arrived [%s]\n", payload);
#ifdef ENABLE_HOMEASISTANT
#ifdef ENABLE_HOMEASSISTANT
if ((strcmp(topic, mqtt_ha_state_in.c_str()) == 0)) {
if (!processJson((char*)payload)) {
return;
@ -842,7 +842,7 @@ void checkForRequests() {
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
}
#ifdef ENABLE_HOMEASISTANT
#ifdef ENABLE_HOMEASSISTANT
}
#endif
free(payload);
@ -863,7 +863,7 @@ void checkForRequests() {
mqtt_client.publish(mqtt_outtopic, message);
// ... and resubscribe
mqtt_client.subscribe(mqtt_intopic);
#ifdef ENABLE_HOMEASISTANT
#ifdef ENABLE_HOMEASSISTANT
mqtt_client.subscribe(String(mqtt_ha + "#").c_str());
#endif