From 35b989e98d3e625e1d08b9339f92461cd7f4ce74 Mon Sep 17 00:00:00 2001 From: Debashish Sahu Date: Wed, 12 Dec 2018 20:46:56 -0500 Subject: [PATCH] e131 update + HA: sendState() update - Stop strip when e131 is sent - sendState() needs extra memory for jsonBuffer - sensState() effect can be sent directly instead of copying from PROGMEM --- Arduino/McLighting/McLighting.ino | 2 -- Arduino/McLighting/request_handlers.h | 19 +++++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Arduino/McLighting/McLighting.ino b/Arduino/McLighting/McLighting.ino index eb556a0..deb5f0d 100644 --- a/Arduino/McLighting/McLighting.ino +++ b/Arduino/McLighting/McLighting.ino @@ -357,8 +357,6 @@ void setup() { strcpy(mqtt_user, custom_mqtt_user.getValue()); strcpy(mqtt_pass, custom_mqtt_pass.getValue()); - Serial.printf(">>>>>%s %s %s %s<<<<<<<<<\n", mqtt_host, mqtt_port, mqtt_user, mqtt_pass); - //save the custom parameters to FS #if defined(ENABLE_STATE_SAVE_SPIFFS) and (defined(ENABLE_MQTT) or defined(ENABLE_AMQTT)) (writeConfigFS(shouldSaveConfig)) ? DBG_OUTPUT_PORT.println("WiFiManager config FS Save success!"): DBG_OUTPUT_PORT.println("WiFiManager config FS Save failure!"); diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index a0e2eb0..c15e9f3 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -304,6 +304,7 @@ void setModeByStateString(String saved_state_string) { void handleE131NamedMode(String str_mode) { exit_func = true; if (str_mode.startsWith("=e131")) { + if(strip.isRunning()) strip.stop(); mode = E131; #ifdef ENABLE_HOMEASSISTANT stateOn = true; @@ -812,7 +813,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght } void sendState() { - const size_t bufferSize = JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(6); + const size_t bufferSize = JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(6) + 500; DynamicJsonDocument jsonBuffer(bufferSize); JsonObject root = jsonBuffer.to(); @@ -828,9 +829,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght root["speed"] = ws2812fx_speed; - char modeName[30]; - strncpy_P(modeName, (PGM_P)strip.getModeName(strip.getMode()), sizeof(modeName)); // copy from progmem - root["effect"] = modeName; + //char modeName[30]; + //strncpy_P(modeName, (PGM_P)strip.getModeName(strip.getMode()), sizeof(modeName)); // copy from progmem + root["effect"] = strip.getModeName(strip.getMode()); char buffer[measureJson(root) + 1]; serializeJson(root, buffer, sizeof(buffer)); @@ -1250,7 +1251,7 @@ bool writeConfigFS(bool saveConfig){ json["mqtt_user"] = mqtt_user; json["mqtt_pass"] = mqtt_pass; -// SPIFFS.remove("/config.json") ? DBG_OUTPUT_PORT.println("removed file") : DBG_OUTPUT_PORT.println("failed removing file"); + //SPIFFS.remove("/config.json") ? DBG_OUTPUT_PORT.println("removed file") : DBG_OUTPUT_PORT.println("failed removing file"); File configFile = SPIFFS.open("/config.json", "w"); if (!configFile) DBG_OUTPUT_PORT.println("failed to open config file for writing"); @@ -1322,7 +1323,7 @@ bool writeStateFS(){ json["green"] = main_color.green; json["blue"] = main_color.blue; -// SPIFFS.remove("/state.json") ? DBG_OUTPUT_PORT.println("removed file") : DBG_OUTPUT_PORT.println("failed removing file"); + //SPIFFS.remove("/stripstate.json") ? DBG_OUTPUT_PORT.println("removed file") : DBG_OUTPUT_PORT.println("failed removing file"); File configFile = SPIFFS.open("/stripstate.json", "w"); if (!configFile) { DBG_OUTPUT_PORT.println("Failed!"); @@ -1371,6 +1372,12 @@ bool readStateFS() { strip.setSpeed(convertSpeed(ws2812fx_speed)); strip.setBrightness(brightness); strip.setColor(main_color.red, main_color.green, main_color.blue); + + #ifdef ENABLE_E131 + if (mode == E131) { + strip.stop(); + } + #endif updateFS = false; return true;