Browse Source

Mock white color support via MQTT

fastled
Xose Pérez 7 years ago
parent
commit
49a3bb2029
2 changed files with 28 additions and 3 deletions
  1. +1
    -0
      code/espurna/config/general.h
  2. +27
    -3
      code/espurna/light.ino

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

@ -235,6 +235,7 @@ PROGMEM const char* const custom_reset_string[] = {
#define MQTT_TOPIC_RELAY "relay"
#define MQTT_TOPIC_LED "led"
#define MQTT_TOPIC_COLOR "color"
#define MQTT_TOPIC_WHITE "white"
#define MQTT_TOPIC_BRIGHTNESS "brightness"
#define MQTT_TOPIC_COLORTEMP "color/temperature"
#define MQTT_TOPIC_BUTTON "button"


+ 27
- 3
code/espurna/light.ino View File

@ -247,12 +247,29 @@ void lightColor(bool save, bool forward) {
// Report color & brightness to MQTT broker
if (forward) {
// Color
char rgb[8];
_color_array2rgb(_lightColor, 1.0, rgb);
mqttSend(MQTT_TOPIC_COLOR, rgb);
char buffer[5];
sprintf(buffer, "%d", (int) (brightness * LIGHT_MAX_BRIGHTNESS));
mqttSend(MQTT_TOPIC_BRIGHTNESS, buffer);
if ((_lightColor[0] == _lightColor[1]) & (_lightColor[1] == _lightColor[2])) {
// White
char buffer[5];
sprintf(buffer, "%d", (int) _lightColor[0]);
mqttSend(MQTT_TOPIC_WHITE, buffer);
} else {
// Brightness
char buffer[5];
sprintf(buffer, "%d", (int) (brightness * LIGHT_MAX_BRIGHTNESS));
mqttSend(MQTT_TOPIC_BRIGHTNESS, buffer);
}
}
// Report color to WS clients
@ -303,6 +320,7 @@ void lightMQTTCallback(unsigned int type, const char * topic, const char * paylo
mqttSubscribe(MQTT_TOPIC_BRIGHTNESS);
mqttSubscribe(MQTT_TOPIC_COLORTEMP);
mqttSubscribe(MQTT_TOPIC_COLOR);
mqttSubscribe(MQTT_TOPIC_WHITE);
}
if (type == MQTT_MESSAGE_EVENT) {
@ -324,6 +342,12 @@ void lightMQTTCallback(unsigned int type, const char * topic, const char * paylo
lightColor(true, mqttForward());
}
// White
if (t.equals(MQTT_TOPIC_WHITE)) {
parseColor(payload);
lightColor(true, mqttForward());
}
// Brightness
if (t.equals(MQTT_TOPIC_BRIGHTNESS)) {
brightness = (float) atoi(payload) / LIGHT_MAX_BRIGHTNESS;


Loading…
Cancel
Save