Skip to content

Commit b85dd55

Browse files
authored
Merge pull request #468 from dbambus/main
FIX for Firstrun MQTT Message
2 parents 063cf74 + 929056c commit b85dd55

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

include/led.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,16 @@ void Led::shiftColumnToRight() {
204204
//------------------------------------------------------------------------------
205205

206206
void Led::setState(bool newState) {
207+
static bool firstRun = true;
207208
static uint8_t oldBrightness[3];
208209

210+
if (firstRun) {
211+
for (uint8_t i = 0; i < 3; i++) {
212+
oldBrightness[i] = G.color[i].B * 100;
213+
}
214+
firstRun = false;
215+
}
216+
209217
if (newState) {
210218
for (uint8_t i = 0; i < 3; i++) {
211219
G.color[i].B = oldBrightness[i] / 100.f;

include/mqtt.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ None
182182
void Mqtt::callback(char *topic, byte *payload, unsigned int length) {
183183
StaticJsonDocument<512> doc;
184184

185-
Serial.print("Received message [");
186-
Serial.print(topic);
187-
Serial.print("] ");
188-
189185
char msg[length + 1];
190186
// Convert payload to a null-terminated string
191187
memcpy(msg, payload, length);
192188
msg[length] = '\0';
193189

190+
Serial.print("Received message [");
191+
Serial.print(msg);
192+
Serial.print("] ");
193+
194194
// Deserialize JSON
195195
DeserializationError error = deserializeJson(doc, msg);
196196

@@ -204,8 +204,10 @@ void Mqtt::callback(char *topic, byte *payload, unsigned int length) {
204204
if (doc.containsKey("state")) {
205205
const char *state = doc["state"];
206206
if (!strcmp(state, "ON")) {
207+
Serial.println("ON");
207208
led.setState(true);
208209
} else if (!strcmp(state, "OFF")) {
210+
Serial.println("OFF");
209211
led.setState(false);
210212
}
211213
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "multilayout-esp-wordclock",
3-
"version": "4.0.0",
3+
"version": "4.0.1",
44
"description": "For building a german layouted wordclock with an esp8266 module and WS2812/SK2812.",
55
"license": "BSD-3-Clause",
66
"contributors": [

0 commit comments

Comments
 (0)