mirror of
https://github.com/wled/WLED.git
synced 2025-04-24 06:47:18 +00:00
MQTT unification and cleanup
This commit is contained in:
parent
fe7fb6c7a9
commit
577fce69e2
@ -537,7 +537,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
||||
|
||||
CJSON(alexaNumPresets, interfaces["va"]["p"]);
|
||||
|
||||
#ifdef WLED_ENABLE_MQTT
|
||||
#ifndef WLED_DISABLE_MQTT
|
||||
JsonObject if_mqtt = interfaces["mqtt"];
|
||||
CJSON(mqttEnabled, if_mqtt["en"]);
|
||||
getStringFromJson(mqttServer, if_mqtt[F("broker")], MQTT_MAX_SERVER_LEN+1);
|
||||
@ -1019,7 +1019,7 @@ void serializeConfig() {
|
||||
if_va["p"] = alexaNumPresets;
|
||||
#endif
|
||||
|
||||
#ifdef WLED_ENABLE_MQTT
|
||||
#ifndef WLED_DISABLE_MQTT
|
||||
JsonObject if_mqtt = interfaces.createNestedObject("mqtt");
|
||||
if_mqtt["en"] = mqttEnabled;
|
||||
if_mqtt[F("broker")] = mqttServer;
|
||||
@ -1165,7 +1165,7 @@ bool deserializeConfigSec() {
|
||||
|
||||
[[maybe_unused]] JsonObject interfaces = root["if"];
|
||||
|
||||
#ifdef WLED_ENABLE_MQTT
|
||||
#ifndef WLED_DISABLE_MQTT
|
||||
JsonObject if_mqtt = interfaces["mqtt"];
|
||||
getStringFromJson(mqttPass, if_mqtt["psk"], 65);
|
||||
#endif
|
||||
@ -1206,7 +1206,7 @@ void serializeConfigSec() {
|
||||
ap["psk"] = apPass;
|
||||
|
||||
[[maybe_unused]] JsonObject interfaces = root.createNestedObject("if");
|
||||
#ifdef WLED_ENABLE_MQTT
|
||||
#ifndef WLED_DISABLE_MQTT
|
||||
JsonObject if_mqtt = interfaces.createNestedObject("mqtt");
|
||||
if_mqtt["psk"] = mqttPass;
|
||||
#endif
|
||||
|
@ -4,10 +4,10 @@
|
||||
* MQTT communication protocol for home automation
|
||||
*/
|
||||
|
||||
#ifdef WLED_ENABLE_MQTT
|
||||
#ifndef WLED_DISABLE_MQTT
|
||||
#define MQTT_KEEP_ALIVE_TIME 60 // contact the MQTT broker every 60 seconds
|
||||
|
||||
void parseMQTTBriPayload(char* payload)
|
||||
static void parseMQTTBriPayload(char* payload)
|
||||
{
|
||||
if (strstr(payload, "ON") || strstr(payload, "on") || strstr(payload, "true")) {bri = briLast; stateUpdated(CALL_MODE_DIRECT_CHANGE);}
|
||||
else if (strstr(payload, "T" ) || strstr(payload, "t" )) {toggleOnOff(); stateUpdated(CALL_MODE_DIRECT_CHANGE);}
|
||||
@ -20,7 +20,7 @@ void parseMQTTBriPayload(char* payload)
|
||||
}
|
||||
|
||||
|
||||
void onMqttConnect(bool sessionPresent)
|
||||
static void onMqttConnect(bool sessionPresent)
|
||||
{
|
||||
//(re)subscribe to required topics
|
||||
char subuf[38];
|
||||
@ -52,7 +52,7 @@ void onMqttConnect(bool sessionPresent)
|
||||
}
|
||||
|
||||
|
||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||
static void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||
static char *payloadStr;
|
||||
|
||||
DEBUG_PRINT(F("MQTT msg: "));
|
||||
@ -166,6 +166,7 @@ bool initMqtt()
|
||||
|
||||
if (mqtt == nullptr) {
|
||||
mqtt = new AsyncMqttClient();
|
||||
if (!mqtt) return false;
|
||||
mqtt->onMessage(onMqttMessage);
|
||||
mqtt->onConnect(onMqttConnect);
|
||||
}
|
||||
|
@ -426,7 +426,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
||||
t = request->arg(F("AP")).toInt();
|
||||
if (t >= 0 && t <= 9) alexaNumPresets = t;
|
||||
|
||||
#ifdef WLED_ENABLE_MQTT
|
||||
#ifndef WLED_DISABLE_MQTT
|
||||
mqttEnabled = request->hasArg(F("MQ"));
|
||||
strlcpy(mqttServer, request->arg(F("MS")).c_str(), MQTT_MAX_SERVER_LEN+1);
|
||||
t = request->arg(F("MQPORT")).toInt();
|
||||
|
@ -145,7 +145,7 @@
|
||||
#endif
|
||||
|
||||
#include "src/dependencies/e131/ESPAsyncE131.h"
|
||||
#ifdef WLED_ENABLE_MQTT
|
||||
#ifndef WLED_DISABLE_MQTT
|
||||
#include "src/dependencies/async-mqtt-client/AsyncMqttClient.h"
|
||||
#endif
|
||||
|
||||
|
@ -541,7 +541,7 @@ void getSettingsJS(byte subPage, char* dest)
|
||||
oappend(SET_F("toggle('Alexa');")); // hide Alexa settings
|
||||
#endif
|
||||
|
||||
#ifdef WLED_ENABLE_MQTT
|
||||
#ifndef WLED_DISABLE_MQTT
|
||||
sappend('c',SET_F("MQ"),mqttEnabled);
|
||||
sappends('s',SET_F("MS"),mqttServer);
|
||||
sappend('v',SET_F("MQPORT"),mqttPort);
|
||||
|
Loading…
x
Reference in New Issue
Block a user