diff --git a/CHANGELOG.md b/CHANGELOG.md index 63271ad2..b02aef1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ ### Development versions after 0.10.0 release -#### Build 2007020 +#### Build 2007190 + +- Fixed hostname containing illegal characters (#1035) #### Build 2006251 diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 399df185..a1b4096c 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -801,6 +801,16 @@ void WS2812FX::handle_palette(void) } } + +/* + * Gets a single color from the currently selected palette. + * @param i Palette Index (if mapping is true, the full palette will be SEGLEN long, if false, 255). Will wrap around automatically. + * @param mapping if true, LED position in segment is considered for color + * @param wrap FastLED palettes will usally wrap back to the start smoothly. Set false to get a hard edge + * @param mcol If the default palette 0 is selected, return the standard color 0, 1 or 2 instead. If >2, Party palette is used instead + * @param pbri Value to scale the brightness of the returned color by. Default is 255. (no scaling) + * @returns Single color from palette + */ uint32_t WS2812FX::color_from_palette(uint16_t i, bool mapping, bool wrap, uint8_t mcol, uint8_t pbri) { if (SEGMENT.palette == 0 && mcol < 3) return SEGCOLOR(mcol); //WS2812FX default @@ -812,6 +822,7 @@ uint32_t WS2812FX::color_from_palette(uint16_t i, bool mapping, bool wrap, uint8 return fastled_col.r*65536 + fastled_col.g*256 + fastled_col.b; } +//@returns `true` if color, mode, speed, intensity and palette match bool WS2812FX::segmentsAreIdentical(Segment* a, Segment* b) { //if (a->start != b->start) return false; diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 594c9225..58698654 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -324,15 +324,41 @@ void WLED::initConnection() DEBUG_PRINT(clientSSID); DEBUG_PRINTLN("..."); + // convert the "serverDescription" into a valid DNS hostname (alphanumeric) + char hostname[25] = "wled-"; + const char *pC = serverDescription; + uint8_t pos = 5; + + while (*pC && pos < 24) { // while !null and not over length + if (isalnum(*pC)) { // if the current char is alpha-numeric append it to the hostname + hostname[pos] = *pC; + pos++; + } else if (*pC == ' ' || *pC == '_' || *pC == '-' || *pC == '+' || *pC == '!' || *pC == '?' || *pC == '*') { + hostname[pos] = '-'; + pos++; + } + // else do nothing - no leading hyphens and do not include hyphens for all other characters. + pC++; + } + // if the hostname is left blank, use the mac address/default mdns name + if (pos < 6) { + sprintf(hostname + 5, "%*s", 6, escapedMac.c_str() + 6); + } else { //last character must not be hyphen + while (pos > 0 && hostname[pos -1] == '-') { + hostname[pos -1] = 0; + pos--; + } + } + #ifdef ESP8266 - WiFi.hostname(serverDescription); + WiFi.hostname(hostname); #endif WiFi.begin(clientSSID, clientPass); #ifdef ARDUINO_ARCH_ESP32 WiFi.setSleep(!noWifiSleep); - WiFi.setHostname(serverDescription); + WiFi.setHostname(hostname); #else wifi_set_sleep_type((noWifiSleep) ? NONE_SLEEP_T : MODEM_SLEEP_T); #endif diff --git a/wled00/wled.h b/wled00/wled.h index fda93b52..fbe6ab01 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2007020 +#define VERSION 2007190 // ESP8266-01 (blue) got too little storage space to work with all features of WLED. To use it, you must use ESP8266 Arduino Core v2.4.2 and the setting 512K(No SPIFFS).