You can now change the brightness via MQTT_TOPIC_BRIGHTNESS (by default "pitrix/brightness").

This commit is contained in:
Fabian Schlenz 2019-05-25 20:30:11 +02:00
parent 47ac036390
commit 4df02338e7
3 changed files with 18 additions and 8 deletions

View File

@ -9,6 +9,7 @@
#define LED_TYPE WS2812B #define LED_TYPE WS2812B
#define DATA_PIN 14 #define DATA_PIN 14
#define COLOR_ORDER GRB #define COLOR_ORDER GRB
uint8_t config_brightness = 20; // Can be overwritten via MQTT_TOPIC_BRIGHTNESS
#define NTP_SERVER "pool.ntp.org" #define NTP_SERVER "pool.ntp.org"
#define NTP_INTERVAL 60000 #define NTP_INTERVAL 60000

View File

@ -1,4 +1,4 @@
void fastled_setup() { void fastled_setup() {
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, LED_COUNT).setCorrection(TypicalLEDStrip); FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, LED_COUNT).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(20); FastLED.setBrightness(config_brightness);
} }

23
mqtt.h
View File

@ -3,13 +3,21 @@ long mqtt_last_reconnect_attempt = 0;
void mqtt_callback(char* topic, byte* payload, unsigned int length) { void mqtt_callback(char* topic, byte* payload, unsigned int length) {
payload[length] = '\0'; payload[length] = '\0';
for (int i=0; i<NUM_EFFECTS; i++) { if(strcmp(topic, MQTT_TOPIC_MODE)==0) {
EffectEntry* e = &effects[i]; for (int i=0; i<NUM_EFFECTS; i++) {
if (strcmp(e->name, (char*)payload)==0) { EffectEntry* e = &effects[i];
//Serial.printf("Effect found in mqtt_callback: %p\n", (void *)&e->effect); if (strcmp(e->name, (char*)payload)==0) {
current_effect = e->effect; //Serial.printf("Effect found in mqtt_callback: %p\n", (void *)&e->effect);
clear(); current_effect = e->effect;
return; 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)) { if (mqtt_client.connect(client_id, MQTT_USER, MQTT_PASS)) {
LOGln("MQTT * Connected."); LOGln("MQTT * Connected.");
mqtt_client.subscribe(MQTT_TOPIC_MODE); mqtt_client.subscribe(MQTT_TOPIC_MODE);
mqtt_client.subscribe(MQTT_TOPIC_BRIGHTNESS);
mqtt_client.publish(MQTT_TOPIC_STATUS, "ONLINE"); mqtt_client.publish(MQTT_TOPIC_STATUS, "ONLINE");
} }
return mqtt_client.connected(); return mqtt_client.connected();