diff --git a/config.sample.h b/config.sample.h index 63fe159..769d5db 100644 --- a/config.sample.h +++ b/config.sample.h @@ -9,6 +9,7 @@ #define LED_TYPE WS2812B #define DATA_PIN 14 #define COLOR_ORDER GRB +uint8_t config_brightness = 20; // Can be overwritten via MQTT_TOPIC_BRIGHTNESS #define NTP_SERVER "pool.ntp.org" #define NTP_INTERVAL 60000 diff --git a/fastled.ino b/fastled.ino index 28ca0ba..a009a88 100644 --- a/fastled.ino +++ b/fastled.ino @@ -1,4 +1,4 @@ void fastled_setup() { FastLED.addLeds(leds, LED_COUNT).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(20); + FastLED.setBrightness(config_brightness); } diff --git a/mqtt.h b/mqtt.h index f066ca1..220371b 100644 --- a/mqtt.h +++ b/mqtt.h @@ -3,13 +3,21 @@ long mqtt_last_reconnect_attempt = 0; void mqtt_callback(char* topic, byte* payload, unsigned int length) { payload[length] = '\0'; - for (int i=0; iname, (char*)payload)==0) { - //Serial.printf("Effect found in mqtt_callback: %p\n", (void *)&e->effect); - current_effect = e->effect; - clear(); - return; + if(strcmp(topic, MQTT_TOPIC_MODE)==0) { + for (int i=0; iname, (char*)payload)==0) { + //Serial.printf("Effect found in mqtt_callback: %p\n", (void *)&e->effect); + current_effect = e->effect; + clear(); + return; + } + } + } else if (strcmp(topic, MQTT_TOPIC_BRIGHTNESS)==0) { + long new_value = atol((char *) payload); + if (new_value > 0 && new_value <= 255) { + config_brightness = new_value; + FastLED.setBrightness(config_brightness); } } } @@ -21,6 +29,7 @@ boolean mqtt_connect() { if (mqtt_client.connect(client_id, MQTT_USER, MQTT_PASS)) { LOGln("MQTT * Connected."); mqtt_client.subscribe(MQTT_TOPIC_MODE); + mqtt_client.subscribe(MQTT_TOPIC_BRIGHTNESS); mqtt_client.publish(MQTT_TOPIC_STATUS, "ONLINE"); } return mqtt_client.connected();