Browse Source

Added support for MQTT_USE_SETTER in leds module

fastled
Xose Pérez 8 years ago
parent
commit
8cf10eee90
2 changed files with 10 additions and 3 deletions
  1. +1
    -0
      code/src/config/general.h
  2. +9
    -3
      code/src/led.ino

+ 1
- 0
code/src/config/general.h View File

@ -68,6 +68,7 @@
#define MQTT_KEEPALIVE 30
#define MQTT_RECONNECT_DELAY 10000
#define MQTT_RELAY_TOPIC "/relay"
#define MQTT_LED_TOPIC "/led"
#define MQTT_IP_TOPIC "/ip"
#define MQTT_VERSION_TOPIC "/version"
#define MQTT_FSVERSION_TOPIC "/fsversion"


+ 9
- 3
code/src/led.ino View File

@ -59,17 +59,23 @@ void ledMQTTCallback(unsigned int type, const char * topic, const char * payload
static bool isFirstMessage = true;
String mqttSetter = getSetting("mqttSetter", MQTT_USE_SETTER);
if (type == MQTT_CONNECT_EVENT) {
mqttSubscribe("/led/#");
char buffer[strlen(MQTT_LED_TOPIC) + mqttSetter.length() + 3];
sprintf(buffer, "%s/+%s", MQTT_LED_TOPIC, mqttSetter.c_str());
mqttSubscribe(buffer);
}
if (type == MQTT_MESSAGE_EVENT) {
// Match topic
if (memcmp("/led/", topic, 5) != 0) return;
String t = String(topic);
if (!t.startsWith(MQTT_LED_TOPIC)) return;
if (!t.endsWith(mqttSetter)) return;
// Get led ID
unsigned int ledID = topic[strlen(topic)-1] - '0';
unsigned int ledID = topic[strlen(MQTT_LED_TOPIC)+1] - '0';
if (ledID >= ledCount()) ledID = 0;
// get value


Loading…
Cancel
Save