Skip to content

Commit

Permalink
Disable MQTT more.
Browse files Browse the repository at this point in the history
Disable Alexa more.
  • Loading branch information
blazoncek committed Jan 12, 2023
1 parent e410de9 commit d78bef7
Show file tree
Hide file tree
Showing 27 changed files with 113 additions and 13 deletions.
4 changes: 4 additions & 0 deletions usermods/Animated_Staircase/Animated_Staircase.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ class Animated_Staircase : public Usermod {
static const char _bottomEchoCm[];

void publishMqtt(bool bottom, const char* state) {
#ifndef WLED_DISABLE_MQTT
//Check if MQTT Connected, otherwise it will crash the 8266
if (WLED_MQTT_CONNECTED){
char subuf[64];
sprintf_P(subuf, PSTR("%s/motion/%d"), mqttDeviceTopic, (int)bottom);
mqtt->publish(subuf, 0, false, state);
}
#endif
}

void updateSegments() {
Expand Down Expand Up @@ -345,6 +347,7 @@ class Animated_Staircase : public Usermod {

uint16_t getId() { return USERMOD_ID_ANIMATED_STAIRCASE; }

#ifndef WLED_DISABLE_MQTT
/**
* handling of MQTT message
* topic only contains stripped topic (part after /wled/MAC)
Expand Down Expand Up @@ -382,6 +385,7 @@ class Animated_Staircase : public Usermod {
mqtt->subscribe(subuf, 0);
}
}
#endif

void addToJsonState(JsonObject& root) {
JsonObject staircase = root[FPSTR(_name)];
Expand Down
6 changes: 6 additions & 0 deletions usermods/BH1750_v2/usermod_bh1750.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// force the compiler to show a warning to confirm that this file is included
#warning **** Included USERMOD_BH1750 ****

#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif

#pragma once

#include "wled.h"
Expand Down Expand Up @@ -156,6 +160,7 @@ class Usermod_BH1750 : public Usermod
{
lastLux = lux;
lastSend = millis();
#ifndef WLED_DISABLE_MQTT
if (WLED_MQTT_CONNECTED)
{
if (!mqttInitialized)
Expand All @@ -170,6 +175,7 @@ class Usermod_BH1750 : public Usermod
{
DEBUG_PRINTLN(F("Missing MQTT connection. Not publishing data"));
}
#endif
}
}

Expand Down
4 changes: 4 additions & 0 deletions usermods/BME280_v2/usermod_bme280.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// force the compiler to show a warning to confirm that this file is included
#warning **** Included USERMOD_BME280 version 2.0 ****

#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif

#pragma once

#include "wled.h"
Expand Down
2 changes: 2 additions & 0 deletions usermods/Battery/usermod_v2_Battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,15 @@ class UsermodBattery : public Usermod
if (autoOffEnabled && (autoOffThreshold >= batteryLevel))
turnOff();

#ifndef WLED_DISABLE_MQTT
// SmartHome stuff
// still don't know much about MQTT and/or HA
if (WLED_MQTT_CONNECTED) {
char buf[64]; // buffer for snprintf()
snprintf_P(buf, 63, PSTR("%s/voltage"), mqttDeviceTopic);
mqtt->publish(buf, 0, false, String(voltage).c_str());
}
#endif

}

Expand Down
4 changes: 4 additions & 0 deletions usermods/DHT/usermod_dht.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#pragma once

#include "wled.h"
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif


#include <dht_nonblocking.h>

Expand Down
4 changes: 4 additions & 0 deletions usermods/Enclosure_with_OLED_temp_ESP07/usermod.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif

#include "wled.h"
#include <Arduino.h>
#include <U8x8lib.h> // from https://github.com/olikraus/u8g2/
Expand Down
4 changes: 4 additions & 0 deletions usermods/Enclosure_with_OLED_temp_ESP07/usermod_bme280.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif

#include "wled.h"
#include <Arduino.h>
#include <U8x8lib.h> // from https://github.com/olikraus/u8g2/
Expand Down
4 changes: 4 additions & 0 deletions usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,21 @@ class PIRsensorSwitch : public Usermod

void publishMqtt(const char* state)
{
#ifndef WLED_DISABLE_MQTT
//Check if MQTT Connected, otherwise it will crash the 8266
if (WLED_MQTT_CONNECTED) {
char subuf[64];
strcpy(subuf, mqttDeviceTopic);
strcat_P(subuf, PSTR("/motion"));
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.
void publishHomeAssistantAutodiscovery()
{
#ifndef WLED_DISABLE_MQTT
if (WLED_MQTT_CONNECTED) {
StaticJsonDocument<600> doc;
char uid[24], json_str[1024], buf[128];
Expand Down Expand Up @@ -200,6 +203,7 @@ class PIRsensorSwitch : public Usermod

mqtt->publish(buf, 0, true, json_str, payload_size); // do we really need to retain?
}
#endif
}

/**
Expand Down
2 changes: 2 additions & 0 deletions usermods/SN_Photoresistor/usermod_sn_photoresistor.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class Usermod_SN_Photoresistor : public Usermod
{
lastLDRValue = currentLDRValue;

#ifndef WLED_DISABLE_MQTT
if (WLED_MQTT_CONNECTED)
{
char subuf[45];
Expand All @@ -121,6 +122,7 @@ class Usermod_SN_Photoresistor : public Usermod
DEBUG_PRINTLN("Missing MQTT connection. Not publishing data");
}
}
#endif
}

uint16_t getLastLDRValue()
Expand Down
4 changes: 4 additions & 0 deletions usermods/Si7021_MQTT_HA/usermod_si7021_mqtt_ha.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif

#pragma once

// this is remixed from usermod_v2_SensorsToMqtt.h (sensors_to_mqtt usermod)
Expand Down
6 changes: 6 additions & 0 deletions usermods/Temperature/usermod_temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class UsermodTemperature : public Usermod {
return false;
}

#ifndef WLED_DISABLE_MQTT
void publishHomeAssistantAutodiscovery() {
if (!WLED_MQTT_CONNECTED) return;

Expand All @@ -155,6 +156,7 @@ class UsermodTemperature : public Usermod {
mqtt->publish(buf, 0, true, json_str, payload_size);
HApublished = true;
}
#endif

public:

Expand Down Expand Up @@ -212,6 +214,7 @@ class UsermodTemperature : public Usermod {
}
errorCount = 0;

#ifndef WLED_DISABLE_MQTT
if (WLED_MQTT_CONNECTED) {
char subuf[64];
strcpy(subuf, mqttDeviceTopic);
Expand All @@ -227,6 +230,7 @@ class UsermodTemperature : public Usermod {
// publish something else to indicate status?
}
}
#endif
}
}

Expand All @@ -236,6 +240,7 @@ class UsermodTemperature : public Usermod {
*/
//void connected() {}

#ifndef WLED_DISABLE_MQTT
/**
* subscribe to MQTT topic if needed
*/
Expand All @@ -246,6 +251,7 @@ class UsermodTemperature : public Usermod {
publishHomeAssistantAutodiscovery();
}
}
#endif

/*
* API calls te enable data exchange between WLED modules
Expand Down
2 changes: 2 additions & 0 deletions usermods/Wemos_D1_mini+Wemos32_mini_shield/usermod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void userLoop() {
if (temptimer - lastMeasure > 60000)
{
lastMeasure = temptimer;
#ifndef WLED_DISABLE_MQTT
//Check if MQTT Connected, otherwise it will crash the 8266
if (mqtt != nullptr)
{
Expand All @@ -116,6 +117,7 @@ void userLoop() {
t += "/temperature";
mqtt->publish(t.c_str(), 0, true, String(board_temperature).c_str());
}
#endif
}

// Check if we time interval for redrawing passes.
Expand Down
2 changes: 2 additions & 0 deletions usermods/Wemos_D1_mini+Wemos32_mini_shield/usermod_bme280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void userLoop() {
{
lastMeasure = tempTimer;

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

// Check if we time interval for redrawing passes.
Expand Down
2 changes: 2 additions & 0 deletions usermods/boblight/boblight.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class BobLightUsermod : public Usermod {

void enable(bool en) { enabled = en; }

#ifndef WLED_DISABLE_MQTT
/**
* handling of MQTT message
* topic only contains stripped topic (part after /wled/MAC)
Expand Down Expand Up @@ -249,6 +250,7 @@ class BobLightUsermod : public Usermod {
// mqtt->subscribe(subuf, 0);
//}
}
#endif

void addToJsonInfo(JsonObject& root)
{
Expand Down
4 changes: 4 additions & 0 deletions usermods/multi_relay/usermod_multi_relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ class MultiRelay : public Usermod {
static const char _HAautodiscovery[];

void publishMqtt(int relay) {
#ifndef WLED_DISABLE_MQTT
//Check if MQTT Connected, otherwise it will crash the 8266
if (WLED_MQTT_CONNECTED){
char subuf[64];
sprintf_P(subuf, PSTR("%s/relay/%d"), mqttDeviceTopic, relay);
mqtt->publish(subuf, 0, false, _relay[relay].state ? "on" : "off");
}
#endif
}

/**
Expand Down Expand Up @@ -232,6 +234,7 @@ class MultiRelay : public Usermod {

//Functions called by WLED

#ifndef WLED_DISABLE_MQTT
/**
* handling of MQTT message
* topic only contains stripped topic (part after /wled/MAC)
Expand Down Expand Up @@ -313,6 +316,7 @@ class MultiRelay : public Usermod {
mqtt->publish(buf, 0, true, json_str, payload_size);
}
}
#endif

/**
* setup() is called once at boot. WiFi is not yet connected at this point.
Expand Down
4 changes: 4 additions & 0 deletions usermods/sensors_to_mqtt/usermod_v2_SensorsToMqtt.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif

#pragma once

#include "wled.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif

#pragma once

#include "wled.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif

#pragma once

#include "wled.h"
Expand Down
4 changes: 4 additions & 0 deletions usermods/sht/usermod_sht.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif

#pragma once

#include "SHT85.h"
Expand Down
4 changes: 4 additions & 0 deletions usermods/smartnest/usermod_smartnest.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifndef WLED_ENABLE_MQTT
#error "This user mod requires MQTT to be enabled."
#endif

#pragma once

#include "wled.h"
Expand Down
8 changes: 8 additions & 0 deletions wled00/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ void shortPressAction(uint8_t b)
applyPreset(macroButton[b], CALL_MODE_BUTTON_PRESET);
}

#ifndef WLED_DISABLE_MQTT
// publish MQTT message
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
char subuf[64];
sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
mqtt->publish(subuf, 0, false, "short");
}
#endif
}

void longPressAction(uint8_t b)
Expand All @@ -43,12 +45,14 @@ void longPressAction(uint8_t b)
applyPreset(macroLongPress[b], CALL_MODE_BUTTON_PRESET);
}

#ifndef WLED_DISABLE_MQTT
// publish MQTT message
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
char subuf[64];
sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
mqtt->publish(subuf, 0, false, "long");
}
#endif
}

void doublePressAction(uint8_t b)
Expand All @@ -62,12 +66,14 @@ void doublePressAction(uint8_t b)
applyPreset(macroDoublePress[b], CALL_MODE_BUTTON_PRESET);
}

#ifndef WLED_DISABLE_MQTT
// publish MQTT message
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
char subuf[64];
sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
mqtt->publish(subuf, 0, false, "double");
}
#endif
}

bool isButtonPressed(uint8_t i)
Expand Down Expand Up @@ -119,13 +125,15 @@ void handleSwitch(uint8_t b)
}
}

#ifndef WLED_DISABLE_MQTT
// publish MQTT message
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
char subuf[64];
if (buttonType[b] == BTN_TYPE_PIR_SENSOR) sprintf_P(subuf, PSTR("%s/motion/%d"), mqttDeviceTopic, (int)b);
else sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
mqtt->publish(subuf, 0, false, !buttonPressedBefore[b] ? "off" : "on");
}
#endif

buttonLongPressed[b] = buttonPressedBefore[b]; //save the last "long term" switch state
}
Expand Down
Loading

0 comments on commit d78bef7

Please sign in to comment.