Skip to content

Commit 577fce6

Browse files
committed
MQTT unification and cleanup
1 parent fe7fb6c commit 577fce6

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

wled00/cfg.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
537537

538538
CJSON(alexaNumPresets, interfaces["va"]["p"]);
539539

540-
#ifdef WLED_ENABLE_MQTT
540+
#ifndef WLED_DISABLE_MQTT
541541
JsonObject if_mqtt = interfaces["mqtt"];
542542
CJSON(mqttEnabled, if_mqtt["en"]);
543543
getStringFromJson(mqttServer, if_mqtt[F("broker")], MQTT_MAX_SERVER_LEN+1);
@@ -1019,7 +1019,7 @@ void serializeConfig() {
10191019
if_va["p"] = alexaNumPresets;
10201020
#endif
10211021

1022-
#ifdef WLED_ENABLE_MQTT
1022+
#ifndef WLED_DISABLE_MQTT
10231023
JsonObject if_mqtt = interfaces.createNestedObject("mqtt");
10241024
if_mqtt["en"] = mqttEnabled;
10251025
if_mqtt[F("broker")] = mqttServer;
@@ -1165,7 +1165,7 @@ bool deserializeConfigSec() {
11651165

11661166
[[maybe_unused]] JsonObject interfaces = root["if"];
11671167

1168-
#ifdef WLED_ENABLE_MQTT
1168+
#ifndef WLED_DISABLE_MQTT
11691169
JsonObject if_mqtt = interfaces["mqtt"];
11701170
getStringFromJson(mqttPass, if_mqtt["psk"], 65);
11711171
#endif
@@ -1206,7 +1206,7 @@ void serializeConfigSec() {
12061206
ap["psk"] = apPass;
12071207

12081208
[[maybe_unused]] JsonObject interfaces = root.createNestedObject("if");
1209-
#ifdef WLED_ENABLE_MQTT
1209+
#ifndef WLED_DISABLE_MQTT
12101210
JsonObject if_mqtt = interfaces.createNestedObject("mqtt");
12111211
if_mqtt["psk"] = mqttPass;
12121212
#endif

wled00/mqtt.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* MQTT communication protocol for home automation
55
*/
66

7-
#ifdef WLED_ENABLE_MQTT
7+
#ifndef WLED_DISABLE_MQTT
88
#define MQTT_KEEP_ALIVE_TIME 60 // contact the MQTT broker every 60 seconds
99

10-
void parseMQTTBriPayload(char* payload)
10+
static void parseMQTTBriPayload(char* payload)
1111
{
1212
if (strstr(payload, "ON") || strstr(payload, "on") || strstr(payload, "true")) {bri = briLast; stateUpdated(CALL_MODE_DIRECT_CHANGE);}
1313
else if (strstr(payload, "T" ) || strstr(payload, "t" )) {toggleOnOff(); stateUpdated(CALL_MODE_DIRECT_CHANGE);}
@@ -20,7 +20,7 @@ void parseMQTTBriPayload(char* payload)
2020
}
2121

2222

23-
void onMqttConnect(bool sessionPresent)
23+
static void onMqttConnect(bool sessionPresent)
2424
{
2525
//(re)subscribe to required topics
2626
char subuf[38];
@@ -52,7 +52,7 @@ void onMqttConnect(bool sessionPresent)
5252
}
5353

5454

55-
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
55+
static void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
5656
static char *payloadStr;
5757

5858
DEBUG_PRINT(F("MQTT msg: "));
@@ -166,6 +166,7 @@ bool initMqtt()
166166

167167
if (mqtt == nullptr) {
168168
mqtt = new AsyncMqttClient();
169+
if (!mqtt) return false;
169170
mqtt->onMessage(onMqttMessage);
170171
mqtt->onConnect(onMqttConnect);
171172
}

wled00/set.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
426426
t = request->arg(F("AP")).toInt();
427427
if (t >= 0 && t <= 9) alexaNumPresets = t;
428428

429-
#ifdef WLED_ENABLE_MQTT
429+
#ifndef WLED_DISABLE_MQTT
430430
mqttEnabled = request->hasArg(F("MQ"));
431431
strlcpy(mqttServer, request->arg(F("MS")).c_str(), MQTT_MAX_SERVER_LEN+1);
432432
t = request->arg(F("MQPORT")).toInt();

wled00/wled.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
#endif
146146

147147
#include "src/dependencies/e131/ESPAsyncE131.h"
148-
#ifdef WLED_ENABLE_MQTT
148+
#ifndef WLED_DISABLE_MQTT
149149
#include "src/dependencies/async-mqtt-client/AsyncMqttClient.h"
150150
#endif
151151

wled00/xml.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ void getSettingsJS(byte subPage, char* dest)
541541
oappend(SET_F("toggle('Alexa');")); // hide Alexa settings
542542
#endif
543543

544-
#ifdef WLED_ENABLE_MQTT
544+
#ifndef WLED_DISABLE_MQTT
545545
sappend('c',SET_F("MQ"),mqttEnabled);
546546
sappends('s',SET_F("MS"),mqttServer);
547547
sappend('v',SET_F("MQPORT"),mqttPort);

0 commit comments

Comments
 (0)