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);
} }

9
mqtt.h
View File

@ -3,6 +3,7 @@ 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';
if(strcmp(topic, MQTT_TOPIC_MODE)==0) {
for (int i=0; i<NUM_EFFECTS; i++) { for (int i=0; i<NUM_EFFECTS; i++) {
EffectEntry* e = &effects[i]; EffectEntry* e = &effects[i];
if (strcmp(e->name, (char*)payload)==0) { if (strcmp(e->name, (char*)payload)==0) {
@ -12,6 +13,13 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) {
return; 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() { boolean mqtt_connect() {
@ -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();