Disable MQTT more.

Disable Alexa more.
This commit is contained in:
Blaz Kristan 2023-01-12 20:35:34 +01:00
parent e410de9552
commit d78bef72ea
27 changed files with 113 additions and 13 deletions

View File

@ -92,12 +92,14 @@ class Animated_Staircase : public Usermod {
static const char _bottomEchoCm[]; static const char _bottomEchoCm[];
void publishMqtt(bool bottom, const char* state) { void publishMqtt(bool bottom, const char* state) {
#ifndef WLED_DISABLE_MQTT
//Check if MQTT Connected, otherwise it will crash the 8266 //Check if MQTT Connected, otherwise it will crash the 8266
if (WLED_MQTT_CONNECTED){ if (WLED_MQTT_CONNECTED){
char subuf[64]; char subuf[64];
sprintf_P(subuf, PSTR("%s/motion/%d"), mqttDeviceTopic, (int)bottom); sprintf_P(subuf, PSTR("%s/motion/%d"), mqttDeviceTopic, (int)bottom);
mqtt->publish(subuf, 0, false, state); mqtt->publish(subuf, 0, false, state);
} }
#endif
} }
void updateSegments() { void updateSegments() {
@ -345,6 +347,7 @@ class Animated_Staircase : public Usermod {
uint16_t getId() { return USERMOD_ID_ANIMATED_STAIRCASE; } uint16_t getId() { return USERMOD_ID_ANIMATED_STAIRCASE; }
#ifndef WLED_DISABLE_MQTT
/** /**
* handling of MQTT message * handling of MQTT message
* topic only contains stripped topic (part after /wled/MAC) * topic only contains stripped topic (part after /wled/MAC)
@ -382,6 +385,7 @@ class Animated_Staircase : public Usermod {
mqtt->subscribe(subuf, 0); mqtt->subscribe(subuf, 0);
} }
} }
#endif
void addToJsonState(JsonObject& root) { void addToJsonState(JsonObject& root) {
JsonObject staircase = root[FPSTR(_name)]; JsonObject staircase = root[FPSTR(_name)];

View File

@ -1,6 +1,10 @@
// force the compiler to show a warning to confirm that this file is included // force the compiler to show a warning to confirm that this file is included
#warning **** Included USERMOD_BH1750 **** #warning **** Included USERMOD_BH1750 ****
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif
#pragma once #pragma once
#include "wled.h" #include "wled.h"
@ -156,6 +160,7 @@ public:
{ {
lastLux = lux; lastLux = lux;
lastSend = millis(); lastSend = millis();
#ifndef WLED_DISABLE_MQTT
if (WLED_MQTT_CONNECTED) if (WLED_MQTT_CONNECTED)
{ {
if (!mqttInitialized) if (!mqttInitialized)
@ -170,6 +175,7 @@ public:
{ {
DEBUG_PRINTLN(F("Missing MQTT connection. Not publishing data")); DEBUG_PRINTLN(F("Missing MQTT connection. Not publishing data"));
} }
#endif
} }
} }

View File

@ -1,6 +1,10 @@
// force the compiler to show a warning to confirm that this file is included // force the compiler to show a warning to confirm that this file is included
#warning **** Included USERMOD_BME280 version 2.0 **** #warning **** Included USERMOD_BME280 version 2.0 ****
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif
#pragma once #pragma once
#include "wled.h" #include "wled.h"

View File

@ -224,6 +224,7 @@ class UsermodBattery : public Usermod
if (autoOffEnabled && (autoOffThreshold >= batteryLevel)) if (autoOffEnabled && (autoOffThreshold >= batteryLevel))
turnOff(); turnOff();
#ifndef WLED_DISABLE_MQTT
// SmartHome stuff // SmartHome stuff
// still don't know much about MQTT and/or HA // still don't know much about MQTT and/or HA
if (WLED_MQTT_CONNECTED) { if (WLED_MQTT_CONNECTED) {
@ -231,6 +232,7 @@ class UsermodBattery : public Usermod
snprintf_P(buf, 63, PSTR("%s/voltage"), mqttDeviceTopic); snprintf_P(buf, 63, PSTR("%s/voltage"), mqttDeviceTopic);
mqtt->publish(buf, 0, false, String(voltage).c_str()); mqtt->publish(buf, 0, false, String(voltage).c_str());
} }
#endif
} }

View File

@ -1,6 +1,10 @@
#pragma once #pragma once
#include "wled.h" #include "wled.h"
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif
#include <dht_nonblocking.h> #include <dht_nonblocking.h>

View File

@ -1,3 +1,7 @@
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif
#include "wled.h" #include "wled.h"
#include <Arduino.h> #include <Arduino.h>
#include <U8x8lib.h> // from https://github.com/olikraus/u8g2/ #include <U8x8lib.h> // from https://github.com/olikraus/u8g2/

View File

@ -1,3 +1,7 @@
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif
#include "wled.h" #include "wled.h"
#include <Arduino.h> #include <Arduino.h>
#include <U8x8lib.h> // from https://github.com/olikraus/u8g2/ #include <U8x8lib.h> // from https://github.com/olikraus/u8g2/

View File

@ -159,6 +159,7 @@ private:
void publishMqtt(const char* state) void publishMqtt(const char* state)
{ {
#ifndef WLED_DISABLE_MQTT
//Check if MQTT Connected, otherwise it will crash the 8266 //Check if MQTT Connected, otherwise it will crash the 8266
if (WLED_MQTT_CONNECTED) { if (WLED_MQTT_CONNECTED) {
char subuf[64]; char subuf[64];
@ -166,11 +167,13 @@ private:
strcat_P(subuf, PSTR("/motion")); strcat_P(subuf, PSTR("/motion"));
mqtt->publish(subuf, 0, false, state); mqtt->publish(subuf, 0, false, state);
} }
#endif
} }
// Create an MQTT Binary Sensor for Home Assistant Discovery purposes, this includes a pointer to the topic that is published to in the Loop. // Create an MQTT Binary Sensor for Home Assistant Discovery purposes, this includes a pointer to the topic that is published to in the Loop.
void publishHomeAssistantAutodiscovery() void publishHomeAssistantAutodiscovery()
{ {
#ifndef WLED_DISABLE_MQTT
if (WLED_MQTT_CONNECTED) { if (WLED_MQTT_CONNECTED) {
StaticJsonDocument<600> doc; StaticJsonDocument<600> doc;
char uid[24], json_str[1024], buf[128]; char uid[24], json_str[1024], buf[128];
@ -200,6 +203,7 @@ private:
mqtt->publish(buf, 0, true, json_str, payload_size); // do we really need to retain? mqtt->publish(buf, 0, true, json_str, payload_size); // do we really need to retain?
} }
#endif
} }
/** /**

View File

@ -109,6 +109,7 @@ public:
{ {
lastLDRValue = currentLDRValue; lastLDRValue = currentLDRValue;
#ifndef WLED_DISABLE_MQTT
if (WLED_MQTT_CONNECTED) if (WLED_MQTT_CONNECTED)
{ {
char subuf[45]; char subuf[45];
@ -121,6 +122,7 @@ public:
DEBUG_PRINTLN("Missing MQTT connection. Not publishing data"); DEBUG_PRINTLN("Missing MQTT connection. Not publishing data");
} }
} }
#endif
} }
uint16_t getLastLDRValue() uint16_t getLastLDRValue()

View File

@ -1,3 +1,7 @@
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif
#pragma once #pragma once
// this is remixed from usermod_v2_SensorsToMqtt.h (sensors_to_mqtt usermod) // this is remixed from usermod_v2_SensorsToMqtt.h (sensors_to_mqtt usermod)

View File

@ -134,6 +134,7 @@ class UsermodTemperature : public Usermod {
return false; return false;
} }
#ifndef WLED_DISABLE_MQTT
void publishHomeAssistantAutodiscovery() { void publishHomeAssistantAutodiscovery() {
if (!WLED_MQTT_CONNECTED) return; if (!WLED_MQTT_CONNECTED) return;
@ -155,6 +156,7 @@ class UsermodTemperature : public Usermod {
mqtt->publish(buf, 0, true, json_str, payload_size); mqtt->publish(buf, 0, true, json_str, payload_size);
HApublished = true; HApublished = true;
} }
#endif
public: public:
@ -212,6 +214,7 @@ class UsermodTemperature : public Usermod {
} }
errorCount = 0; errorCount = 0;
#ifndef WLED_DISABLE_MQTT
if (WLED_MQTT_CONNECTED) { if (WLED_MQTT_CONNECTED) {
char subuf[64]; char subuf[64];
strcpy(subuf, mqttDeviceTopic); strcpy(subuf, mqttDeviceTopic);
@ -227,6 +230,7 @@ class UsermodTemperature : public Usermod {
// publish something else to indicate status? // publish something else to indicate status?
} }
} }
#endif
} }
} }
@ -236,6 +240,7 @@ class UsermodTemperature : public Usermod {
*/ */
//void connected() {} //void connected() {}
#ifndef WLED_DISABLE_MQTT
/** /**
* subscribe to MQTT topic if needed * subscribe to MQTT topic if needed
*/ */
@ -246,6 +251,7 @@ class UsermodTemperature : public Usermod {
publishHomeAssistantAutodiscovery(); publishHomeAssistantAutodiscovery();
} }
} }
#endif
/* /*
* API calls te enable data exchange between WLED modules * API calls te enable data exchange between WLED modules

View File

@ -101,6 +101,7 @@ void userLoop() {
if (temptimer - lastMeasure > 60000) if (temptimer - lastMeasure > 60000)
{ {
lastMeasure = temptimer; lastMeasure = temptimer;
#ifndef WLED_DISABLE_MQTT
//Check if MQTT Connected, otherwise it will crash the 8266 //Check if MQTT Connected, otherwise it will crash the 8266
if (mqtt != nullptr) if (mqtt != nullptr)
{ {
@ -116,6 +117,7 @@ void userLoop() {
t += "/temperature"; t += "/temperature";
mqtt->publish(t.c_str(), 0, true, String(board_temperature).c_str()); mqtt->publish(t.c_str(), 0, true, String(board_temperature).c_str());
} }
#endif
} }
// Check if we time interval for redrawing passes. // Check if we time interval for redrawing passes.

View File

@ -103,6 +103,7 @@ void userLoop() {
{ {
lastMeasure = tempTimer; lastMeasure = tempTimer;
#ifndef WLED_DISABLE_MQTT
// Check if MQTT Connected, otherwise it will crash the 8266 // Check if MQTT Connected, otherwise it will crash the 8266
if (mqtt != nullptr) if (mqtt != nullptr)
{ {
@ -122,6 +123,7 @@ void userLoop() {
h += "/humidity"; h += "/humidity";
mqtt->publish(h.c_str(), 0, true, String(board_humidity).c_str()); mqtt->publish(h.c_str(), 0, true, String(board_humidity).c_str());
} }
#endif
} }
// Check if we time interval for redrawing passes. // Check if we time interval for redrawing passes.

View File

@ -219,6 +219,7 @@ class BobLightUsermod : public Usermod {
void enable(bool en) { enabled = en; } void enable(bool en) { enabled = en; }
#ifndef WLED_DISABLE_MQTT
/** /**
* handling of MQTT message * handling of MQTT message
* topic only contains stripped topic (part after /wled/MAC) * topic only contains stripped topic (part after /wled/MAC)
@ -249,6 +250,7 @@ class BobLightUsermod : public Usermod {
// mqtt->subscribe(subuf, 0); // mqtt->subscribe(subuf, 0);
//} //}
} }
#endif
void addToJsonInfo(JsonObject& root) void addToJsonInfo(JsonObject& root)
{ {

View File

@ -66,12 +66,14 @@ class MultiRelay : public Usermod {
static const char _HAautodiscovery[]; static const char _HAautodiscovery[];
void publishMqtt(int relay) { void publishMqtt(int relay) {
#ifndef WLED_DISABLE_MQTT
//Check if MQTT Connected, otherwise it will crash the 8266 //Check if MQTT Connected, otherwise it will crash the 8266
if (WLED_MQTT_CONNECTED){ if (WLED_MQTT_CONNECTED){
char subuf[64]; char subuf[64];
sprintf_P(subuf, PSTR("%s/relay/%d"), mqttDeviceTopic, relay); sprintf_P(subuf, PSTR("%s/relay/%d"), mqttDeviceTopic, relay);
mqtt->publish(subuf, 0, false, _relay[relay].state ? "on" : "off"); mqtt->publish(subuf, 0, false, _relay[relay].state ? "on" : "off");
} }
#endif
} }
/** /**
@ -232,6 +234,7 @@ class MultiRelay : public Usermod {
//Functions called by WLED //Functions called by WLED
#ifndef WLED_DISABLE_MQTT
/** /**
* handling of MQTT message * handling of MQTT message
* topic only contains stripped topic (part after /wled/MAC) * topic only contains stripped topic (part after /wled/MAC)
@ -313,6 +316,7 @@ class MultiRelay : public Usermod {
mqtt->publish(buf, 0, true, json_str, payload_size); mqtt->publish(buf, 0, true, json_str, payload_size);
} }
} }
#endif
/** /**
* setup() is called once at boot. WiFi is not yet connected at this point. * setup() is called once at boot. WiFi is not yet connected at this point.

View File

@ -1,3 +1,7 @@
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif
#pragma once #pragma once
#include "wled.h" #include "wled.h"

View File

@ -1,3 +1,7 @@
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif
#pragma once #pragma once
#include "wled.h" #include "wled.h"

View File

@ -1,3 +1,7 @@
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif
#pragma once #pragma once
#include "wled.h" #include "wled.h"

View File

@ -1,3 +1,7 @@
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif
#pragma once #pragma once
#include "SHT85.h" #include "SHT85.h"

View File

@ -1,3 +1,7 @@
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif
#pragma once #pragma once
#include "wled.h" #include "wled.h"

View File

@ -24,12 +24,14 @@ void shortPressAction(uint8_t b)
applyPreset(macroButton[b], CALL_MODE_BUTTON_PRESET); applyPreset(macroButton[b], CALL_MODE_BUTTON_PRESET);
} }
#ifndef WLED_DISABLE_MQTT
// publish MQTT message // publish MQTT message
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) { if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
char subuf[64]; char subuf[64];
sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b); sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
mqtt->publish(subuf, 0, false, "short"); mqtt->publish(subuf, 0, false, "short");
} }
#endif
} }
void longPressAction(uint8_t b) void longPressAction(uint8_t b)
@ -43,12 +45,14 @@ void longPressAction(uint8_t b)
applyPreset(macroLongPress[b], CALL_MODE_BUTTON_PRESET); applyPreset(macroLongPress[b], CALL_MODE_BUTTON_PRESET);
} }
#ifndef WLED_DISABLE_MQTT
// publish MQTT message // publish MQTT message
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) { if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
char subuf[64]; char subuf[64];
sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b); sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
mqtt->publish(subuf, 0, false, "long"); mqtt->publish(subuf, 0, false, "long");
} }
#endif
} }
void doublePressAction(uint8_t b) void doublePressAction(uint8_t b)
@ -62,12 +66,14 @@ void doublePressAction(uint8_t b)
applyPreset(macroDoublePress[b], CALL_MODE_BUTTON_PRESET); applyPreset(macroDoublePress[b], CALL_MODE_BUTTON_PRESET);
} }
#ifndef WLED_DISABLE_MQTT
// publish MQTT message // publish MQTT message
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) { if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
char subuf[64]; char subuf[64];
sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b); sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
mqtt->publish(subuf, 0, false, "double"); mqtt->publish(subuf, 0, false, "double");
} }
#endif
} }
bool isButtonPressed(uint8_t i) bool isButtonPressed(uint8_t i)
@ -119,6 +125,7 @@ void handleSwitch(uint8_t b)
} }
} }
#ifndef WLED_DISABLE_MQTT
// publish MQTT message // publish MQTT message
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) { if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
char subuf[64]; char subuf[64];
@ -126,6 +133,7 @@ void handleSwitch(uint8_t b)
else sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b); else sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
mqtt->publish(subuf, 0, false, !buttonPressedBefore[b] ? "off" : "on"); mqtt->publish(subuf, 0, false, !buttonPressedBefore[b] ? "off" : "on");
} }
#endif
buttonLongPressed[b] = buttonPressedBefore[b]; //save the last "long term" switch state buttonLongPressed[b] = buttonPressedBefore[b]; //save the last "long term" switch state
} }

View File

@ -1,18 +1,17 @@
#ifndef WLED_FCN_DECLARE_H #ifndef WLED_FCN_DECLARE_H
#define WLED_FCN_DECLARE_H #define WLED_FCN_DECLARE_H
#include <Arduino.h>
#include "src/dependencies/espalexa/EspalexaDevice.h"
#include "src/dependencies/e131/ESPAsyncE131.h"
/* /*
* All globally accessible functions are declared here * All globally accessible functions are declared here
*/ */
//alexa.cpp //alexa.cpp
#ifndef WLED_DISABLE_ALEXA
void onAlexaChange(EspalexaDevice* dev); void onAlexaChange(EspalexaDevice* dev);
void alexaInit(); void alexaInit();
void handleAlexa(); void handleAlexa();
void onAlexaChange(EspalexaDevice* dev); void onAlexaChange(EspalexaDevice* dev);
#endif
//blynk.cpp //blynk.cpp
#ifndef WLED_DISABLE_BLYNK #ifndef WLED_DISABLE_BLYNK

View File

@ -180,7 +180,9 @@ void handleTransitions()
{ {
//handle still pending interface update //handle still pending interface update
if (interfaceUpdateCallMode && millis() - lastInterfaceUpdate > INTERFACE_UPDATE_COOLDOWN) updateInterfaces(interfaceUpdateCallMode); if (interfaceUpdateCallMode && millis() - lastInterfaceUpdate > INTERFACE_UPDATE_COOLDOWN) updateInterfaces(interfaceUpdateCallMode);
#ifndef WLED_DISABLE_MQTT
if (doPublishMqtt) publishMqtt(); if (doPublishMqtt) publishMqtt();
#endif
if (transitionActive && transitionDelayTemp > 0) if (transitionActive && transitionDelayTemp > 0)
{ {

View File

@ -177,8 +177,4 @@ bool initMqtt()
mqtt->connect(); mqtt->connect();
return true; return true;
} }
#else
bool initMqtt(){return false;}
void publishMqtt(){}
#endif #endif

View File

@ -681,7 +681,9 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
lastEditTime = millis(); lastEditTime = millis();
if (subPage != 2 && !doReboot) doSerializeConfig = true; //serializeConfig(); //do not save if factory reset or LED settings (which are saved after LED re-init) if (subPage != 2 && !doReboot) doSerializeConfig = true; //serializeConfig(); //do not save if factory reset or LED settings (which are saved after LED re-init)
#ifndef WLED_DISABLE_ALEXA
if (subPage == 4) alexaInit(); if (subPage == 4) alexaInit();
#endif
} }

View File

@ -42,7 +42,9 @@ void WLED::loop()
#endif #endif
handleTime(); handleTime();
#ifndef WLED_DISABLE_INFRARED
handleIR(); // 2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too handleIR(); // 2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too
#endif
handleConnection(); handleConnection();
handleSerial(); handleSerial();
handleNotifications(); handleNotifications();
@ -64,7 +66,9 @@ void WLED::loop()
yield(); yield();
handleIO(); handleIO();
#ifndef WLED_DISABLE_INFRARED
handleIR(); handleIR();
#endif
#ifndef WLED_DISABLE_ALEXA #ifndef WLED_DISABLE_ALEXA
handleAlexa(); handleAlexa();
#endif #endif
@ -135,7 +139,9 @@ void WLED::loop()
} }
if (millis() - lastMqttReconnectAttempt > 30000 || lastMqttReconnectAttempt == 0) { // lastMqttReconnectAttempt==0 forces immediate broadcast if (millis() - lastMqttReconnectAttempt > 30000 || lastMqttReconnectAttempt == 0) { // lastMqttReconnectAttempt==0 forces immediate broadcast
lastMqttReconnectAttempt = millis(); lastMqttReconnectAttempt = millis();
#ifndef WLED_DISABLE_MQTT
initMqtt(); initMqtt();
#endif
yield(); yield();
// refresh WLED nodes list // refresh WLED nodes list
refreshNodeList(); refreshNodeList();
@ -414,8 +420,10 @@ void WLED::setup()
// fill in unique mdns default // fill in unique mdns default
if (strcmp(cmDNS, "x") == 0) sprintf_P(cmDNS, PSTR("wled-%*s"), 6, escapedMac.c_str() + 6); if (strcmp(cmDNS, "x") == 0) sprintf_P(cmDNS, PSTR("wled-%*s"), 6, escapedMac.c_str() + 6);
#ifndef WLED_DISABLE_MQTT
if (mqttDeviceTopic[0] == 0) sprintf_P(mqttDeviceTopic, PSTR("wled/%*s"), 6, escapedMac.c_str() + 6); if (mqttDeviceTopic[0] == 0) sprintf_P(mqttDeviceTopic, PSTR("wled/%*s"), 6, escapedMac.c_str() + 6);
if (mqttClientID[0] == 0) sprintf_P(mqttClientID, PSTR("WLED-%*s"), 6, escapedMac.c_str() + 6); if (mqttClientID[0] == 0) sprintf_P(mqttClientID, PSTR("WLED-%*s"), 6, escapedMac.c_str() + 6);
#endif
#ifdef WLED_ENABLE_ADALIGHT #ifdef WLED_ENABLE_ADALIGHT
if (Serial.available() > 0 && Serial.peek() == 'I') handleImprovPacket(); if (Serial.available() > 0 && Serial.peek() == 'I') handleImprovPacket();
@ -674,9 +682,11 @@ void WLED::initInterfaces()
} }
#endif #endif
#ifndef WLED_DISABLE_ALEXA
// init Alexa hue emulation // init Alexa hue emulation
if (alexaEnabled) if (alexaEnabled)
alexaInit(); alexaInit();
#endif
#ifndef WLED_DISABLE_OTA #ifndef WLED_DISABLE_OTA
if (aOtaEnabled) if (aOtaEnabled)
@ -715,7 +725,9 @@ void WLED::initInterfaces()
e131.begin(e131Multicast, e131Port, e131Universe, E131_MAX_UNIVERSE_COUNT); e131.begin(e131Multicast, e131Port, e131Universe, E131_MAX_UNIVERSE_COUNT);
ddp.begin(false, DDP_DEFAULT_PORT); ddp.begin(false, DDP_DEFAULT_PORT);
reconnectHue(); reconnectHue();
#ifndef WLED_DISABLE_MQTT
initMqtt(); initMqtt();
#endif
interfacesInited = true; interfacesInited = true;
wasConnected = true; wasConnected = true;
} }

