diff --git a/Arduino/McLighting/McLighting.ino b/Arduino/McLighting/McLighting.ino index e7d83c2..a55b376 100644 --- a/Arduino/McLighting/McLighting.ino +++ b/Arduino/McLighting/McLighting.ino @@ -360,13 +360,20 @@ void initMqtt() { #else snprintf(mqtt_clientid, sizeof(mqtt_clientid), "%s", HOSTNAME); #endif + mqtt_clientid[sizeof(mqtt_clientid) - 1] = 0x00; snprintf(mqtt_will_topic, sizeof(mqtt_will_topic), "%s/config", HOSTNAME); + mqtt_will_topic[sizeof(mqtt_will_topic) - 1] = 0x00; snprintf(mqtt_intopic, sizeof(mqtt_intopic), "%s/in", HOSTNAME); + mqtt_intopic[sizeof(mqtt_intopic) - 1] = 0x00; snprintf(mqtt_outtopic, sizeof(mqtt_outtopic), "%s/out", HOSTNAME); + mqtt_outtopic[sizeof(mqtt_outtopic) - 1] = 0x00; #if defined(MQTT_HOME_ASSISTANT_SUPPORT) snprintf(mqtt_ha_config, sizeof(mqtt_ha_config), "homeassistant/light/%s/config", HOSTNAME); + mqtt_ha_config[sizeof(mqtt_ha_config) - 1] = 0x00; snprintf(mqtt_ha_state_in, sizeof(mqtt_ha_state_in), "home/%s_ha/state/in", HOSTNAME); + mqtt_ha_state_in[sizeof(mqtt_ha_state_in) - 1] = 0x00; snprintf(mqtt_ha_state_out, sizeof(mqtt_ha_state_out), "home/%s_ha/state/out", HOSTNAME); + mqtt_ha_state_out[sizeof(mqtt_ha_state_out) - 1] = 0x00; #endif if ((strlen(mqtt_host) != 0) && (mqtt_port != 0)) { #if ENABLE_MQTT == 0 @@ -563,7 +570,7 @@ void setup() { #else snprintf(last_conf, sizeof(last_conf), "CNF|%64s|%64s|%5d|%32s|%32s|%4d|%2d|%4s|%3d", HOSTNAME, "", "", "", "", WS2812FXStripSettings.stripSize, WS2812FXStripSettings.pin, WS2812FXStripSettings.RGBOrder, WS2812FXStripSettings.fxoptions); #endif - last_conf[sizeof(last_conf)]=0; + last_conf[sizeof(last_conf)] = 0x00; writeEEPROM(0, 222, last_conf); EEPROM.commit(); shouldSaveConfig = false; @@ -678,6 +685,7 @@ void setup() { #if defined(ENABLE_REMOTE) irrecv.enableIRIn(); // Start the receiver snprintf(last_state, sizeof(last_state), "STA|%2d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d", mode, ws2812fx_mode, ws2812fx_speed, brightness, main_color.red, main_color.green, main_color.blue, main_color.white, back_color.red, back_color.green, back_color.blue, back_color.white, xtra_color.red, xtra_color.green, xtra_color.blue,xtra_color.white); + last_state[sizeof(last_state)]= 0x00; #endif DBG_OUTPUT_PORT.println("finished Main Setup!"); @@ -866,6 +874,7 @@ void loop() { if(!settings_save_state.active()) settings_save_state.once(3, tickerSaveState); #endif snprintf(last_state, sizeof(last_state), "STA|%2d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d", prevmode, ws2812fx_mode, ws2812fx_speed, brightness, main_color.red, main_color.green, main_color.blue, main_color.white, back_color.red, back_color.green, back_color.blue, back_color.white, xtra_color.red, xtra_color.green, xtra_color.blue, xtra_color.white); + last_state[sizeof(last_state) - 1] = 0x00; } #if defined(ENABLE_MQTT) #if ENABLE_MQTT == 0 @@ -902,7 +911,7 @@ void loop() { #else snprintf(last_conf, sizeof(last_conf), "CNF|%64s|%64s|%5d|%32s|%32s|%4d|%2d|%4s|%3d", HOSTNAME, "", "", "", "", WS2812FXStripSettings.stripSize, WS2812FXStripSettings.pin, WS2812FXStripSettings.RGBOrder, WS2812FXStripSettings.fxoptions); #endif - last_conf[sizeof(last_conf)-1]= 0x00; + last_conf[sizeof(last_conf) - 1] = 0x00; writeEEPROM(0, 222, last_conf); EEPROM.commit(); shouldSaveConfig = false; diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index 51d4b59..8083612 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -284,11 +284,12 @@ void handleRangeDifferentColors(uint8_t * mypayload) { colorval[8] = 0x00; uint8_t rangebegin = atoi(startled); uint8_t rangeend = atoi(endled); - DBG_OUTPUT_PORT.printf("Setting RANGE from [%i] to [%i] as color [%s] \r\n", rangebegin, rangeend, colorval); + DBG_OUTPUT_PORT.printf("Setting RANGE from [%i] to [%i] as color [%s]\r\n", rangebegin, rangeend, colorval); while ( rangebegin <= rangeend ) { char rangeData[11]; snprintf(rangeData, sizeof(rangeData), "%02d%s", rangebegin, colorval); + rangeData[sizeof(rangeData) - 1] = 0x00; // Set one LED handleSetSingleLED((uint8_t*) rangeData, 0); rangebegin++; @@ -668,10 +669,7 @@ void getModesJSON() { // HTTP request handlers // *************************************************************************** void handleMinimalUpload() { - char temp[1500]; - - snprintf ( temp, 1500, - "\ + char message[] = "\ \ \ ESP8266 Upload\ @@ -686,10 +684,9 @@ void handleMinimalUpload() { \ \ \ - " - ); + "; server.sendHeader("Access-Control-Allow-Origin", "*"); - server.send ( 200, "text/html", temp ); + server.send ( 200, "text/html", message ); } void handleNotFound() { @@ -877,8 +874,8 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) { #if !defined(USE_WS2812FX_DMA) if (payload[2] == 'p') { char tmp_pin[3]; - tmp_pin[2] = 0x00; snprintf(tmp_pin, sizeof(tmp_pin), "%s", &payload[3]); + tmp_pin[2] = 0x00; checkPin(atoi(tmp_pin)); updateStrip = true; updateConf = true; @@ -897,26 +894,31 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) { } if (payload[1] == 'h') { snprintf(HOSTNAME, sizeof(HOSTNAME), "%s", &payload[2]); + HOSTNAME[sizeof(HOSTNAME) - 1] = 0x00; updateConf = true; } #if defined(ENABLE_MQTT) if (payload[1] == 'm') { if (payload[2] == 'h') { snprintf(mqtt_host, sizeof(mqtt_host), "%s", &payload[3]); + mqtt_host[sizeof(mqtt_host) - 1] = 0x00; updateConf = true; } if (payload[2] == 'p') { char tmp_port[6]; snprintf(tmp_port, sizeof(tmp_port), "%s", &payload[3]); + tmp_port[sizeof(tmp_port) - 1] = 0x00; mqtt_port = constrain(atoi(tmp_port), 0, 65535); updateConf = true; } if (payload[2] == 'u') { snprintf(mqtt_user, sizeof(mqtt_user), "%s", &payload[3]); + mqtt_user[sizeof(mqtt_user) - 1] = 0x00; updateConf = true; } if (payload[2] == 'w') { snprintf(mqtt_pass, sizeof(mqtt_pass), "%s", &payload[3]); + mqtt_pass[sizeof(mqtt_pass) - 1] = 0x00; updateConf = true; } } @@ -1502,6 +1504,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght DBG_OUTPUT_PORT.printf("Short button press\r\n"); if (mode == OFF) { setModeByStateString(BTN_MODE_SHORT); + prevmode = mode; mode = SET_ALL; } else { mode = OFF; @@ -1512,6 +1515,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght void mediumKeyPress() { DBG_OUTPUT_PORT.printf("Medium button press\r\n"); setModeByStateString(BTN_MODE_MEDIUM); + prevmode = mode; mode = SET_ALL; } @@ -1519,6 +1523,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght void longKeyPress() { DBG_OUTPUT_PORT.printf("Long button press\r\n"); setModeByStateString(BTN_MODE_LONG); + prevmode = mode; mode = SET_ALL; } @@ -1556,8 +1561,6 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght #if defined(ENABLE_BUTTON_GY33) void shortKeyPress_gy33() { DBG_OUTPUT_PORT.printf("Short GY-33 button press\r\n"); -// tcs.setConfig(MCU_LED_04, MCU_WHITE_OFF); -// delay(500); uint16_t red, green, blue, cl, ct, lux; tcs.getRawData(&red, &green, &blue, &cl, &lux, &ct); DBG_OUTPUT_PORT.printf("Raw Colors: R: [%d] G: [%d] B: [%d] Clear: [%d] Lux: [%d] Colortemp: [%d]\r\n", (int)red, (int)green, (int)blue, (int)cl, (int)lux, (int)ct); @@ -1565,14 +1568,14 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght tcs.getData(&r, &g, &b, &col, &conf); DBG_OUTPUT_PORT.printf("Colors: R: [%d] G: [%d] B: [%d] Color: [%d] Conf: [%d]\r\n", (int)r, (int)g, (int)b, (int)col, (int)conf); main_color.red = (pow((r/255.0), 2.5)*255); main_color.green = (pow((g/255.0), 2.5)*255); main_color.blue = (pow((b/255.0), 2.5)*255);main_color.white = 0; - ws2812fx_mode = 0; + ws2812fx_mode = FX_MODE_STATIC; + prevmode = HOLD; mode = SET_ALL; -// tcs.setConfig(MCU_LED_OFF, MCU_WHITE_OFF); } // called when button is kept pressed for less than 2 seconds void mediumKeyPress_gy33() { - tcs.setConfig(MCU_LED_06, MCU_WHITE_OFF); + tcs.setConfig(MCU_LED_03, MCU_WHITE_OFF); } // called when button is kept pressed for 2 seconds or more diff --git a/Arduino/McLighting/rest_api.h b/Arduino/McLighting/rest_api.h index 52b33a3..2e0ec4d 100644 --- a/Arduino/McLighting/rest_api.h +++ b/Arduino/McLighting/rest_api.h @@ -201,6 +201,7 @@ server.on("/get_brightness", []() { char str_brightness[4]; snprintf(str_brightness, sizeof(str_brightness), "%i", (int) (brightness / 2.55)); + str_brightness[sizeof(str_brightness) - 1] = 0x00; server.sendHeader("Access-Control-Allow-Origin", "*"); server.send(200, "text/plain", str_brightness ); DBG_OUTPUT_PORT.printf("/get_brightness: %i\r\n", (int) (brightness / 2.55)); @@ -215,6 +216,7 @@ server.on("/get_speed", []() { char str_speed[4]; snprintf(str_speed, sizeof(str_speed), "%i", ws2812fx_speed); + str_speed[sizeof(str_speed) - 1] = 0x00; server.sendHeader("Access-Control-Allow-Origin", "*"); server.send(200, "text/plain", str_speed ); DBG_OUTPUT_PORT.printf("/get_speed: %i\r\n", ws2812fx_speed); @@ -229,6 +231,7 @@ server.on("/get_color", []() { char rgbcolor[10]; snprintf(rgbcolor, sizeof(rgbcolor), "%02X%02X%02X%02X", main_color.white, main_color.red, main_color.green, main_color.blue); + rgbcolor[sizeof(rgbcolor) - 1] = 0x00; server.sendHeader("Access-Control-Allow-Origin", "*"); server.send(200, "text/plain", rgbcolor ); DBG_OUTPUT_PORT.print("/get_color: "); @@ -238,6 +241,7 @@ server.on("/get_color2", []() { char rgbcolor[10]; snprintf(rgbcolor, sizeof(rgbcolor), "%02X%02X%02X%02X", back_color.white, back_color.red, back_color.green, back_color.blue); + rgbcolor[sizeof(rgbcolor) - 1] = 0x00; server.sendHeader("Access-Control-Allow-Origin", "*"); server.send(200, "text/plain", rgbcolor ); DBG_OUTPUT_PORT.print("/get_color2: "); @@ -247,6 +251,7 @@ server.on("/get_color3", []() { char rgbcolor[10]; snprintf(rgbcolor, sizeof(rgbcolor), "%02X%02X%02X%02X", xtra_color.white, xtra_color.red, xtra_color.green, xtra_color.blue); + rgbcolor[sizeof(rgbcolor) - 1] = 0x00; server.sendHeader("Access-Control-Allow-Origin", "*"); server.send(200, "text/plain", rgbcolor ); DBG_OUTPUT_PORT.print("/get_color3: "); @@ -285,6 +290,7 @@ if(server.hasArg("ws_rgbo")){ char tmp_rgbOrder[5]; snprintf(tmp_rgbOrder, sizeof(tmp_rgbOrder), "%s", server.arg("ws_rgbo").c_str()); + tmp_rgbOrder[sizeof(tmp_rgbOrder) - 1] = 0x00; checkRGBOrder(tmp_rgbOrder); updateStrip = true; updateConf = true; @@ -312,12 +318,14 @@ if(server.hasArg("hostname")){ snprintf(HOSTNAME, sizeof(HOSTNAME), "%s", server.arg("hostname").c_str()); + HOSTNAME[sizeof(HOSTNAME) - 1] = 0x00; updateConf = true; } #if defined(ENABLE_MQTT) if(server.hasArg("mqtt_host")){ snprintf(mqtt_host, sizeof(mqtt_host), "%s", server.arg("mqtt_host").c_str()); + mqtt_host[sizeof(mqtt_host) - 1] = 0x00; updateConf = true; } if(server.hasArg("mqtt_port")){ @@ -328,10 +336,12 @@ } if(server.hasArg("mqtt_user")){ snprintf(mqtt_user, sizeof(mqtt_user), "%s", server.arg("mqtt_user").c_str()); + mqtt_user[sizeof(mqtt_user) - 1] = 0x00; updateConf = true; } if(server.hasArg("mqtt_pass")){ snprintf(mqtt_pass, sizeof(mqtt_pass), "%s", server.arg("mqtt_pass").c_str()); + mqtt_pass[sizeof(mqtt_pass) - 1] = 0x00; updateConf = true; } if (updateConf) { diff --git a/Arduino/McLighting/version_info.ino b/Arduino/McLighting/version_info.ino index 16c9aa6..85b4f38 100644 --- a/Arduino/McLighting/version_info.ino +++ b/Arduino/McLighting/version_info.ino @@ -146,4 +146,7 @@ * added pointer for MQTT again * Removed some String datatype and replaced with char array * better responsiveness in ui for sliders - */ + * + * 26 Mar 2019 + * Bugfixes + */