diff --git a/include/led.hpp b/include/led.hpp index c95b925..cc59848 100644 --- a/include/led.hpp +++ b/include/led.hpp @@ -204,8 +204,16 @@ void Led::shiftColumnToRight() { //------------------------------------------------------------------------------ void Led::setState(bool newState) { + static bool firstRun = true; static uint8_t oldBrightness[3]; + if (firstRun) { + for (uint8_t i = 0; i < 3; i++) { + oldBrightness[i] = G.color[i].B * 100; + } + firstRun = false; + } + if (newState) { for (uint8_t i = 0; i < 3; i++) { G.color[i].B = oldBrightness[i] / 100.f; diff --git a/include/mqtt.hpp b/include/mqtt.hpp index c4eaf88..b2a80ab 100644 --- a/include/mqtt.hpp +++ b/include/mqtt.hpp @@ -182,15 +182,15 @@ None void Mqtt::callback(char *topic, byte *payload, unsigned int length) { StaticJsonDocument<512> doc; - Serial.print("Received message ["); - Serial.print(topic); - Serial.print("] "); - char msg[length + 1]; // Convert payload to a null-terminated string memcpy(msg, payload, length); msg[length] = '\0'; + Serial.print("Received message ["); + Serial.print(msg); + Serial.print("] "); + // Deserialize JSON DeserializationError error = deserializeJson(doc, msg); @@ -204,8 +204,10 @@ void Mqtt::callback(char *topic, byte *payload, unsigned int length) { if (doc.containsKey("state")) { const char *state = doc["state"]; if (!strcmp(state, "ON")) { + Serial.println("ON"); led.setState(true); } else if (!strcmp(state, "OFF")) { + Serial.println("OFF"); led.setState(false); } } diff --git a/package.json b/package.json index 411dfbd..2b75e15 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "multilayout-esp-wordclock", - "version": "4.0.0", + "version": "4.0.1", "description": "For building a german layouted wordclock with an esp8266 module and WS2812/SK2812.", "license": "BSD-3-Clause", "contributors": [