Zmartcharge support (#1007)

* ZC initial implementation

* ZmartCharge

* Fixed zc bug

* Adjustments to ZmartCharge connection
This commit is contained in:
Gunnar Skjold
2025-09-25 11:38:05 +02:00
committed by GitHub
parent 633671851e
commit e5d260ae3e
10 changed files with 315 additions and 13 deletions

View File

@@ -26,6 +26,9 @@ ADC_MODE(ADC_VCC);
#if defined(AMS_CLOUD)
#include "CloudConnector.h"
#endif
#if defined(ZMART_CHARGE)
#include "ZmartChargeCloudConnector.h"
#endif
#define WDT_TIMEOUT 120
#if defined(SLOW_PROC_TRIGGER_MS)
@@ -182,6 +185,11 @@ AmsFirmwareUpdater updater(&Debug, &hw, &meterState);
AmsDataStorage ds(&Debug);
#if defined(_CLOUDCONNECTOR_H)
CloudConnector *cloud = NULL;
#endif
#if defined(ZMART_CHARGE)
ZmartChargeCloudConnector *zcloud = NULL;
#endif
#if defined(ESP32)
__NOINIT_ATTR EnergyAccountingRealtimeData rtd;
#else
EnergyAccountingRealtimeData rtd;
@@ -694,6 +702,36 @@ void loop() {
cloud->update(meterState, ea);
}
#endif
#if defined(ZMART_CHARGE)
if(config.isZmartChargeConfigChanged()) {
ZmartChargeConfig zcc;
if(config.getZmartChargeConfig(zcc) && zcc.enabled) {
if(zcloud == NULL) {
zcloud = new ZmartChargeCloudConnector(&Debug, (char*) commonBuffer);
}
zcloud->setup(zcc.baseUrl, zcc.token);
} else if(zcloud != NULL) {
delete zcloud;
zcloud = NULL;
}
config.ackZmartChargeConfig();
}
if(zcloud != NULL) {
zcloud->update(meterState);
if(zcloud->isConfigChanged()) {
ZmartChargeConfig zcc;
if(config.getZmartChargeConfig(zcc)) {
const char* newBaseUrl = zcloud->getBaseUrl();
memset(zcc.baseUrl, 0, 64);
memcpy(zcc.baseUrl, newBaseUrl, strlen(newBaseUrl));
config.setZmartChargeConfig(zcc);
config.ackZmartChargeConfig();
}
zcloud->ackConfigChanged();
}
}
#endif
start = millis();
handleUiLanguage();
end = millis();