Skip to content

Commit 7f783e2

Browse files
committed
Added calculated current, adjusted translations and refined verbose debugging
1 parent c623426 commit 7f783e2

File tree

8 files changed

+72
-24
lines changed

8 files changed

+72
-24
lines changed

include/solarcharger/integrated/Provider.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class Provider : public ::SolarChargers::Provider {
1919
void deinit() final { return; };
2020
void loop() final { return; };
2121
std::shared_ptr<::SolarChargers::Stats> getStats() const final { return _stats; }
22-
//std::shared_ptr<Stats> getStats() { return _stats; }
2322

2423
private:
2524
Provider(Provider const& other) = delete;

include/solarcharger/integrated/Stats.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,6 @@ class DeviceData {
6767
return true;
6868
}
6969

70-
// bool equals(const String& manufacture, const String& device, const String& serial, const size_t numMppts) {
71-
// if (_manufacture != manufacture) { return false; }
72-
// if (_device != device) { return false; }
73-
// if (_serial != serial) { return false; }
74-
// if (_numMppts != numMppts) { return false; }
75-
76-
// return true;
77-
// }
7870
inline String getName() {
7971
return _manufacture + " " + _device;
8072
}

src/battery/zendure/Provider.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ bool Provider::init()
6363
}
6464

6565
// setup static device info
66-
DTU_LOGI("Device name '%s' - LOG messages are %s supported\r\n",
66+
DTU_LOGI("Device name '%s' - LOG messages are %s supported",
6767
deviceName.c_str(), (_full_log_supported ? "fully" : "partly"));
6868
_stats->setDevice(std::move(deviceName));
6969
_stats->setManufacturer("Zendure");
@@ -124,7 +124,7 @@ bool Provider::init()
124124
JsonDocument root;
125125
JsonVariant prop = root[ZENDURE_REPORT_PROPERTIES].to<JsonObject>();
126126
prop[ZENDURE_REPORT_PV_BRAND] = 1; // means Hoymiles
127-
prop[ZENDURE_REPORT_PV_AUTO_MODEL] = 0; // we did static setup
127+
//prop[ZENDURE_REPORT_PV_AUTO_MODEL] = 0; // we did static setup
128128
prop[ZENDURE_REPORT_AUTO_RECOVER] = static_cast<uint8_t>(config.Battery.Zendure.BypassMode == static_cast<uint8_t>(BypassMode::Automatic));
129129
prop[ZENDURE_REPORT_AUTO_SHUTDOWN] = static_cast<uint8_t>(config.Battery.Zendure.AutoShutdown);
130130
prop[ZENDURE_REPORT_BUZZER_SWITCH] = static_cast<uint8_t>(config.Battery.Zendure.BuzzerEnable);
@@ -941,7 +941,7 @@ void Provider::publishPersistentSettings(const char* subtopic, const String& pay
941941
{
942942
if (!_topicPersistentSettings.isEmpty())
943943
{
944-
DTU_LOGD("Writing Persistent Settings %s = %s\r\n",
944+
DTU_LOGD("Writing Persistent Settings %s = %s",
945945
String(_topicPersistentSettings + subtopic).c_str(),
946946
payload.substring(0, 32).c_str());
947947
MqttSettings.publishGeneric(_topicPersistentSettings + subtopic, payload, true);

src/solarcharger/Controller.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,21 @@ std::shared_ptr<Integrated::Stats> Controller::getIntegratedStats()
7676

7777
std::lock_guard<std::mutex> lock(_mutex);
7878

79+
auto const delay = 20 * 1000U;
80+
auto const ms = millis();
81+
if (ms < delay) {
82+
DTU_LOGV("getIntegratedStats(): Startup Delay running %ld/%" PRId32 " ms", ms, delay);
83+
return nullptr;
84+
}
85+
7986
if (!_upProvider || config.SolarCharger.Provider != SolarChargerProviderType::Integrated) {
8087
return nullptr;
8188
}
8289

83-
return std::reinterpret_pointer_cast<Integrated::Stats>(_upProvider->getStats());
90+
auto stats = std::reinterpret_pointer_cast<Integrated::Stats>(_upProvider->getStats());
91+
92+
DTU_LOGV("getIntegratedStats(): returning 0x%p", static_cast<void*>(&*stats));
93+
return stats;
8494
}
8595

8696
void Controller::loop()

src/solarcharger/integrated/Provider.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ namespace SolarChargers::Integrated {
1111

1212
bool Provider::init()
1313
{
14-
if (Configuration.get().Battery.Provider != 7) {
15-
DTU_LOGE("Init failed - you must use a supported battery integration. Currently supported integrations are: Zendure");
16-
return false;
17-
}
14+
if (Configuration.get().Battery.Provider == 7) { return true; }
1815

19-
return true;
16+
DTU_LOGE("Init failed - you must use a supported battery integration. Currently supported integrations are: Zendure");
17+
return false;
2018
}
2119

2220
} // namespace SolarChargers::Integrated

src/solarcharger/integrated/Stats.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
#include <CRC.h>
33
#include <MqttSettings.h>
44
#include <solarcharger/integrated/Stats.h>
5+
#include <LogHelper.h>
6+
7+
#undef TAG
8+
static const char* TAG = "solarCharger";
9+
static const char* SUBTAG = "Integrated";
10+
511

612
namespace SolarChargers::Integrated {
713

@@ -45,6 +51,8 @@ void Stats::getLiveViewData(JsonVariant& root, const boolean fullUpdate, const u
4551
if (!fullUpdate && !hasUpdate) { return; }
4652

4753
for (const auto& [hash, device] : _devices) {
54+
DTU_LOGV("getLiveViewData(): device=0x%X", hash);
55+
4856
auto devage = millis() - device->getLastUpdate();
4957

5058
const JsonObject instance = root["solarcharger"]["instances"][device->getSerial()].to<JsonObject>();
@@ -54,6 +62,8 @@ void Stats::getLiveViewData(JsonVariant& root, const boolean fullUpdate, const u
5462
instance["product_id"] = device->getName();
5563

5664
for (const auto& [index, mppt] : device->_mppts) {
65+
DTU_LOGV("LIVE -> device=0x%X -> mppt=%d", hash, static_cast<size_t>(index));
66+
5767
auto name = String("mppt" + String(static_cast<size_t>(index)));
5868
const JsonObject output = instance["values"][name.c_str()].to<JsonObject>();
5969

@@ -70,8 +80,21 @@ void Stats::getLiveViewData(JsonVariant& root, const boolean fullUpdate, const u
7080
output["Voltage"]["u"] = "V";
7181
output["Voltage"]["d"] = 1;
7282
}
83+
84+
if (voltage.has_value() && power.has_value()) {
85+
if (*voltage == 0) {
86+
output["Current"] = "N/A";
87+
} else {
88+
output["Current"]["v"] = *power / *voltage;
89+
output["Current"]["u"] = "A";
90+
output["Current"]["d"] = 1;
91+
}
92+
93+
}
7394
}
7495
}
96+
97+
DTU_LOGV("LIVE EXIT");
7598
}
7699

77100
DeviceData::DeviceData(const String& manufacture, const String& device, const String& serial, const size_t numMppts /* = 0 */)
@@ -80,6 +103,8 @@ DeviceData::DeviceData(const String& manufacture, const String& device, const St
80103
, _serial(serial)
81104
, _numMppts(numMppts)
82105
{
106+
DTU_LOGV("DeviceData(): assert(%d <= 4)", numMppts);
107+
83108
// we currently support up to 4 MPPTs
84109
assert(numMppts <= 4);
85110

@@ -106,12 +131,15 @@ std::optional<std::pair<uint32_t, std::shared_ptr<DeviceData>>> Stats::addDevice
106131
const uint32_t hash = crc.calc();
107132

108133
auto new_device = std::make_shared<DeviceData>(*manufacture, *device, *serial, numMppts);
134+
DTU_LOGV("addDevice(): hash=0x%X, new_device=0x%p", hash, static_cast<void*>(&*new_device));
109135

110136
// check if the device already exits
111137
try
112138
{
113139
auto old_device = _devices.at(hash);
140+
DTU_LOGV("addDevice(): old_device=0x%p", static_cast<void*>(&*old_device));
114141
if (*old_device == *new_device) {
142+
DTU_LOGV("addDevice(): returning (0x%X, 0x%p)", hash, static_cast<void*>(&*old_device));
115143
return std::make_pair(hash, old_device);
116144
}
117145

@@ -120,6 +148,8 @@ std::optional<std::pair<uint32_t, std::shared_ptr<DeviceData>>> Stats::addDevice
120148
}
121149
catch(const std::out_of_range& ex) {;}
122150

151+
DTU_LOGV("addDevice(): returning (0x%X, 0x%p)", hash, static_cast<void*>(&*new_device));
152+
123153
// if no device found for our "hash", add a new one
124154
_devices[hash] = new_device;
125155
return std::make_pair(hash, new_device);
@@ -130,7 +160,7 @@ void Stats::mqttPublish() const {
130160

131161
for (const auto& [hash, device] : _devices) {
132162
for (const auto& [index, mppt] : device->_mppts) {
133-
String prefix = "solarchargers/" + device->getSerial() + "/" + static_cast<uint8_t>(index) + "/";
163+
String prefix = "solarchargers/" + device->getSerial() + "/mppt" + static_cast<uint8_t>(index) + "/";
134164

135165
auto power = mppt->getPower();
136166
if (power.has_value()) {
@@ -141,6 +171,10 @@ void Stats::mqttPublish() const {
141171
if (voltage.has_value()) {
142172
MqttSettings.publish(prefix + "voltage", String(*voltage, 1));
143173
}
174+
175+
if (voltage.value_or(0) != 0 && power.has_value()) {
176+
MqttSettings.publish(prefix + "current", String(*power / *voltage, 1));
177+
}
144178
}
145179
}
146180
}

webapp/src/locales/de.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,14 @@
229229
"section_mppt1": "Solareingang 1",
230230
"section_mppt2": "Solareingang 2",
231231
"mppt1": {
232-
"Power": "Leistung",
233-
"Voltage": "Voltage"
232+
"Power": "@:solarchargerhome.input.PPV",
233+
"Voltage": "@:solarchargerhome.input.VPV",
234+
"Current": "@:solarchargerhome.input.IPV"
234235
},
235236
"mppt2": {
236237
"Power": "@:solarchargerhome.mppt1.Power",
237-
"Voltage": "@:solarchargerhome.mppt1.Voltage"
238+
"Voltage": "@:solarchargerhome.mppt1.Voltage",
239+
"Current": "@:solarchargerhome.mppt1.Current"
238240
}
239241
},
240242
"eventlog": {
@@ -624,6 +626,7 @@
624626
"Provider": "Datenanbieter",
625627
"ProviderVeDirect": "Victron MPPT(s) per VE.Direct Schnittstelle",
626628
"ProviderMqtt": "Solarladereglerwerte aus MQTT Broker",
629+
"ProviderIntegrated": "MPPT Daten von unterstützten Batteriedatenanbietern (aktuell nur Zendure)",
627630
"MqttPublishUpdatesOnly": "Werte nur bei Änderung an MQTT broker senden",
628631
"CalculateOutputPower": "Solarladeregler-Ausgangsleistung berechnen",
629632
"CalculateOutputPowerDescription": "Wenn aktiviert, wird die Ausgangsleistung des Solarladeregler basierend auf den Strom- und Spannungswerten berechnet. Wenn deaktiviert, wird die Ausgangsleistung direkt vom Solarladeregler übernommen.",

webapp/src/locales/en.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,19 @@
225225
"MaximumPowerToday": "Maximum power today",
226226
"MaximumPowerYesterday": "Maximum power yesterday"
227227
},
228-
"PowerLimiterState": "Power limiter state [off (charging), solar passthrough, on battery]"
228+
"PowerLimiterState": "Power limiter state [off (charging), solar passthrough, on battery]",
229+
"section_mppt1": "Solar Input 1",
230+
"section_mppt2": "Solar Input 2",
231+
"mppt1": {
232+
"Power": "@:solarchargerhome.input.PPV",
233+
"Voltage": "@:solarchargerhome.input.VPV",
234+
"Current": "@:solarchargerhome.input.IPV"
235+
},
236+
"mppt2": {
237+
"Power": "@:solarchargerhome.mppt1.Power",
238+
"Voltage": "@:solarchargerhome.mppt1.Voltage",
239+
"Current": "@:solarchargerhome.mppt1.Current"
240+
}
229241
},
230242
"eventlog": {
231243
"Start": "Start",
@@ -614,7 +626,7 @@
614626
"Provider": "Data Provider",
615627
"ProviderVeDirect": "Victron MPPT(s) using VE.Direct interface",
616628
"ProviderMqtt": "Solar Charger data from MQTT broker",
617-
"ProviderIntegrated": "MPPT data from Smart Buffer Batteries",
629+
"ProviderIntegrated": "MPPT data from supported battery integrations (currently only zendure)",
618630
"MqttPublishUpdatesOnly": "Publish values to MQTT only when they change",
619631
"CalculateOutputPower": "Calculate Solar Charger output power",
620632
"CalculateOutputPowerDescription": "If enabled, the output power of the Solar Charger will be calculated based on the current and voltage values. If disabled, the output power will be taken from the Solar Charger directly.",

0 commit comments

Comments
 (0)