Binary file not shown.
@@ -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_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
|
#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_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
|
#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
|
||||||
|
|||||||
@@ -810,73 +810,76 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
|
|||||||
|
|
||||||
// $ ==> Get config Info.
|
// $ ==> Get config Info.
|
||||||
if (payload[0] == 'C') {
|
if (payload[0] == 'C') {
|
||||||
bool updateFSE = false;
|
bool updateStrip = false;
|
||||||
if (payload[1] == 'h') {
|
bool updateConf = false;
|
||||||
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
|
|
||||||
if (payload[1] == 's') {
|
if (payload[1] == 's') {
|
||||||
if (payload[2] == 'c') {
|
if (payload[2] == 'c') {
|
||||||
char tmp_count[6];
|
char tmp_count[6];
|
||||||
snprintf(tmp_count, sizeof(tmp_count), "%s", &payload[3]);
|
snprintf(tmp_count, sizeof(tmp_count), "%s", &payload[3]);
|
||||||
WS2812FXStripSettings.stripSize = constrain(atoi(tmp_count), 0, 65535);
|
WS2812FXStripSettings.stripSize = constrain(atoi(tmp_count), 0, 65535);
|
||||||
updateFSE=true;
|
updateStrip = true;
|
||||||
}
|
}
|
||||||
if (payload[2] == 'r') {
|
if (payload[2] == 'r') {
|
||||||
char tmp_rgbOrder[5];
|
char tmp_rgbOrder[5];
|
||||||
snprintf(tmp_rgbOrder, sizeof(tmp_rgbOrder), "%s", &payload[3]);
|
snprintf(tmp_rgbOrder, sizeof(tmp_rgbOrder), "%s", &payload[3]);
|
||||||
checkRGBOrder(tmp_rgbOrder);
|
checkRGBOrder(tmp_rgbOrder);
|
||||||
updateFSE=true;
|
updateStrip=true;
|
||||||
}
|
}
|
||||||
#if !defined(USE_WS2812FX_DMA)
|
#if !defined(USE_WS2812FX_DMA)
|
||||||
if (payload[2] == 'p') {
|
if (payload[2] == 'p') {
|
||||||
char tmp_pin[3];
|
char tmp_pin[3];
|
||||||
snprintf(tmp_pin, sizeof(tmp_pin), "%s", &payload[3]);
|
snprintf(tmp_pin, sizeof(tmp_pin), "%s", &payload[3]);
|
||||||
checkPin(atoi(tmp_pin));
|
checkPin(atoi(tmp_pin));
|
||||||
updateFSE=true;
|
updateStrip = true;
|
||||||
|
updateConf = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (payload[2] == 'o') {
|
if (payload[2] == 'o') {
|
||||||
char tmp_fxoptions[4];
|
char tmp_fxoptions[4];
|
||||||
snprintf(tmp_fxoptions, sizeof(tmp_fxoptions), "%s", &payload[3]);
|
snprintf(tmp_fxoptions, sizeof(tmp_fxoptions), "%s", &payload[3]);
|
||||||
WS2812FXStripSettings.fxoptions = constrain(atoi(tmp_fxoptions), 0, 255);
|
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 defined(ENABLE_STATE_SAVE)
|
||||||
#if ENABLE_STATE_SAVE == 1
|
#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
|
#endif
|
||||||
#if ENABLE_STATE_SAVE == 0
|
#if ENABLE_STATE_SAVE == 0
|
||||||
if (updateFSE) {
|
if (updateConf || updateStrip) {
|
||||||
char last_conf[223];
|
char last_conf[223];
|
||||||
#if defined(ENABLE_MQTT)
|
#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);
|
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, "OK");
|
||||||
webSocket.sendTXT(num, json);
|
webSocket.sendTXT(num, json);
|
||||||
}
|
}
|
||||||
|
updateStrip = false;
|
||||||
|
updateConf = false;
|
||||||
DBG_OUTPUT_PORT.println("Get status info: " + json);
|
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["g3"] = xtra_color.green;
|
||||||
color["b3"] = xtra_color.blue;
|
color["b3"] = xtra_color.blue;
|
||||||
color["w3"] = xtra_color.white;
|
color["w3"] = xtra_color.white;
|
||||||
|
if (strstr(WS2812FXStripSettings.RGBOrder, "W") != NULL) {
|
||||||
|
root["white_value"]= main_color.white;
|
||||||
|
}
|
||||||
root["brightness"] = brightness;
|
root["brightness"] = brightness;
|
||||||
root["color_temp"] = color_temp;
|
root["color_temp"] = color_temp;
|
||||||
root["speed"] = ws2812fx_speed;
|
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"];
|
xtra_color.white = (uint8_t) color["w3"];
|
||||||
mode = SET_COLOR;
|
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")) {
|
if (root.containsKey("speed")) {
|
||||||
uint8_t json_speed = constrain((uint8_t) root["speed"], 0, 255);
|
uint8_t json_speed = constrain((uint8_t) root["speed"], 0, 255);
|
||||||
if (json_speed != ws2812fx_speed) {
|
if (json_speed != ws2812fx_speed) {
|
||||||
@@ -1276,6 +1292,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
#endif
|
#endif
|
||||||
json["brightness"] = "true";
|
json["brightness"] = "true";
|
||||||
json["rgb"] = "true";
|
json["rgb"] = "true";
|
||||||
|
if (strstr(WS2812FXStripSettings.RGBOrder, "W") != NULL) {
|
||||||
|
json["white_value"]= "true";
|
||||||
|
}
|
||||||
json["optimistic"] = "false";
|
json["optimistic"] = "false";
|
||||||
json["color_temp"] = "true";
|
json["color_temp"] = "true";
|
||||||
json["effect"] = "true";
|
json["effect"] = "true";
|
||||||
@@ -1381,6 +1400,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
#endif
|
#endif
|
||||||
json["brightness"] = "true";
|
json["brightness"] = "true";
|
||||||
json["rgb"] = "true";
|
json["rgb"] = "true";
|
||||||
|
if (strstr(WS2812FXStripSettings.RGBOrder, "W") != NULL) {
|
||||||
|
json["white_value"]= "true";
|
||||||
|
}
|
||||||
json["optimistic"] = "false";
|
json["optimistic"] = "false";
|
||||||
json["color_temp"] = "true";
|
json["color_temp"] = "true";
|
||||||
json["effect"] = "true";
|
json["effect"] = "true";
|
||||||
|
|||||||
@@ -272,25 +272,27 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool updateFSE = false;
|
bool updateStrip = false;
|
||||||
|
bool updateConf = false;
|
||||||
if(server.hasArg("ws_cnt")){
|
if(server.hasArg("ws_cnt")){
|
||||||
uint16_t pixelCt = server.arg("ws_cnt").toInt();
|
uint16_t pixelCt = server.arg("ws_cnt").toInt();
|
||||||
if (pixelCt > 0) {
|
if (pixelCt > 0) {
|
||||||
WS2812FXStripSettings.stripSize = pixelCt;
|
WS2812FXStripSettings.stripSize = pixelCt;
|
||||||
updateFSE = true;
|
updateStrip = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(server.hasArg("ws_rgbo")){
|
if(server.hasArg("ws_rgbo")){
|
||||||
char tmp_rgbOrder[5];
|
char tmp_rgbOrder[5];
|
||||||
snprintf(tmp_rgbOrder, sizeof(tmp_rgbOrder), "%s", server.arg("ws_rgbo").c_str());
|
snprintf(tmp_rgbOrder, sizeof(tmp_rgbOrder), "%s", server.arg("ws_rgbo").c_str());
|
||||||
checkRGBOrder(tmp_rgbOrder);
|
checkRGBOrder(tmp_rgbOrder);
|
||||||
updateFSE = true;
|
updateStrip = true;
|
||||||
|
updateConf = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(USE_WS2812FX_DMA)
|
#if !defined(USE_WS2812FX_DMA)
|
||||||
if(server.hasArg("wspin")){
|
if(server.hasArg("wspin")){
|
||||||
if (checkPin(server.arg("wspin").toInt()) {
|
if (checkPin(server.arg("wspin").toInt()) {
|
||||||
updateFSE = true;
|
updateStrip = true;
|
||||||
DBG_OUTPUT_PORT.println(WS2812FXStripSettings.pin);
|
DBG_OUTPUT_PORT.println(WS2812FXStripSettings.pin);
|
||||||
} else {
|
} else {
|
||||||
DBG_OUTPUT_PORT.println("invalid input!");
|
DBG_OUTPUT_PORT.println("invalid input!");
|
||||||
@@ -300,45 +302,48 @@
|
|||||||
|
|
||||||
if(server.hasArg("ws_fxopt")){
|
if(server.hasArg("ws_fxopt")){
|
||||||
WS2812FXStripSettings.fxoptions = server.arg("ws_fxopt").toInt();
|
WS2812FXStripSettings.fxoptions = server.arg("ws_fxopt").toInt();
|
||||||
updateFSE = true;
|
updateStrip = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(updateFSE) {
|
if(updateStrip) {
|
||||||
mode = INIT_STRIP;
|
mode = INIT_STRIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(server.hasArg("hostname")){
|
if(server.hasArg("hostname")){
|
||||||
snprintf(HOSTNAME, sizeof(HOSTNAME), "%s", server.arg("hostname").c_str());
|
snprintf(HOSTNAME, sizeof(HOSTNAME), "%s", server.arg("hostname").c_str());
|
||||||
updateFSE = true;
|
updateConf = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
if(server.hasArg("mqtt_host")){
|
if(server.hasArg("mqtt_host")){
|
||||||
snprintf(mqtt_host, sizeof(mqtt_host), "%s", server.arg("mqtt_host").c_str());
|
snprintf(mqtt_host, sizeof(mqtt_host), "%s", server.arg("mqtt_host").c_str());
|
||||||
updateFSE = true;
|
updateConf = true;
|
||||||
}
|
}
|
||||||
if(server.hasArg("mqtt_port")){
|
if(server.hasArg("mqtt_port")){
|
||||||
if ((server.arg("mqtt_port").toInt() >= 0) && (server.arg("mqtt_port").toInt() <=65535)) {
|
if ((server.arg("mqtt_port").toInt() >= 0) && (server.arg("mqtt_port").toInt() <=65535)) {
|
||||||
mqtt_port = server.arg("mqttport").toInt();
|
mqtt_port = server.arg("mqttport").toInt();
|
||||||
updateFSE = true;
|
updateConf = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(server.hasArg("mqtt_user")){
|
if(server.hasArg("mqtt_user")){
|
||||||
snprintf(mqtt_user, sizeof(mqtt_user), "%s", server.arg("mqtt_user").c_str());
|
snprintf(mqtt_user, sizeof(mqtt_user), "%s", server.arg("mqtt_user").c_str());
|
||||||
updateFSE = true;
|
updateConf = true;
|
||||||
}
|
}
|
||||||
if(server.hasArg("mqtt_pass")){
|
if(server.hasArg("mqtt_pass")){
|
||||||
snprintf(mqtt_pass, sizeof(mqtt_pass), "%s", server.arg("mqtt_pass").c_str());
|
snprintf(mqtt_pass, sizeof(mqtt_pass), "%s", server.arg("mqtt_pass").c_str());
|
||||||
updateFSE = true;
|
updateConf = true;
|
||||||
}
|
}
|
||||||
|
if (updateConf) {
|
||||||
|
initMqtt();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ENABLE_STATE_SAVE)
|
#if defined(ENABLE_STATE_SAVE)
|
||||||
#if ENABLE_STATE_SAVE == 1
|
#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
|
#endif
|
||||||
#if ENABLE_STATE_SAVE == 0
|
#if ENABLE_STATE_SAVE == 0
|
||||||
if (updateFSE) {
|
if (updateConf || updateStrip) {
|
||||||
char last_conf[223];
|
char last_conf[223];
|
||||||
#if defined(ENABLE_MQTT)
|
#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);
|
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
|
#endif
|
||||||
getConfigJSON();
|
getConfigJSON();
|
||||||
delay(500);
|
delay(500);
|
||||||
|
updateStrip = false;
|
||||||
#if defined(ENABLE_MQTT)
|
updateConf = false;
|
||||||
if (updateFSE) {
|
|
||||||
initMqtt();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
updateFSE = false;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/off", []() {
|
server.on("/off", []() {
|
||||||
|
|||||||
@@ -126,4 +126,7 @@
|
|||||||
* ~ Get Modes
|
* ~ Get Modes
|
||||||
* / Set modes
|
* / Set modes
|
||||||
*
|
*
|
||||||
|
* 17 Mar 2019
|
||||||
|
* adressed issue: #2
|
||||||
|
* adressed issue: #3
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user