You can now change the brightness via MQTT_TOPIC_BRIGHTNESS (by default "pitrix/brightness").
This commit is contained in:
parent
47ac036390
commit
4df02338e7
@ -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
|
||||
|
@ -1,4 +1,4 @@
|
||||
void fastled_setup() {
|
||||
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, LED_COUNT).setCorrection(TypicalLEDStrip);
|
||||
FastLED.setBrightness(20);
|
||||
FastLED.setBrightness(config_brightness);
|
||||
}
|
||||
|
9
mqtt.h
9
mqtt.h
@ -3,6 +3,7 @@ long mqtt_last_reconnect_attempt = 0;
|
||||
|
||||
void mqtt_callback(char* topic, byte* payload, unsigned int length) {
|
||||
payload[length] = '\0';
|
||||
if(strcmp(topic, MQTT_TOPIC_MODE)==0) {
|
||||
for (int i=0; i<NUM_EFFECTS; i++) {
|
||||
EffectEntry* e = &effects[i];
|
||||
if (strcmp(e->name, (char*)payload)==0) {
|
||||
@ -12,6 +13,13 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean mqtt_connect() {
|
||||
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user