From c754983d3b18fb322d172aee59e8c1c98a026211 Mon Sep 17 00:00:00 2001 From: debsahu Date: Tue, 19 Jun 2018 19:40:21 -0400 Subject: [PATCH 1/2] Added extra WiFiManger settings --- Arduino/McLighting/McLighting.ino | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Arduino/McLighting/McLighting.ino b/Arduino/McLighting/McLighting.ino index 0c6a7fe..f0fb0d0 100644 --- a/Arduino/McLighting/McLighting.ino +++ b/Arduino/McLighting/McLighting.ino @@ -319,6 +319,10 @@ void setup() { #endif WiFi.setSleepMode(WIFI_NONE_SLEEP); + + // Uncomment if you want to restart ESP8266 if it cannot connect to WiFi. + // Value in brackets is in seconds that WiFiManger waits until restart + //wifiManager.setConfigPortalTimeout(180); // Uncomment if you want to set static IP // Order is: IP, Gateway and Subnet @@ -331,8 +335,8 @@ void setup() { if (!wifiManager.autoConnect(HOSTNAME)) { DBG_OUTPUT_PORT.println("failed to connect and hit timeout"); //reset and try again, or maybe put it to deep sleep - ESP.reset(); - delay(1000); + ESP.reset(); //Will be removed when upgrading to standalone offline McLightingUI version + delay(1000); //Will be removed when upgrading to standalone offline McLightingUI version } #if defined(ENABLE_MQTT) or defined(ENABLE_AMQTT) From a84bd04001744a61009ff02281ba72e3dde0616b Mon Sep 17 00:00:00 2001 From: debsahu Date: Thu, 5 Jul 2018 13:12:54 -0400 Subject: [PATCH 2/2] Fixes for ArduinoJson 6.1.0-beta --- Arduino/McLighting/McLighting.ino | 2 +- Arduino/McLighting/request_handlers.h | 34 +++++++++++++-------------- Arduino/McLighting/version.h | 2 +- Arduino/McLighting/version_info.ino | 3 +++ 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Arduino/McLighting/McLighting.ino b/Arduino/McLighting/McLighting.ino index f0fb0d0..c16a918 100644 --- a/Arduino/McLighting/McLighting.ino +++ b/Arduino/McLighting/McLighting.ino @@ -497,7 +497,7 @@ void setup() { //get heap status, analog input value and all GPIO statuses in one json call server.on("/esp_status", HTTP_GET, []() { DynamicJsonDocument jsonBuffer; - JsonObject& json = jsonBuffer.to(); + JsonObject json = jsonBuffer.to(); json["HOSTNAME"] = HOSTNAME; json["version"] = SKETCH_VERSION; diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index 6e3af10..1917812 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -279,13 +279,13 @@ String listStatusJSON(void) { const size_t bufferSize = JSON_ARRAY_SIZE(3) + JSON_OBJECT_SIZE(6); DynamicJsonDocument jsonBuffer(bufferSize); - JsonObject& root = jsonBuffer.to(); + JsonObject root = jsonBuffer.to(); root["mode"] = (uint8_t) mode; root["ws2812fx_mode"] = tmp_mode; root["ws2812fx_mode_name"] = strip.getModeName(tmp_mode); root["speed"] = ws2812fx_speed; root["brightness"] = brightness; - JsonArray& color = root.createNestedArray("color"); + JsonArray color = root.createNestedArray("color"); color.add(main_color.red); color.add(main_color.green); color.add(main_color.blue); @@ -304,13 +304,13 @@ void getStatusJSON() { String listModesJSON(void) { const size_t bufferSize = JSON_ARRAY_SIZE(strip.getModeCount()+1) + strip.getModeCount()*JSON_OBJECT_SIZE(2); DynamicJsonDocument jsonBuffer(bufferSize); - JsonArray& json = jsonBuffer.to(); + JsonArray json = jsonBuffer.to(); for (uint8_t i = 0; i < strip.getModeCount(); i++) { - JsonObject& object = json.createNestedObject(); + JsonObject object = json.createNestedObject(); object["mode"] = i; object["name"] = strip.getModeName(i); } - JsonObject& object = json.createNestedObject(); + JsonObject object = json.createNestedObject(); String json_str; serializeJson(json, json_str); @@ -766,10 +766,10 @@ 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); DynamicJsonDocument jsonBuffer(bufferSize); - JsonObject& root = jsonBuffer.to(); + JsonObject root = jsonBuffer.to(); root["state"] = (stateOn) ? on_cmd : off_cmd; - JsonObject& color = root.createNestedObject("color"); + JsonObject color = root.createNestedObject("color"); color["r"] = main_color.red; color["g"] = main_color.green; color["b"] = main_color.blue; @@ -810,7 +810,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght return false; } //DBG_OUTPUT_PORT.println("JSON ParseObject() done!"); - JsonObject& root = jsonBuffer.as(); + JsonObject root = jsonBuffer.as(); if (root.containsKey("state")) { const char* state_in = root["state"]; @@ -828,7 +828,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght } if (root.containsKey("color")) { - JsonObject& color = root["color"]; + JsonObject color = root["color"]; main_color.red = (uint8_t) color["r"]; main_color.green = (uint8_t) color["g"]; main_color.blue = (uint8_t) color["b"]; @@ -938,7 +938,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght 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)); - JsonObject& json = jsonBuffer.to(); + JsonObject json = jsonBuffer.to(); json["name"] = HOSTNAME; json["platform"] = "mqtt_json"; json["state_topic"] = mqtt_ha_state_out; @@ -949,7 +949,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght json["optimistic"] = "false"; json["color_temp"] = "true"; json["effect"] = "true"; - JsonArray& effect_list = json.createNestedArray("effect_list"); + JsonArray effect_list = json.createNestedArray("effect_list"); for (uint8_t i = 0; i < strip.getModeCount(); i++) { effect_list.add(strip.getModeName(i)); } @@ -1018,7 +1018,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght 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)); - JsonObject& json = jsonBuffer.to(); + JsonObject json = jsonBuffer.to(); json["name"] = HOSTNAME; json["platform"] = "mqtt_json"; json["state_topic"] = mqtt_ha_state_out; @@ -1029,7 +1029,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght json["optimistic"] = "false"; json["color_temp"] = "true"; json["effect"] = "true"; - JsonArray& effect_list = json.createNestedArray("effect_list"); + JsonArray effect_list = json.createNestedArray("effect_list"); for (uint8_t i = 0; i < strip.getModeCount(); i++) { effect_list.add(strip.getModeName(i)); } @@ -1188,7 +1188,7 @@ bool writeConfigFS(bool saveConfig){ updateFS = true; DBG_OUTPUT_PORT.print("Saving config: "); DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(4)); - JsonObject& json = jsonBuffer.to(); + JsonObject json = jsonBuffer.to(); json["mqtt_host"] = mqtt_host; json["mqtt_port"] = mqtt_port; json["mqtt_user"] = mqtt_user; @@ -1228,7 +1228,7 @@ bool readConfigFS() { DBG_OUTPUT_PORT.print("Config: "); if (!error) { DBG_OUTPUT_PORT.println(" Parsed!"); - JsonObject& json = jsonBuffer.as(); + JsonObject json = jsonBuffer.as(); serializeJson(json, DBG_OUTPUT_PORT); strcpy(mqtt_host, json["mqtt_host"]); strcpy(mqtt_port, json["mqtt_port"]); @@ -1257,7 +1257,7 @@ bool writeStateFS(){ //save the strip state to FS JSON DBG_OUTPUT_PORT.print("Saving cfg: "); DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(7)); - JsonObject& json = jsonBuffer.to(); + JsonObject json = jsonBuffer.to(); json["mode"] = static_cast(mode); json["strip_mode"] = (int) strip.getMode(); json["brightness"] = brightness; @@ -1301,7 +1301,7 @@ bool readStateFS() { DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(7)+200); DeserializationError error = deserializeJson(jsonBuffer, buf.get()); if (!error) { - JsonObject& json = jsonBuffer.as(); + JsonObject json = jsonBuffer.as(); serializeJson(json, DBG_OUTPUT_PORT); mode = static_cast((int) json["mode"]); ws2812fx_mode = json["strip_mode"]; diff --git a/Arduino/McLighting/version.h b/Arduino/McLighting/version.h index 78f074b..0574111 100644 --- a/Arduino/McLighting/version.h +++ b/Arduino/McLighting/version.h @@ -1 +1 @@ -#define SKETCH_VERSION "2.1.2" +#define SKETCH_VERSION "2.1.3" diff --git a/Arduino/McLighting/version_info.ino b/Arduino/McLighting/version_info.ino index bafde4f..4e3d6c1 100644 --- a/Arduino/McLighting/version_info.ino +++ b/Arduino/McLighting/version_info.ino @@ -11,4 +11,7 @@ * - Upgrade to ArduinoJSON 6.xx from ArduinoJSON 5.xx * - Added example for static IP * - Added more internal variables to /esp_status + * + * 5 Jul 2018 c 2.1.3 + * - Fixes for ArduinoJson 6.1.0-beta */