1313bool AmsConfiguration::getSystemConfig (SystemConfig& config) {
1414 EEPROM.begin (EEPROM_SIZE);
1515 uint8_t configVersion = EEPROM.read (EEPROM_CONFIG_ADDRESS);
16+ EEPROM.get (CONFIG_SYSTEM_START, config);
17+ EEPROM.end ();
1618 if (configVersion == EEPROM_CHECK_SUM) {
17- EEPROM.get (CONFIG_SYSTEM_START, config);
18- EEPROM.end ();
1919 return true ;
2020 } else {
21- if (configVersion == EEPROM_CLEARED_INDICATOR) {
21+ if (configVersion == EEPROM_CLEARED_INDICATOR && config. boardType > 0 && config. boardType < 250 ) {
2222 config.vendorConfigured = true ;
2323 } else {
2424 config.vendorConfigured = false ;
2525 config.boardType = 0xFF ;
26+ clear ();
2627 }
2728 config.userConfigured = false ;
2829 config.dataCollectionConsent = 0 ;
@@ -282,8 +283,9 @@ void AmsConfiguration::ackWebChange() {
282283}
283284
284285bool AmsConfiguration::getMeterConfig (MeterConfig& config) {
285- if (hasConfig ()) {
286- EEPROM.begin (EEPROM_SIZE);
286+ EEPROM.begin (EEPROM_SIZE);
287+ uint8_t configVersion = EEPROM.read (EEPROM_CONFIG_ADDRESS);
288+ if (configVersion == EEPROM_CHECK_SUM || configVersion == EEPROM_CLEARED_INDICATOR) {
287289 EEPROM.get (CONFIG_METER_START, config);
288290 EEPROM.end ();
289291 if (config.bufferSize < 1 || config.bufferSize > 64 ) {
@@ -903,12 +905,12 @@ bool AmsConfiguration::getZmartChargeConfig(ZmartChargeConfig& config) {
903905 EEPROM.end ();
904906 stripNonAscii ((uint8_t *) config.token , 21 );
905907 stripNonAscii ((uint8_t *) config.baseUrl , 64 );
906- if (strlen (config.token ) < 20 ) {
908+ if (strlen (config.token ) != 20 || !config. enabled ) {
907909 config.enabled = false ;
908910 memset (config.token , 0 , 64 );
909911 memset (config.baseUrl , 0 , 64 );
910912 }
911- if (strncmp_P (config.baseUrl , PSTR (" https" ), 5 ) != 0 ) {
913+ if (strlen (config. baseUrl ) == 0 || strncmp_P (config.baseUrl , PSTR (" https" ), 5 ) != 0 ) {
912914 memset (config.baseUrl , 0 , 64 );
913915 snprintf_P (config.baseUrl , 64 , PSTR (" https://main.zmartcharge.com/api" ));
914916 }
@@ -923,8 +925,8 @@ bool AmsConfiguration::setZmartChargeConfig(ZmartChargeConfig& config) {
923925 ZmartChargeConfig existing;
924926 if (getZmartChargeConfig (existing)) {
925927 zcChanged |= config.enabled != existing.enabled ;
926- zcChanged |= memcmp (config.token , existing.token , 21 ) != 0 ;
927- zcChanged |= memcmp (config.token , existing.baseUrl , 64 ) != 0 ;
928+ zcChanged |= strcmp (config.token , existing.token ) != 0 ;
929+ zcChanged |= strcmp (config.baseUrl , existing.baseUrl ) != 0 ;
928930 } else {
929931 zcChanged = true ;
930932 }
@@ -1022,6 +1024,10 @@ void AmsConfiguration::clear() {
10221024 clearCloudConfig (cloud);
10231025 EEPROM.put (CONFIG_CLOUD_START, cloud);
10241026
1027+ ZmartChargeConfig zc;
1028+ clearZmartChargeConfig (zc);
1029+ EEPROM.put (CONFIG_ZC_START, zc);
1030+
10251031 EEPROM.put (EEPROM_CONFIG_ADDRESS, EEPROM_CLEARED_INDICATOR);
10261032 EEPROM.commit ();
10271033 EEPROM.end ();
@@ -1348,10 +1354,10 @@ void AmsConfiguration::print(Print* debugger)
13481354 debugger->printf_P (PSTR (" Area: %s\r\n " ), price.area );
13491355 debugger->printf_P (PSTR (" Currency: %s\r\n " ), price.currency );
13501356 debugger->printf_P (PSTR (" ENTSO-E Token: %s\r\n " ), price.entsoeToken );
1357+ debugger->println (F (" " ));
1358+ delay (10 );
1359+ debugger->flush ();
13511360 }
1352- debugger->println (F (" " ));
1353- delay (10 );
1354- debugger->flush ();
13551361 }
13561362
13571363 UiConfig ui;
@@ -1369,9 +1375,29 @@ void AmsConfiguration::print(Print* debugger)
13691375 String uuid = ESPRandom::uuidToString (cc.clientId );;
13701376 debugger->println (F (" --Cloud configuration--" ));
13711377 debugger->printf_P (PSTR (" Enabled: %s\r\n " ), cc.enabled ? " Yes" : " No" );
1372- debugger->printf_P (PSTR (" Hostname: %s\r\n " ), cc.hostname );
1373- debugger->printf_P (PSTR (" Client ID: %s\r\n " ), uuid.c_str ());
1374- debugger->printf_P (PSTR (" Interval: %d\r\n " ), cc.interval );
1378+ if (cc.enabled ) {
1379+ debugger->printf_P (PSTR (" Hostname: %s\r\n " ), cc.hostname );
1380+ debugger->printf_P (PSTR (" Client ID: %s\r\n " ), uuid.c_str ());
1381+ debugger->printf_P (PSTR (" Interval: %d\r\n " ), cc.interval );
1382+ }
1383+ debugger->println (F (" " ));
1384+ delay (10 );
1385+ debugger->flush ();
1386+ }
1387+ #endif
1388+
1389+ #if defined(ZMART_CHARGE)
1390+ ZmartChargeConfig zc;
1391+ if (getZmartChargeConfig (zc)) {
1392+ debugger->println (F (" --ZmartCharge configuration--" ));
1393+ debugger->printf_P (PSTR (" Enabled: %s\r\n " ), zc.enabled ? " Yes" : " No" );
1394+ if (zc.enabled ) {
1395+ debugger->printf_P (PSTR (" Base URL: '%s'\r\n " ), zc.baseUrl );
1396+ debugger->printf_P (PSTR (" Token: '%s'\r\n " ), zc.token );
1397+ }
1398+ debugger->println (F (" " ));
1399+ delay (10 );
1400+ debugger->flush ();
13751401 }
13761402 #endif
13771403
0 commit comments