View File

@ -121,6 +121,7 @@
#define ESPALEXA_MAXDEVICES 10 #define ESPALEXA_MAXDEVICES 10
// #define ESPALEXA_DEBUG // #define ESPALEXA_DEBUG
#include "src/dependencies/espalexa/Espalexa.h" #include "src/dependencies/espalexa/Espalexa.h"
#include "src/dependencies/espalexa/EspalexaDevice.h"
#endif #endif
#ifndef WLED_DISABLE_BLYNK #ifndef WLED_DISABLE_BLYNK
#include "src/dependencies/blynk/BlynkSimpleEsp.h" #include "src/dependencies/blynk/BlynkSimpleEsp.h"
@ -135,7 +136,9 @@
#endif #endif
#include "src/dependencies/e131/ESPAsyncE131.h" #include "src/dependencies/e131/ESPAsyncE131.h"
#ifdef WLED_ENABLE_MQTT
#include "src/dependencies/async-mqtt-client/AsyncMqttClient.h" #include "src/dependencies/async-mqtt-client/AsyncMqttClient.h"
#endif
#define ARDUINOJSON_DECODE_UNICODE 0 #define ARDUINOJSON_DECODE_UNICODE 0
#include "src/dependencies/json/AsyncJson-v6.h" #include "src/dependencies/json/AsyncJson-v6.h"
@ -407,7 +410,12 @@ WLED_GLOBAL bool e131Multicast _INIT(false); // multicast o
WLED_GLOBAL bool e131SkipOutOfSequence _INIT(false); // freeze instead of flickering WLED_GLOBAL bool e131SkipOutOfSequence _INIT(false); // freeze instead of flickering
WLED_GLOBAL uint16_t pollReplyCount _INIT(0); // count number of replies for ArtPoll node report WLED_GLOBAL uint16_t pollReplyCount _INIT(0); // count number of replies for ArtPoll node report
// mqtt
WLED_GLOBAL unsigned long lastMqttReconnectAttempt _INIT(0); // used for other periodic tasks too
#ifndef WLED_DISABLE_MQTT
WLED_GLOBAL AsyncMqttClient *mqtt _INIT(NULL);
WLED_GLOBAL bool mqttEnabled _INIT(false); WLED_GLOBAL bool mqttEnabled _INIT(false);
WLED_GLOBAL char mqttStatusTopic[40] _INIT(""); // this must be global because of async handlers
WLED_GLOBAL char mqttDeviceTopic[33] _INIT(""); // main MQTT topic (individual per device, default is wled/mac) WLED_GLOBAL char mqttDeviceTopic[33] _INIT(""); // main MQTT topic (individual per device, default is wled/mac)
WLED_GLOBAL char mqttGroupTopic[33] _INIT("wled/all"); // second MQTT topic (for example to group devices) WLED_GLOBAL char mqttGroupTopic[33] _INIT("wled/all"); // second MQTT topic (for example to group devices)
WLED_GLOBAL char mqttServer[33] _INIT(""); // both domains and IPs should work (no SSL) WLED_GLOBAL char mqttServer[33] _INIT(""); // both domains and IPs should work (no SSL)
@ -415,6 +423,10 @@ WLED_GLOBAL char mqttUser[41] _INIT(""); // optional: username
WLED_GLOBAL char mqttPass[65] _INIT(""); // optional: password for MQTT auth WLED_GLOBAL char mqttPass[65] _INIT(""); // optional: password for MQTT auth
WLED_GLOBAL char mqttClientID[41] _INIT(""); // override the client ID WLED_GLOBAL char mqttClientID[41] _INIT(""); // override the client ID
WLED_GLOBAL uint16_t mqttPort _INIT(1883); WLED_GLOBAL uint16_t mqttPort _INIT(1883);
#define WLED_MQTT_CONNECTED (mqtt != nullptr && mqtt->connected())
#else
#define WLED_MQTT_CONNECTED false
#endif
#ifndef WLED_DISABLE_HUESYNC #ifndef WLED_DISABLE_HUESYNC
WLED_GLOBAL bool huePollingEnabled _INIT(false); // poll hue bridge for light state WLED_GLOBAL bool huePollingEnabled _INIT(false); // poll hue bridge for light state
@ -590,11 +602,8 @@ WLED_GLOBAL uint8_t tpmPacketCount _INIT(0);
WLED_GLOBAL uint16_t tpmPayloadFrameSize _INIT(0); WLED_GLOBAL uint16_t tpmPayloadFrameSize _INIT(0);
WLED_GLOBAL bool useMainSegmentOnly _INIT(false); WLED_GLOBAL bool useMainSegmentOnly _INIT(false);
// mqtt
WLED_GLOBAL unsigned long lastMqttReconnectAttempt _INIT(0);
WLED_GLOBAL unsigned long lastInterfaceUpdate _INIT(0); WLED_GLOBAL unsigned long lastInterfaceUpdate _INIT(0);
WLED_GLOBAL byte interfaceUpdateCallMode _INIT(CALL_MODE_INIT); WLED_GLOBAL byte interfaceUpdateCallMode _INIT(CALL_MODE_INIT);
WLED_GLOBAL char mqttStatusTopic[40] _INIT(""); // this must be global because of async handlers
// alexa udp // alexa udp
WLED_GLOBAL String escapedMac; WLED_GLOBAL String escapedMac;
@ -656,7 +665,6 @@ WLED_GLOBAL AsyncWebServer server _INIT_N(((80)));
WLED_GLOBAL AsyncWebSocket ws _INIT_N((("/ws"))); WLED_GLOBAL AsyncWebSocket ws _INIT_N((("/ws")));
#endif #endif
WLED_GLOBAL AsyncClient *hueClient _INIT(NULL); WLED_GLOBAL AsyncClient *hueClient _INIT(NULL);
WLED_GLOBAL AsyncMqttClient* mqtt _INIT(NULL);
WLED_GLOBAL AsyncWebHandler *editHandler _INIT(nullptr); WLED_GLOBAL AsyncWebHandler *editHandler _INIT(nullptr);
// udp interface objects // udp interface objects
@ -766,7 +774,6 @@ WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0);
#define WLED_CONNECTED (WiFi.status() == WL_CONNECTED) #define WLED_CONNECTED (WiFi.status() == WL_CONNECTED)
#endif #endif
#define WLED_WIFI_CONFIGURED (strlen(clientSSID) >= 1 && strcmp(clientSSID, DEFAULT_CLIENT_SSID) != 0) #define WLED_WIFI_CONFIGURED (strlen(clientSSID) >= 1 && strcmp(clientSSID, DEFAULT_CLIENT_SSID) != 0)
#define WLED_MQTT_CONNECTED (mqtt != nullptr && mqtt->connected())
#ifndef WLED_AP_SSID_UNIQUE #ifndef WLED_AP_SSID_UNIQUE
#define WLED_SET_AP_SSID() do { \ #define WLED_SET_AP_SSID() do { \