Compare commits

...

1 Commits

Author SHA1 Message Date
Gunnar Skjold
473932f1bc Fixed Zmartcharge configuration issue 2025-10-15 16:35:36 +02:00
4 changed files with 47 additions and 16 deletions

View File

@@ -905,14 +905,12 @@ bool AmsConfiguration::getZmartChargeConfig(ZmartChargeConfig& config) {
EEPROM.end();
stripNonAscii((uint8_t*) config.token, 21);
stripNonAscii((uint8_t*) config.baseUrl, 64);
if(strlen(config.token) != 20) {
if(strlen(config.token) != 20 || !config.enabled) {
config.enabled = false;
memset(config.token, 0, 64);
memset(config.baseUrl, 0, 64);
}
if(strncmp_P(config.baseUrl, PSTR("https"), 5) != 0) {
config.enabled = false;
memset(config.token, 0, 64);
if(strlen(config.baseUrl) == 0 || strncmp_P(config.baseUrl, PSTR("https"), 5) != 0) {
memset(config.baseUrl, 0, 64);
snprintf_P(config.baseUrl, 64, PSTR("https://main.zmartcharge.com/api"));
}
@@ -927,8 +925,8 @@ bool AmsConfiguration::setZmartChargeConfig(ZmartChargeConfig& config) {
ZmartChargeConfig existing;
if(getZmartChargeConfig(existing)) {
zcChanged |= config.enabled != existing.enabled;
zcChanged |= memcmp(config.token, existing.token, 21) != 0;
zcChanged |= memcmp(config.token, existing.baseUrl, 64) != 0;
zcChanged |= strcmp(config.token, existing.token) != 0;
zcChanged |= strcmp(config.baseUrl, existing.baseUrl) != 0;
} else {
zcChanged = true;
}
@@ -1356,10 +1354,10 @@ void AmsConfiguration::print(Print* debugger)
debugger->printf_P(PSTR("Area: %s\r\n"), price.area);
debugger->printf_P(PSTR("Currency: %s\r\n"), price.currency);
debugger->printf_P(PSTR("ENTSO-E Token: %s\r\n"), price.entsoeToken);
debugger->println(F(""));
delay(10);
debugger->flush();
}
debugger->println(F(""));
delay(10);
debugger->flush();
}
UiConfig ui;
@@ -1377,9 +1375,29 @@ void AmsConfiguration::print(Print* debugger)
String uuid = ESPRandom::uuidToString(cc.clientId);;
debugger->println(F("--Cloud configuration--"));
debugger->printf_P(PSTR("Enabled: %s\r\n"), cc.enabled ? "Yes" : "No");
debugger->printf_P(PSTR("Hostname: %s\r\n"), cc.hostname);
debugger->printf_P(PSTR("Client ID: %s\r\n"), uuid.c_str());
debugger->printf_P(PSTR("Interval: %d\r\n"), cc.interval);
if(cc.enabled) {
debugger->printf_P(PSTR("Hostname: %s\r\n"), cc.hostname);
debugger->printf_P(PSTR("Client ID: %s\r\n"), uuid.c_str());
debugger->printf_P(PSTR("Interval: %d\r\n"), cc.interval);
}
debugger->println(F(""));
delay(10);
debugger->flush();
}
#endif
#if defined(ZMART_CHARGE)
ZmartChargeConfig zc;
if(getZmartChargeConfig(zc)) {
debugger->println(F("--ZmartCharge configuration--"));
debugger->printf_P(PSTR("Enabled: %s\r\n"), zc.enabled ? "Yes" : "No");
if(zc.enabled) {
debugger->printf_P(PSTR("Base URL: '%s'\r\n"), zc.baseUrl);
debugger->printf_P(PSTR("Token: '%s'\r\n"), zc.token);
}
debugger->println(F(""));
delay(10);
debugger->flush();
}
#endif

View File

@@ -1192,6 +1192,17 @@ void AmsWebServer::handleSave() {
if(!checkSecurity(1))
return;
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::DEBUG)) {
#endif
debugger->printf(PSTR("Received %d args for /save\n"), server.args());
for(uint8_t i = 0; i < server.args(); i++) {
debugger->printf_P(PSTR(" %s: %s\n"), server.argName(i).c_str(), server.arg(i).c_str());
}
#if defined(AMS_REMOTE_DEBUG)
}
#endif
SystemConfig sys;
config->getSystemConfig(sys);

View File

@@ -38,7 +38,7 @@ void ZmartChargeCloudConnector::update(AmsData& data) {
return;
}
if(((now - lastUpdate) / 1000) > (fast || lastFailed ? heartbeatFast : heartbeat)) {
if(lastUpdate == 0 || ((now - lastUpdate) / 1000) > (fast || lastFailed ? heartbeatFast : heartbeat)) {
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf_P(PSTR("(ZmartCharge) Preparing to update cloud\n"));
memset(json, 0, BufferSize);
snprintf_P(json, BufferSize, ZC_LB_JSON,
@@ -86,9 +86,9 @@ void ZmartChargeCloudConnector::update(AmsData& data) {
}
http->end();
} else {
if(debugger->isActive(RemoteDebug::ERROR)) debugger->printf_P(PSTR("(ZmartCharge) Communication error, returned status: %d\n"), status);
if(debugger->isActive(RemoteDebug::ERROR)) debugger->printf(http->errorToString(status).c_str());
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf(http->getString().c_str());
if(debugger->isActive(RemoteDebug::ERROR)) debugger->printf_P(PSTR("(ZmartCharge) Communication error with %s, returned status: %d\n"), baseUrl, status);
if(debugger->isActive(RemoteDebug::ERROR)) debugger->printf("%s\n", http->errorToString(status).c_str());
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("%s\n", http->getString().c_str());
http->end();
}

View File

@@ -343,6 +343,8 @@ void setup() {
if(!hw.ledBlink(LED_RED, 6)) {
hw.ledBlink(LED_INTERNAL, 6);
}
ESP.restart();
return;
}
}
}