diff --git a/Arduino/McLighting/McLighting.ino.nodemcu.bin b/Arduino/McLighting/McLighting.ino.nodemcu.bin index c33d374..4911ef4 100644 Binary files a/Arduino/McLighting/McLighting.ino.nodemcu.bin and b/Arduino/McLighting/McLighting.ino.nodemcu.bin differ diff --git a/Arduino/McLighting/definitions.h b/Arduino/McLighting/definitions.h index c0a8117..3db307b 100644 --- a/Arduino/McLighting/definitions.h +++ b/Arduino/McLighting/definitions.h @@ -8,7 +8,7 @@ //#define LED_TYPE_WS2811 // Uncomment, if LED type uses 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) #define LED_BUILTIN 2 // ESP-12F has the built in LED on GPIO2, see https://github.com/esp8266/Arduino/issues/2192 -char HOSTNAME[65] = "McLightingRGBW"; // Friedly hostname is configurable just for the start +char HOSTNAME[65] = "McLightingRGBW_02"; // Friedly hostname is configurable just for the start #define ENABLE_OTA 1 // If defined, enable Arduino OTA code. If set to 0 enable Arduino OTA code, if set to 1 enable ESP8266HTTPUpdateServer OTA code. #define ENABLE_MQTT 1 // If defined use MQTT OR AMQTT, if set to 0 enable MQTT client code, see: https://github.com/toblum/McLighting/wiki/MQTT-API, if set to 1, enable Async MQTT code, see: https://github.com/marvinroger/async-mqtt-client diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index c54a7f7..fee0b70 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -810,73 +810,76 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) { // $ ==> Get config Info. if (payload[0] == 'C') { - bool updateFSE = false; - if (payload[1] == 'h') { - snprintf(HOSTNAME, sizeof(HOSTNAME), "%s", &payload[2]); - updateFSE=true; - #if defined(ENABLE_MQTT) - initMqtt(); - #endif - } - #if defined(ENABLE_MQTT) - if (payload[1] == 'm') { - if (payload[2] == 'h') { - snprintf(mqtt_host, sizeof(mqtt_host), "%s", &payload[3]); - updateFSE=true; - } - if (payload[2] == 'p') { - char tmp_port[6]; - snprintf(tmp_port, sizeof(tmp_port), "%s", &payload[3]); - mqtt_port = constrain(atoi(tmp_port), 0, 65535); - updateFSE=true; - } - if (payload[2] == 'u') { - snprintf(mqtt_user, sizeof(mqtt_user), "%s", &payload[3]); - updateFSE=true; - } - if (payload[2] == 'w') { - snprintf(mqtt_pass, sizeof(mqtt_pass), "%s", &payload[3]); - updateFSE=true; - } - initMqtt(); - } - #endif + bool updateStrip = false; + bool updateConf = false; if (payload[1] == 's') { if (payload[2] == 'c') { char tmp_count[6]; snprintf(tmp_count, sizeof(tmp_count), "%s", &payload[3]); WS2812FXStripSettings.stripSize = constrain(atoi(tmp_count), 0, 65535); - updateFSE=true; + updateStrip = true; } if (payload[2] == 'r') { char tmp_rgbOrder[5]; snprintf(tmp_rgbOrder, sizeof(tmp_rgbOrder), "%s", &payload[3]); checkRGBOrder(tmp_rgbOrder); - updateFSE=true; + updateStrip=true; } #if !defined(USE_WS2812FX_DMA) if (payload[2] == 'p') { char tmp_pin[3]; snprintf(tmp_pin, sizeof(tmp_pin), "%s", &payload[3]); checkPin(atoi(tmp_pin)); - updateFSE=true; + updateStrip = true; + updateConf = true; } #endif if (payload[2] == 'o') { char tmp_fxoptions[4]; snprintf(tmp_fxoptions, sizeof(tmp_fxoptions), "%s", &payload[3]); WS2812FXStripSettings.fxoptions = constrain(atoi(tmp_fxoptions), 0, 255); - updateFSE=true; + updateStrip = true; + } + } + if (updateStrip){ + mode = INIT_STRIP; + } + if (payload[1] == 'h') { + snprintf(HOSTNAME, sizeof(HOSTNAME), "%s", &payload[2]); + updateConf = true; + } + #if defined(ENABLE_MQTT) + if (payload[1] == 'm') { + if (payload[2] == 'h') { + snprintf(mqtt_host, sizeof(mqtt_host), "%s", &payload[3]); + updateConf = true; } - mode = INIT_STRIP; - } - + if (payload[2] == 'p') { + char tmp_port[6]; + snprintf(tmp_port, sizeof(tmp_port), "%s", &payload[3]); + mqtt_port = constrain(atoi(tmp_port), 0, 65535); + updateConf = true; + } + if (payload[2] == 'u') { + snprintf(mqtt_user, sizeof(mqtt_user), "%s", &payload[3]); + updateConf = true; + } + if (payload[2] == 'w') { + snprintf(mqtt_pass, sizeof(mqtt_pass), "%s", &payload[3]); + updateConf = true; + } + } + if (updateConf) { + initMqtt(); + } + #endif + #if defined(ENABLE_STATE_SAVE) #if ENABLE_STATE_SAVE == 1 - (writeConfigFS(updateFSE)) ? DBG_OUTPUT_PORT.println("Config FS Save success!"): DBG_OUTPUT_PORT.println("Config FS Save failure!"); + (writeConfigFS(updateConf || updateStrip)) ? DBG_OUTPUT_PORT.println("Config FS Save success!"): DBG_OUTPUT_PORT.println("Config FS Save failure!"); #endif #if ENABLE_STATE_SAVE == 0 - if (updateFSE) { + if (updateConf || updateStrip) { char last_conf[223]; #if defined(ENABLE_MQTT) snprintf(last_conf, sizeof(last_conf), "CNF|%64s|%64s|%5d|%32s|%32s|%4d|%2d|%4s|%3d", HOSTNAME, mqtt_host, mqtt_port, mqtt_user, mqtt_pass, WS2812FXStripSettings.stripSize, WS2812FXStripSettings.pin, WS2812FXStripSettings.RGBOrder, WS2812FXStripSettings.fxoptions); @@ -904,6 +907,8 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) { webSocket.sendTXT(num, "OK"); webSocket.sendTXT(num, json); } + updateStrip = false; + updateConf = false; DBG_OUTPUT_PORT.println("Get status info: " + json); } @@ -1066,6 +1071,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght color["g3"] = xtra_color.green; color["b3"] = xtra_color.blue; color["w3"] = xtra_color.white; + if (strstr(WS2812FXStripSettings.RGBOrder, "W") != NULL) { + root["white_value"]= main_color.white; + } root["brightness"] = brightness; root["color_temp"] = color_temp; root["speed"] = ws2812fx_speed; @@ -1147,7 +1155,15 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght xtra_color.white = (uint8_t) color["w3"]; mode = SET_COLOR; } - + + if (root.containsKey("white_value")) { + uint8_t json_white_value = constrain((uint8_t) root["white_value"], 0, 255); + if (json_white_value != main_color.white) { + main_color.white = json_white_value; + mode = SET_COLOR; + } + } + if (root.containsKey("speed")) { uint8_t json_speed = constrain((uint8_t) root["speed"], 0, 255); if (json_speed != ws2812fx_speed) { @@ -1276,6 +1292,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght #endif json["brightness"] = "true"; json["rgb"] = "true"; + if (strstr(WS2812FXStripSettings.RGBOrder, "W") != NULL) { + json["white_value"]= "true"; + } json["optimistic"] = "false"; json["color_temp"] = "true"; json["effect"] = "true"; @@ -1381,6 +1400,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght #endif json["brightness"] = "true"; json["rgb"] = "true"; + if (strstr(WS2812FXStripSettings.RGBOrder, "W") != NULL) { + json["white_value"]= "true"; + } json["optimistic"] = "false"; json["color_temp"] = "true"; json["effect"] = "true"; diff --git a/Arduino/McLighting/rest_api.h b/Arduino/McLighting/rest_api.h index dbeb5a3..52d9011 100644 --- a/Arduino/McLighting/rest_api.h +++ b/Arduino/McLighting/rest_api.h @@ -272,25 +272,27 @@ */ - bool updateFSE = false; + bool updateStrip = false; + bool updateConf = false; if(server.hasArg("ws_cnt")){ uint16_t pixelCt = server.arg("ws_cnt").toInt(); if (pixelCt > 0) { WS2812FXStripSettings.stripSize = pixelCt; - updateFSE = true; + updateStrip = true; } } if(server.hasArg("ws_rgbo")){ char tmp_rgbOrder[5]; snprintf(tmp_rgbOrder, sizeof(tmp_rgbOrder), "%s", server.arg("ws_rgbo").c_str()); checkRGBOrder(tmp_rgbOrder); - updateFSE = true; + updateStrip = true; + updateConf = true; } #if !defined(USE_WS2812FX_DMA) if(server.hasArg("wspin")){ if (checkPin(server.arg("wspin").toInt()) { - updateFSE = true; + updateStrip = true; DBG_OUTPUT_PORT.println(WS2812FXStripSettings.pin); } else { DBG_OUTPUT_PORT.println("invalid input!"); @@ -300,45 +302,48 @@ if(server.hasArg("ws_fxopt")){ WS2812FXStripSettings.fxoptions = server.arg("ws_fxopt").toInt(); - updateFSE = true; + updateStrip = true; } - if(updateFSE) { + if(updateStrip) { mode = INIT_STRIP; } if(server.hasArg("hostname")){ snprintf(HOSTNAME, sizeof(HOSTNAME), "%s", server.arg("hostname").c_str()); - updateFSE = true; + updateConf = true; } #if defined(ENABLE_MQTT) if(server.hasArg("mqtt_host")){ snprintf(mqtt_host, sizeof(mqtt_host), "%s", server.arg("mqtt_host").c_str()); - updateFSE = true; + updateConf = true; } if(server.hasArg("mqtt_port")){ if ((server.arg("mqtt_port").toInt() >= 0) && (server.arg("mqtt_port").toInt() <=65535)) { mqtt_port = server.arg("mqttport").toInt(); - updateFSE = true; + updateConf = true; } } if(server.hasArg("mqtt_user")){ snprintf(mqtt_user, sizeof(mqtt_user), "%s", server.arg("mqtt_user").c_str()); - updateFSE = true; + updateConf = true; } if(server.hasArg("mqtt_pass")){ snprintf(mqtt_pass, sizeof(mqtt_pass), "%s", server.arg("mqtt_pass").c_str()); - updateFSE = true; - } + updateConf = true; + } + if (updateConf) { + initMqtt(); + } #endif #if defined(ENABLE_STATE_SAVE) #if ENABLE_STATE_SAVE == 1 - (writeConfigFS(updateFSE)) ? DBG_OUTPUT_PORT.println("Config FS Save success!"): DBG_OUTPUT_PORT.println("Config FS Save failure!"); + (writeConfigFS(updateConf || updateStrip)) ? DBG_OUTPUT_PORT.println("Config FS Save success!"): DBG_OUTPUT_PORT.println("Config FS Save failure!"); #endif #if ENABLE_STATE_SAVE == 0 - if (updateFSE) { + if (updateConf || updateStrip) { char last_conf[223]; #if defined(ENABLE_MQTT) snprintf(last_conf, sizeof(last_conf), "CNF|%64s|%64s|%5d|%32s|%32s|%4d|%2d|%4s|%3d", HOSTNAME, mqtt_host, mqtt_port, mqtt_user, mqtt_pass, WS2812FXStripSettings.stripSize, WS2812FXStripSettings.pin, WS2812FXStripSettings.RGBOrder, WS2812FXStripSettings.fxoptions); @@ -352,14 +357,8 @@ #endif getConfigJSON(); delay(500); - -#if defined(ENABLE_MQTT) - if (updateFSE) { - initMqtt(); - } -#endif - - updateFSE = false; + updateStrip = false; + updateConf = false; }); server.on("/off", []() { diff --git a/Arduino/McLighting/version_info.ino b/Arduino/McLighting/version_info.ino index 4ad988c..ddd88b9 100644 --- a/Arduino/McLighting/version_info.ino +++ b/Arduino/McLighting/version_info.ino @@ -126,4 +126,7 @@ * ~ Get Modes * / Set modes * + * 17 Mar 2019 + * adressed issue: #2 + * adressed issue: #3 */