@@ -45,7 +45,7 @@ bool JBWoprWiFiDevice::begin(JBWoprBoardVariant variant, JBWoprBoardPins pins) {
4545 _loadConfiguration ();
4646 }
4747
48- JBTimeHelper::configure (_log, _wifiConfig.ntpServer , _wifiConfig.tzString );
48+ JBTimeHelper::configure (_log, _wifiConfig.ntpServer , _wifiConfig.tzName );
4949 _setupWiFiManager ();
5050
5151 displayShowText (" Start WiFi" );
@@ -225,7 +225,7 @@ void JBWoprWiFiDevice::_setConfigFromJsonDocument(const JsonDocument &jsonDoc) {
225225 _wifiConfig.ntpServer = jsonDoc[JSON_KEY_WIFI_NTP_SERVER].as <std::string>();
226226 }
227227 if (!jsonDoc[JSON_KEY_WIFI_TIMEZONE].isNull ()) {
228- _wifiConfig.tzString = jsonDoc[JSON_KEY_WIFI_TIMEZONE].as <std::string>();
228+ _wifiConfig.tzName = jsonDoc[JSON_KEY_WIFI_TIMEZONE].as <std::string>();
229229 }
230230 if (!jsonDoc[JSON_KEY_WIFI_USE_WEB_PORTAL].isNull ()) {
231231 _wifiConfig.useWebPortal = jsonDoc[JSON_KEY_WIFI_USE_WEB_PORTAL].as <bool >();
@@ -240,7 +240,7 @@ void JBWoprWiFiDevice::_setJsonDocumentFromConfig(JsonDocument &jsonDoc) {
240240 jsonDoc[JSON_KEY_EFFECTS_TIMEOUT] = _config.effectsTimeout ;
241241 jsonDoc[JSON_KEY_WIFI_HOST_NAME] = _wifiConfig.hostName ;
242242 jsonDoc[JSON_KEY_WIFI_NTP_SERVER] = _wifiConfig.ntpServer ;
243- jsonDoc[JSON_KEY_WIFI_TIMEZONE] = _wifiConfig.tzString ;
243+ jsonDoc[JSON_KEY_WIFI_TIMEZONE] = _wifiConfig.tzName ;
244244 jsonDoc[JSON_KEY_WIFI_USE_WEB_PORTAL] = _wifiConfig.useWebPortal ;
245245}
246246
@@ -253,7 +253,7 @@ void JBWoprWiFiDevice::_dumpConfig() {
253253 _log->trace (" Effects timeout: %u" , _config.effectsTimeout );
254254 _log->trace (" Host name: %s" , _wifiConfig.hostName .c_str ());
255255 _log->trace (" NTP server: %s" , _wifiConfig.ntpServer .c_str ());
256- _log->trace (" Timezone string : %s" , _wifiConfig.tzString .c_str ());
256+ _log->trace (" Timezone name : %s" , _wifiConfig.tzName .c_str ());
257257 _log->trace (" Use web portal: %s" , _wifiConfig.useWebPortal ? " true" : " false" );
258258}
259259
@@ -297,21 +297,23 @@ void JBWoprWiFiDevice::_setupWiFiManager() {
297297 _hostNameParam = new WiFiManagerParameter (JSON_KEY_WIFI_HOST_NAME, " Host name" , _wifiConfig.hostName .c_str (), 40 );
298298 _ntpServerNameParam = new WiFiManagerParameter (JSON_KEY_WIFI_NTP_SERVER, " NTP server" , _wifiConfig.ntpServer .c_str (), 40 );
299299
300- _tzHtml = " <br/><label for='tz_select'>Timezone</label><select id='tz_select' name='tz_select'>" ;
300+ _tzHtml = " <input id='tzString' name='tzString' type='hidden' value='" ;
301+ _tzHtml += _wifiConfig.tzName ;
302+ _tzHtml += " '><br/><label for='tz_select'>Timezone</label><select id='tz_select' name='tz_select'>" ;
301303 _tzHtml.reserve (40 * 1024 );
302304 _tzHtml += " <option value=''>UTC</option>" ;
303305 for (int i = 0 ; i < TZ_DATA_COUNT; i++) {
304306 _tzHtml += " <option value='" ;
305- _tzHtml += TZ_DATA[i].v ;
307+ _tzHtml += TZ_DATA[i].n ;
306308 _tzHtml += " '" ;
307- if (_wifiConfig.tzString == TZ_DATA[i].v ) {
309+ if (_wifiConfig.tzName == TZ_DATA[i].n ) {
308310 _tzHtml += " selected" ;
309311 }
310312 _tzHtml += " >" ;
311313 _tzHtml += TZ_DATA[i].n ;
312314 _tzHtml += " </option>" ;
313315 }
314- _tzHtml += " </select>" ;
316+ _tzHtml += " </select><script>document.getElementById('tz_select').onchange = function() { document.getElementById('tzString').value = this.value; };</script> " ;
315317 _tzStringParam = new WiFiManagerParameter (_tzHtml.c_str ());
316318
317319 _useWebPortalParam = new WiFiManagerParameter (JSON_KEY_WIFI_USE_WEB_PORTAL, " Use web portal" , " T" , 2 , _wifiConfig.useWebPortal ? HTML_CHECKBOX_TRUE : HTML_CHECKBOX_FALSE, WFM_LABEL_AFTER);
@@ -342,7 +344,7 @@ void JBWoprWiFiDevice::_saveParamsCallback () {
342344 _config.effectsTimeout = atoi (_effectsTimeoutParam->getValue ());
343345 _wifiConfig.hostName = _hostNameParam->getValue ();
344346 _wifiConfig.ntpServer = _ntpServerNameParam->getValue ();
345- _wifiConfig.tzString = _wifiManager->server ->arg (" tz_select " ).c_str ();
347+ _wifiConfig.tzName = _wifiManager->server ->arg (JSON_KEY_WIFI_TIMEZONE ).c_str ();
346348 _wifiConfig.useWebPortal = strncmp (_useWebPortalParam->getValue (), " T" , 1 ) == 0 ;
347349 _shouldSaveConfig = true ;
348350}
0 commit comments