From d6297ae9543b32d60f1a66cd4eafae0220a32fb8 Mon Sep 17 00:00:00 2001 From: Debashish Sahu <debashish.sahu@gmail.com> Date: Fri, 8 Mar 2019 14:46:44 -0500 Subject: [PATCH 1/5] LWT fix - fix LWT track #340 - fix PubSubClient related bug --- Arduino/McLighting/definitions.h | 3 ++- Arduino/McLighting/request_handlers.h | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Arduino/McLighting/definitions.h b/Arduino/McLighting/definitions.h index dc02cc5..835cbee 100644 --- a/Arduino/McLighting/definitions.h +++ b/Arduino/McLighting/definitions.h @@ -66,9 +66,10 @@ uint32_t autoParams[][4] = { // color, speed, mode, duration (milliseconds) #if defined(ENABLE_MQTT) or defined(ENABLE_AMQTT) const char mqtt_will_topic[] = HOSTNAME "/status"; - const char mqtt_will_payload[] = "ONLINE"; + const char mqtt_will_payload[] = "OFFLINE"; const char mqtt_intopic[] = HOSTNAME "/in"; const char mqtt_outtopic[] = HOSTNAME "/out"; + bool mqtt_lwt_boot_flag = true; #ifdef ENABLE_MQTT #define MQTT_MAX_PACKET_SIZE 512 diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index 4f0f445..bb38f33 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -996,7 +996,7 @@ void checkForRequests() { mqtt_reconnect_retries++; DBG_OUTPUT_PORT.printf("Attempting MQTT connection %d / %d ...\n", mqtt_reconnect_retries, MQTT_MAX_RECONNECT_TRIES); // Attempt to connect - if (mqtt_client.connect(mqtt_clientid, mqtt_user, mqtt_pass, mqtt_will_topic.c_str(), 2, true, mqtt_will_payload, true)) { + if (mqtt_client.connect(mqtt_clientid, mqtt_user, mqtt_pass, mqtt_will_topic, 2, true, mqtt_will_payload, true)) { DBG_OUTPUT_PORT.println("MQTT connected!"); // Once connected, publish an announcement... char * message = new char[18 + strlen(HOSTNAME) + 1]; @@ -1005,6 +1005,11 @@ void checkForRequests() { mqtt_client.publish(mqtt_outtopic, message); // ... and resubscribe mqtt_client.subscribe(mqtt_intopic, qossub); + if(mqtt_lwt_boot_flag) + { + mqtt_client.publish(mqtt_will_topic, "ONLINE"); + mqtt_lwt_boot_flag = false; + } #ifdef ENABLE_HOMEASSISTANT ha_send_data.detach(); mqtt_client.subscribe(mqtt_ha_state_in, qossub); @@ -1103,6 +1108,11 @@ void checkForRequests() { //Subscribe uint16_t packetIdSub1 = amqttClient.subscribe((char *)mqtt_intopic, qossub); DBG_OUTPUT_PORT.printf("Subscribing at QoS %d, packetId: ", qossub); DBG_OUTPUT_PORT.println(packetIdSub1); + if(mqtt_lwt_boot_flag) + { + amqttClient.publish(mqtt_will_topic, qospub, false, "ONLINE"); + mqtt_lwt_boot_flag = false; + } #ifdef ENABLE_HOMEASSISTANT ha_send_data.detach(); uint16_t packetIdSub2 = amqttClient.subscribe((char *)mqtt_ha_state_in, qossub); From 5b76af1424b0e06a104e91d6da77816f1c2b8087 Mon Sep 17 00:00:00 2001 From: Debashish Sahu <debashish.sahu@gmail.com> Date: Fri, 8 Mar 2019 14:59:20 -0500 Subject: [PATCH 2/5] Update README.md - Added to todo #348 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 73b89d5..0308569 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ I hope I didn't miss any sources and mentioned every author. In case I forgot so - [ ] IR remote support [issue](https://github.com/toblum/McLightingUI/issues/3) - [ ] Make number of pixels, MQTT and PIN configurable via front end [Issue](https://github.com/toblum/McLighting/issues/93) and [Issue](https://github.com/toblum/McLighting/issues/272) - [ ] Make switching between methods: Adafruit NeoPixel, NeoPixelBus's DMA, NeoPixelBus's UART1 and NeoPixelBus's UART2 via REST API +- [ ] Add Espalexa library support [Issue](https://github.com/toblum/McLighting/issues/348) - [x] Make number of pixels, RGB Order and PIN configurable via REST API - [x] Bundle webpages instead of SPIFFS [Issue](https://github.com/toblum/McLighting/issues/93) - [x] Music visualizer / Bring back ArtNet [Issue](https://github.com/toblum/McLighting/issues/111) From 2806bb09105ac7c7efe6d14d634300e01d91a46b Mon Sep 17 00:00:00 2001 From: Debashish Sahu <debashish.sahu@gmail.com> Date: Sat, 16 Mar 2019 11:26:25 -0400 Subject: [PATCH 3/5] Update request_handlers.h --- Arduino/McLighting/request_handlers.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index bb38f33..db66022 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -1049,9 +1049,10 @@ void checkForRequests() { unsigned int msg_len = measureJson(json) + 1; char buffer[msg_len]; serializeJson(json, buffer, sizeof(buffer)); - mqtt->beginPublish(String("homeassistant/light/" + String(HOSTNAME) + "/config").c_str(), msg_len, true); - mqtt->write((const uint8_t*)buffer, msg_len); - mqtt->endPublish(); + DBG_OUTPUT_PORT.println(buffer); + mqtt_client.beginPublish(String("homeassistant/light/" + String(HOSTNAME) + "/config").c_str(), msg_len-1, true); + mqtt_client.write((const uint8_t*)buffer, msg_len-1); + mqtt_client.endPublish(); #endif #endif From b15f013019439cb7fbb33854ce2a01da07ff928e Mon Sep 17 00:00:00 2001 From: Debashish Sahu <debashish.sahu@gmail.com> Date: Sat, 16 Mar 2019 12:50:23 -0400 Subject: [PATCH 4/5] bug-fixes - UART 1 and 0 were mixed up - LWT revisit - Custom mode needs index --- Arduino/McLighting/McLighting.ino | 18 +++++++++--------- Arduino/McLighting/request_handlers.h | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Arduino/McLighting/McLighting.ino b/Arduino/McLighting/McLighting.ino index 89a63ae..ee76179 100644 --- a/Arduino/McLighting/McLighting.ino +++ b/Arduino/McLighting/McLighting.ino @@ -99,16 +99,16 @@ WS2812FX* strip; #endif #ifdef USE_WS2812FX_UART1 // Uses UART1: GPIO1/TXD0/TX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods #ifndef LED_TYPE_WS2811 - NeoEsp8266Uart0800KbpsMethod* dma; //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) + NeoEsp8266Uart1800KbpsMethod* dma; //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) #else - NeoEsp8266Uart0400KbpsMethod* dma; //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) + NeoEsp8266Uart1400KbpsMethod* dma; //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) #endif #endif #ifdef USE_WS2812FX_UART2 // Uses UART2: GPIO2/TXD1/D4, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods #ifndef LED_TYPE_WS2811 - NeoEsp8266Uart1800KbpsMethod* dma; //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) + NeoEsp8266Uart0800KbpsMethod* dma; //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) #else - NeoEsp8266Uart1400KbpsMethod* dma; //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) + NeoEsp8266Uart0400KbpsMethod* dma; //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) #endif #endif @@ -123,16 +123,16 @@ void initDMA(uint16_t stripSize = NUMLEDS){ #endif #ifdef USE_WS2812FX_UART1 // Uses UART1: GPIO1/TXD0/TX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods #ifndef LED_TYPE_WS2811 - dma = new NeoEsp8266Uart0800KbpsMethod(stripSize, 3); //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) + dma = new NeoEsp8266Uart1800KbpsMethod(stripSize, 3); //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) #else - dma = new NeoEsp8266Uart0400KbpsMethod(stripSize, 3); //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) + dma = new NeoEsp8266Uart1400KbpsMethod(stripSize, 3); //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) #endif #endif #ifdef USE_WS2812FX_UART2 // Uses UART2: GPIO2/TXD1/D4, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods #ifndef LED_TYPE_WS2811 - dma = new NeoEsp8266Uart1800KbpsMethod(stripSize, 3); //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) + dma = new NeoEsp8266Uart0800KbpsMethod(stripSize, 3); //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) #else - dma = new NeoEsp8266Uart1400KbpsMethod(stripSize, 3); //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) + dma = new NeoEsp8266Uart0400KbpsMethod(stripSize, 3); //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) #endif #endif dma->Initialize(); @@ -293,7 +293,7 @@ void initStrip(uint16_t stripSize = WS2812FXStripSettings.stripSize, neoPixelTyp strip->setColor(main_color.red, main_color.green, main_color.blue); strip->setOptions(0, GAMMA); // We only have one WS2812FX segment, set color to human readable GAMMA correction #ifdef CUSTOM_WS2812FX_ANIMATIONS - strip->setCustomMode(F("Fire 2012"), myCustomEffect); + strip->setCustomMode(0, F("Fire 2012"), myCustomEffect); #endif strip->start(); if(mode != HOLD) mode = SET_MODE; diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index db66022..d3878e6 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -999,7 +999,7 @@ void checkForRequests() { if (mqtt_client.connect(mqtt_clientid, mqtt_user, mqtt_pass, mqtt_will_topic, 2, true, mqtt_will_payload, true)) { DBG_OUTPUT_PORT.println("MQTT connected!"); // Once connected, publish an announcement... - char * message = new char[18 + strlen(HOSTNAME) + 1]; + char message[18 + strlen(HOSTNAME) + 1]; strcpy(message, "McLighting ready: "); strcat(message, HOSTNAME); mqtt_client.publish(mqtt_outtopic, message); @@ -1008,7 +1008,7 @@ void checkForRequests() { if(mqtt_lwt_boot_flag) { mqtt_client.publish(mqtt_will_topic, "ONLINE"); - mqtt_lwt_boot_flag = false; + //mqtt_lwt_boot_flag = false; } #ifdef ENABLE_HOMEASSISTANT ha_send_data.detach(); @@ -1102,12 +1102,12 @@ void checkForRequests() { DBG_OUTPUT_PORT.println("Connected to MQTT."); DBG_OUTPUT_PORT.print("Session present: "); DBG_OUTPUT_PORT.println(sessionPresent); - char * message = new char[18 + strlen(HOSTNAME) + 1]; + char message[18 + strlen(HOSTNAME) + 1]; strcpy(message, "McLighting ready: "); strcat(message, HOSTNAME); amqttClient.publish(mqtt_outtopic, qospub, false, message); //Subscribe - uint16_t packetIdSub1 = amqttClient.subscribe((char *)mqtt_intopic, qossub); + uint16_t packetIdSub1 = amqttClient.subscribe(mqtt_intopic, qossub); DBG_OUTPUT_PORT.printf("Subscribing at QoS %d, packetId: ", qossub); DBG_OUTPUT_PORT.println(packetIdSub1); if(mqtt_lwt_boot_flag) { From d6be20546ade208e6e3f8b4c05320ac91a90c195 Mon Sep 17 00:00:00 2001 From: Debashish Sahu <debashish.sahu@gmail.com> Date: Mon, 18 Mar 2019 12:29:55 -0400 Subject: [PATCH 5/5] version bump 2.2.3 --- Arduino/McLighting/version.h | 2 +- Arduino/McLighting/version_info.ino | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Arduino/McLighting/version.h b/Arduino/McLighting/version.h index 08832bb..b16ad31 100644 --- a/Arduino/McLighting/version.h +++ b/Arduino/McLighting/version.h @@ -1 +1 @@ -#define SKETCH_VERSION "2.2.2" \ No newline at end of file +#define SKETCH_VERSION "2.2.3" \ No newline at end of file diff --git a/Arduino/McLighting/version_info.ino b/Arduino/McLighting/version_info.ino index 2764ee5..ecd38e1 100644 --- a/Arduino/McLighting/version_info.ino +++ b/Arduino/McLighting/version_info.ino @@ -82,4 +82,10 @@ * 7 Mar 2019 v 2.2.2 * - Add compiler flag for WS2811 strips #define LED_TYPE_WS2811 * - Hotfix #351 + * + * 18 Mar 2019 v 2.2.3 (mostly bugfix) + * - PubSubClient related bug fixed + * - UART 1 and 0 were mixed up + * - LWT revisit + * - Custom mode needs index */