From 7e9bfac8f71a1ff1f857491862ad3bb01bf3de3f Mon Sep 17 00:00:00 2001 From: Debashish Sahu Date: Tue, 11 Dec 2018 10:30:31 -0500 Subject: [PATCH 1/5] HA 0.84 autodiscovery update Changes as per https://github.com/home-assistant/home-assistant/pull/18227 and suggestion from https://github.com/toblum/McLighting/issues/286 --- Arduino/McLighting/definitions.h | 6 +++++- Arduino/McLighting/request_handlers.h | 14 ++++++++++++-- platformio.ini | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Arduino/McLighting/definitions.h b/Arduino/McLighting/definitions.h index 10440e8..44bc8eb 100644 --- a/Arduino/McLighting/definitions.h +++ b/Arduino/McLighting/definitions.h @@ -27,6 +27,10 @@ const char HOSTNAME[] = "McLighting01"; // Friedly hostname uint8_t _sn[4] = {255,255,255,0}; #endif +#ifdef MQTT_HOME_ASSISTANT_SUPPORT + #define MQTT_HOME_ASSISTANT_0_84_SUPPORT // Comment if using HA version < 0.84 +#endif + #if defined(USE_WS2812FX_DMA) and defined(USE_WS2812FX_UART) #error "Cant have both DMA and UART method." #endif @@ -50,7 +54,7 @@ uint32_t autoParams[][4] = { // color, speed, mode, duration (seconds) #if defined(ENABLE_MQTT) or defined(ENABLE_AMQTT) #ifdef ENABLE_MQTT - #define MQTT_MAX_PACKET_SIZE 512 + #define MQTT_MAX_PACKET_SIZE 2048 #define MQTT_MAX_RECONNECT_TRIES 4 int mqtt_reconnect_retries = 0; diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index ee2b571..5e0949a 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -936,10 +936,15 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght ha_send_data.detach(); mqtt_client.subscribe(mqtt_ha_state_in.c_str(), qossub); #ifdef MQTT_HOME_ASSISTANT_SUPPORT - DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip.getModeCount()) + JSON_OBJECT_SIZE(11)); + DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip.getModeCount()) + JSON_OBJECT_SIZE(12)); JsonObject json = jsonBuffer.to(); json["name"] = HOSTNAME; + #ifdef MQTT_HOME_ASSISTANT_0_84_SUPPORT + json["platform"] = "mqtt"; + json["schema"] = "json"; + #else json["platform"] = "mqtt_json"; + #endif json["state_topic"] = mqtt_ha_state_out; json["command_topic"] = mqtt_ha_state_in; json["on_command_type"] = "first"; @@ -1016,10 +1021,15 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght uint16_t packetIdSub2 = amqttClient.subscribe((char *)mqtt_ha_state_in.c_str(), qossub); DBG_OUTPUT_PORT.printf("Subscribing at QoS %d, packetId: ", qossub); DBG_OUTPUT_PORT.println(packetIdSub2); #ifdef MQTT_HOME_ASSISTANT_SUPPORT - DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip.getModeCount()) + JSON_OBJECT_SIZE(11)); + DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip.getModeCount()) + JSON_OBJECT_SIZE(12)); JsonObject json = jsonBuffer.to(); json["name"] = HOSTNAME; + #ifdef MQTT_HOME_ASSISTANT_0_84_SUPPORT + json["platform"] = "mqtt"; + json["schema"] = "json"; + #else json["platform"] = "mqtt_json"; + #endif json["state_topic"] = mqtt_ha_state_out; json["command_topic"] = mqtt_ha_state_in; json["on_command_type"] = "first"; diff --git a/platformio.ini b/platformio.ini index 192f8ae..26fa778 100644 --- a/platformio.ini +++ b/platformio.ini @@ -17,6 +17,8 @@ description = The ESP8266 based multi-client lighting gadget [common] build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH + -DMQTT_MAX_PACKET_SIZE=2048 ; PubSubClient Specific flags + -w ; supress all warnings monitor_speed = 115200 board_build.flash_mode = dout upload_speed = 115200 From 153d481607cd680898cc8cfa9d607e30cd59ebe8 Mon Sep 17 00:00:00 2001 From: Debashish Sahu Date: Tue, 11 Dec 2018 11:59:39 -0500 Subject: [PATCH 2/5] Update version.h --- Arduino/McLighting/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Arduino/McLighting/version.h b/Arduino/McLighting/version.h index 3f7b186..293818a 100644 --- a/Arduino/McLighting/version.h +++ b/Arduino/McLighting/version.h @@ -1 +1 @@ -#define SKETCH_VERSION "2.1.7" +#define SKETCH_VERSION "2.1.8" From 79393df8a9b8f64aba6a728637e6159bafc8ba1e Mon Sep 17 00:00:00 2001 From: Debashish Sahu Date: Tue, 11 Dec 2018 12:01:50 -0500 Subject: [PATCH 3/5] Update version_info.ino --- Arduino/McLighting/version_info.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Arduino/McLighting/version_info.ino b/Arduino/McLighting/version_info.ino index 72639bc..6a51496 100644 --- a/Arduino/McLighting/version_info.ino +++ b/Arduino/McLighting/version_info.ino @@ -31,4 +31,7 @@ * - rethink ESP.getChipId implementaion * - check ArduinoJSON version * - Try restting prevmode as suggested in #276 + * + * 11 Dec 2018 v 2.1.8 + * - Fix Auto-Discovery for HA version >= 0.84 #286 */ From 181ff7f1d7ac779ce0ab8b8a0bbac193e72b5f90 Mon Sep 17 00:00:00 2001 From: Debashish Sahu Date: Tue, 11 Dec 2018 22:24:46 -0500 Subject: [PATCH 4/5] fix #283 For some reason defining the exact size is causing mqtt_user and mqtt_pass are not stored in SPIFFs. Dynamic assignment should take care of this. Should take care of expception 28 --- Arduino/McLighting/request_handlers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index 5e0949a..bb10c1f 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -1196,7 +1196,7 @@ bool writeConfigFS(bool saveConfig){ //FS save updateFS = true; DBG_OUTPUT_PORT.print("Saving config: "); - DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(4)); + DynamicJsonDocument jsonBuffer; JsonObject json = jsonBuffer.to(); json["mqtt_host"] = mqtt_host; json["mqtt_port"] = mqtt_port; @@ -1265,7 +1265,7 @@ bool writeStateFS(){ updateFS = true; //save the strip state to FS JSON DBG_OUTPUT_PORT.print("Saving cfg: "); - DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(7)); + DynamicJsonDocument jsonBuffer; JsonObject json = jsonBuffer.to(); json["mode"] = static_cast(mode); json["strip_mode"] = (int) strip.getMode(); From 8e77f3796611af7d4b8f54a4f4adf0435384d672 Mon Sep 17 00:00:00 2001 From: Debashish Sahu Date: Tue, 11 Dec 2018 22:28:03 -0500 Subject: [PATCH 5/5] Update version_info.ino --- Arduino/McLighting/version_info.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/Arduino/McLighting/version_info.ino b/Arduino/McLighting/version_info.ino index 6a51496..d13e1d7 100644 --- a/Arduino/McLighting/version_info.ino +++ b/Arduino/McLighting/version_info.ino @@ -34,4 +34,5 @@ * * 11 Dec 2018 v 2.1.8 * - Fix Auto-Discovery for HA version >= 0.84 #286 + * - Fix #283 */