Added support for MQTT topics "pitrix/cycle_time" (sets the delay between effect changes in 'cycle' mode) and "pitrix/reboot" (send anywthing there to have pitrix reboot).

This commit is contained in:
Fabian Schlenz 2019-05-25 23:38:41 +02:00
parent 10098f56fb
commit 7a7c17ede5
2 changed files with 12 additions and 0 deletions

View File

@ -22,6 +22,9 @@ uint8_t config_brightness = 20; // Can be overwritten via MQTT_TOPIC_BRIGHTNESS
#define MQTT_TOPIC_MODE "pitrix/mode"
#define MQTT_TOPIC_STATUS "pitrix/status"
#define MQTT_TOPIC_LOG "pitrix/log"
#define MQTT_TOPIC_BRIGHTNESS "pitrix/brightness"
#define MQTT_TOPIC_EFFECT_CYCLE_TIME "pitrix/cycle_time"
#define MQTT_TOPIC_REBOOT "pitrix/reboot"
#define HOSTNAME "pitrix-%08X"
#define OTA_STARTUP_DELAY 5 // How many seconds to wait at startup. Set to 0 to disable.

9
mqtt.h
View File

@ -19,6 +19,13 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) {
config_brightness = new_value;
FastLED.setBrightness(config_brightness);
}
} else if (strcmp(topic, MQTT_TOPIC_EFFECT_CYCLE_TIME)==0) {
long new_value = atol((char *) payload);
if (new_value > 0) {
config_effect_cycle_time = new_value;
}
} else if (strcmp(topic, MQTT_TOPIC_REBOOT)==0) {
ESP.restart();
}
}
@ -30,6 +37,8 @@ boolean mqtt_connect() {
LOGln("MQTT * Connected.");
mqtt_client.subscribe(MQTT_TOPIC_MODE);
mqtt_client.subscribe(MQTT_TOPIC_BRIGHTNESS);
mqtt_client.subscribe(MQTT_TOPIC_EFFECT_CYCLE_TIME);
mqtt_client.subscribe(MQTT_TOPIC_REBOOT);
mqtt_client.publish(MQTT_TOPIC_STATUS, "ONLINE");
}
return mqtt_client.connected();