Skip to content

Commit c7c9671

Browse files
committed
v3.32
1 parent ce808b6 commit c7c9671

File tree

7 files changed

+80
-7
lines changed

7 files changed

+80
-7
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022-2024 Thomas Heiny, Wolfsburg, Germany
3+
Copyright (c) 2022-2025 Thomas Heiny, Wolfsburg, Germany
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ or to show the help page
160160
If everything works properly, you will see something like this:
161161

162162
```
163-
rscp2mqtt [3.31]
163+
rscp2mqtt [3.32]
164164
E3DC system >192.168.178.111:5033< user: >your E3DC user<
165165
MQTT broker >localhost:1883< qos = >0< retain = >✗< tls >✗< client id >✗< prefix >e3dc<
166166
Requesting PVI ✓ | PM (0) | DCB ✓ (1 battery string) | Wallbox ✗ | Interval 2 | Autorefresh ✓ | Raw data ✗ | Logging OFF

RELEASE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Release Notes
22

3+
### Release v3.32 (02.02.2025)
4+
5+
Features:
6+
- Issue #9, #96: External PM Energy Data
7+
38
### Release v3.31 (26.10.2024)
49

510
Bug fixes:

RscpMqttMain.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <regex>
2323
#include <mutex>
2424

25-
#define RSCP2MQTT_VERSION "3.31"
25+
#define RSCP2MQTT_VERSION "3.32"
2626

2727
#define AES_KEY_SIZE 32
2828
#define AES_BLOCK_SIZE 32
@@ -609,13 +609,16 @@ void storeSetupItem(uint32_t container, uint32_t tag, int index, int value) {
609609
void setupItem(std::vector<RSCP_MQTT::cache_t> & v, char *topic_in, char* payload) {
610610
char topic[TOPIC_SIZE];
611611
char value[15];
612-
char date[9];
613-
char date_in[9];
612+
char date[10];
613+
char date_in[10];
614614
time_t rawtime;
615615
time(&rawtime);
616616
struct tm *l = localtime(&rawtime);
617617

618-
sprintf(date, "%.4d%.2d%.2d", l->tm_year + 1900, l->tm_mon + 1, l->tm_mday);
618+
if (snprintf(date, sizeof(date), "%.4d%.2d%.2d", l->tm_year + 1900, l->tm_mon + 1, l->tm_mday) >= sizeof(date)) {
619+
logMessage(cfg.logfile, (char *)__FILE__, __LINE__, (char *)"setupItem: Buffer overflow\n");
620+
return;
621+
}
619622

620623
if (sscanf(payload, "%9[^:]:%14[^:]", date_in, value) == 2) {
621624
if (strcmp(date, date_in)) return;
@@ -926,6 +929,18 @@ void addPrefix(std::vector<RSCP_MQTT::cache_t> & v, char *prefix) {
926929
return;
927930
}
928931

932+
// Issue #9
933+
void correctExternalPM(std::vector<RSCP_MQTT::cache_t> & v, int pm, char *unit, int divisor) {
934+
for (std::vector<RSCP_MQTT::cache_t>::iterator it = v.begin(); it != v.end(); ++it) {
935+
if (((pm == 0) && (it->tag == TAG_DB_PM_0_POWER)) || ((pm == 1) && (it->tag == TAG_DB_PM_1_POWER))) {
936+
if (unit && (!strcmp(unit, UNIT_KWH) || !strcmp(unit, UNIT_WH))) strcpy(it->unit, unit);
937+
if ((divisor == 1) || (divisor == 1000)) it->divisor = divisor;
938+
if (cfg.verbose) logMessage(cfg.logfile, (char *)__FILE__, __LINE__, (char *)"correctExternalPM pm %d unit >%s< divisor %d topic >%s<\n", pm, it->unit, it->divisor, it->topic);
939+
}
940+
}
941+
return;
942+
}
943+
929944
int handleImmediately(RscpProtocol *protocol, SRscpValue *response, uint32_t container, int year, int month, int day) {
930945
#ifdef INFLUXDB
931946
char buffer[CURL_BUFFER_SIZE];
@@ -2131,7 +2146,10 @@ void handleRaw(RscpProtocol *protocol, SRscpValue *response, uint32_t *cache, in
21312146
if (response->dataType == RSCP::eTypeError) return;
21322147

21332148
if (!l && (response->dataType != RSCP::eTypeContainer)) {
2134-
snprintf(topic, TOPIC_SIZE, "raw/%s", tagName(RSCP_TAGS::RscpTagsOverview, response->tag));
2149+
if (snprintf(topic, TOPIC_SIZE, "raw/%s", tagName(RSCP_TAGS::RscpTagsOverview, response->tag)) >= TOPIC_SIZE) {
2150+
logMessage(cfg.logfile, (char *)__FILE__, __LINE__, (char *)"handleRaw: Buffer overflow\n");
2151+
return;
2152+
}
21352153
if (!cfg.raw_topic_regex || std::regex_match(topic, std::regex(cfg.raw_topic_regex))) publishRaw(protocol, response, topic);
21362154
return;
21372155
}
@@ -3152,6 +3170,19 @@ int main(int argc, char *argv[]) {
31523170
cfg.raw_mode = true;
31533171
else if (strcasecmp(key, "RAW_TOPIC_REGEX") == 0)
31543172
cfg.raw_topic_regex = strdup(value);
3173+
// Issue #9
3174+
else if (strcasecmp(key, "CORRECT_PM_0_UNIT") == 0) {
3175+
correctExternalPM(RSCP_MQTT::RscpMqttCache, 0, value, 0);
3176+
}
3177+
else if (strcasecmp(key, "CORRECT_PM_0_DIVISOR") == 0) {
3178+
correctExternalPM(RSCP_MQTT::RscpMqttCache, 0, NULL, atoi(value));
3179+
}
3180+
else if (strcasecmp(key, "CORRECT_PM_1_UNIT") == 0) {
3181+
correctExternalPM(RSCP_MQTT::RscpMqttCache, 1, value, 0);
3182+
}
3183+
else if (strcasecmp(key, "CORRECT_PM_1_DIVISOR") == 0) {
3184+
correctExternalPM(RSCP_MQTT::RscpMqttCache, 1, NULL, atoi(value));
3185+
}
31553186
else if (strncasecmp(key, "ADD_NEW_REQUEST", strlen("ADD_NEW_REQUEST")) == 0) {
31563187
int order = 0;
31573188
int index = -1;

RscpMqttMapping.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,21 @@ cache_t cache[] = {
282282
{ TAG_SE_EP_RESERVE, TAG_SE_PARAM_EP_RESERVE_MAX_W, 0, "reserve/max", "", F_FLOAT_2, UNIT_WH, 1, 0, false, false, false },
283283
{ TAG_SE_EP_RESERVE, TAG_SE_PARAM_LAST_SOC, 0, "reserve/last_soc", "", F_FLOAT_1, UNIT_PERCENT, 1, 0, false, false, false },
284284
// CONTAINER TAG_DB_HISTORY_DATA_...
285+
// Issue #9
286+
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_PM_0_POWER, 0, "pm_0/energy", "", F_FLOAT_2, UNIT_KWH, 1000, 0, false, false, false },
287+
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_PM_1_POWER, 0, "pm_1/energy", "", F_FLOAT_2, UNIT_KWH, 1000, 0, false, false, false },
288+
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_PM_0_POWER, 1, "yesterday/pm_0/energy", "", F_FLOAT_2, UNIT_KWH, 1000, 0, false, false, false },
289+
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_PM_1_POWER, 1, "yesterday/pm_1/energy", "", F_FLOAT_2, UNIT_KWH, 1000, 0, false, false, false },
290+
{ TAG_DB_HISTORY_DATA_WEEK, TAG_DB_PM_0_POWER, 0, "week/pm_0/energy", "", F_FLOAT_2, UNIT_KWH, 1000, 0, false, false, false },
291+
{ TAG_DB_HISTORY_DATA_WEEK, TAG_DB_PM_1_POWER, 0, "week/pm_1/energy", "", F_FLOAT_2, UNIT_KWH, 1000, 0, false, false, false },
292+
{ TAG_DB_HISTORY_DATA_MONTH, TAG_DB_PM_0_POWER, 0, "month/pm_0/energy", "", F_FLOAT_2, UNIT_KWH, 1000, 0, false, false, false },
293+
{ TAG_DB_HISTORY_DATA_MONTH, TAG_DB_PM_1_POWER, 0, "month/pm_1/energy", "", F_FLOAT_2, UNIT_KWH, 1000, 0, false, false, false },
294+
{ TAG_DB_HISTORY_DATA_YEAR, TAG_DB_PM_0_POWER, 0, "year/pm_0/energy", "", F_FLOAT_0, UNIT_KWH, 1000, 0, false, false, false },
295+
{ TAG_DB_HISTORY_DATA_YEAR, TAG_DB_PM_1_POWER, 0, "year/pm_1/energy", "", F_FLOAT_0, UNIT_KWH, 1000, 0, false, false, false },
296+
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_PM_0_POWER, 1, "day/%d/%d/%d/pm_0/energy", "", F_FLOAT_2, UNIT_KWH, 1000, 0, false, false, false },
297+
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_PM_1_POWER, 1, "day/%d/%d/%d/pm_1/energy", "", F_FLOAT_2, UNIT_KWH, 1000, 0, false, false, false },
298+
{ TAG_DB_HISTORY_DATA_YEAR, TAG_DB_PM_0_POWER, 1, "history/%d/pm_0/energy", "", F_FLOAT_0, UNIT_KWH, 1000, 0, false, false, false },
299+
{ TAG_DB_HISTORY_DATA_YEAR, TAG_DB_PM_1_POWER, 1, "history/%d/pm_1/energy", "", F_FLOAT_0, UNIT_KWH, 1000, 0, false, false, false },
285300
// TODAY
286301
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_BAT_POWER_IN, 0, "battery/energy/charge", "", F_FLOAT_2, UNIT_KWH, 1000, 0, false, false, false },
287302
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_BAT_POWER_OUT, 0, "battery/energy/discharge", "", F_FLOAT_2, UNIT_KWH, 1000, 0, false, false, false },

TOPICS.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ All topics are listed with the default prefix "e3dc".
127127
| Historical Data Grid In Energy "Einspeisung" ** | e3dc/day/<year#>/<month#>/<day#>/grid/energy/in | [kWh] |
128128
| Historical Data Grid Out Energy "Netzbezug" ** | e3dc/day/<year#>/<month#>/<day#>/grid/energy/out | [kWh] |
129129
| Historical Data Home Energy ** | e3dc/day/<year#>/<month#>/<day#>/home/energy | [kWh] |
130+
| Historical Data External PM 0 Energy ** | e3dc/day/<year#>/<month#>/<day#>/pm_0/energy | [kWh] |
131+
| Historical Data External PM 1 Energy ** | e3dc/day/<year#>/<month#>/<day#>/pm_1/energy | [kWh] |
130132
| Historical Data SOC ** | e3dc/day/<year#>/<month#>/<day#>/battery/rsoc | [%] |
131133
| Historical Data Solar Energy ** | e3dc/day/<year#>/<month#>/<day#>/solar/energy | [kWh] |
132134
| Home Energy | e3dc/home/energy (today) | [kWh] |
@@ -137,6 +139,8 @@ All topics are listed with the default prefix "e3dc".
137139
| Month Grid In Energy "Einspeisung" | e3dc/month/grid/energy/in | [kWh] |
138140
| Month Grid Out Energy "Netzbezug" | e3dc/month/grid/energy/out | [kWh] |
139141
| Month Home Energy | e3dc/month/home/energy | [kWh] |
142+
| Month External PM 0 Energy | e3dc/month/pm_0/energy | [kWh] |
143+
| Month External PM 1 Energy | e3dc/month/pm_1/energy | [kWh] |
140144
| Month Solar Energy | e3dc/month/solar/energy | [kWh] |
141145
| PM Active Phase L1 *** | e3dc/pm/active_phases/L1 | (true/false) |
142146
| PM Active Phase L2 *** | e3dc/pm/active_phases/L2 | (true/false) |
@@ -145,6 +149,8 @@ All topics are listed with the default prefix "e3dc".
145149
| PM Energy L1 *** | e3dc/pm/energy/L1 | [kWh] |
146150
| PM Energy L2 *** | e3dc/pm/energy/L2 | [kWh] |
147151
| PM Energy L3 *** | e3dc/pm/energy/L3 | [kWh] |
152+
| PM Energy External 0 *** | e3dc/pm_0/energy | [kWh] |
153+
| PM Energy External 1 ***| e3dc/pm_1/energy | [kWh] |
148154
| PM Power *** | e3dc/pm/power | [W] |
149155
| PM Power L1 *** | e3dc/pm/power/L1 | [W] |
150156
| PM Power L2 *** | e3dc/pm/power/L2 | [W] |
@@ -258,6 +264,8 @@ All topics are listed with the default prefix "e3dc".
258264
| Week Battery Energy Charge | e3dc/week/battery/energy/charge | [kWh] |
259265
| Week Consumed Production | e3dc/week/consumed | [%] |
260266
| Week Energy Discharge | e3dc/week/battery/energy/discharge | [kWh] |
267+
| Week External PM 0 Energy | e3dc/week/pm_0/energy | [kWh] |
268+
| Week External PM 1 Energy | e3dc/week/pm_1/energy | [kWh] |
261269
| Week Grid In Energy "Einspeisung" | e3dc/week/grid/energy/in | [kWh] |
262270
| Week Grid Out Energy "Netzbezug" | e3dc/week/grid/energy/out | [kWh] |
263271
| Week Home Energy | e3dc/week/home/energy | [kWh] |
@@ -266,12 +274,16 @@ All topics are listed with the default prefix "e3dc".
266274
| Year Battery Energy Charge | e3dc/year/battery/energy/charge | [kWh] |
267275
| Year Consumed Production | e3dc/year/consumed | [%] |
268276
| Year Energy Discharge | e3dc/year/battery/energy/discharge | [kWh] |
277+
| Year External PM 0 Energy | e3dc/year/pm_0/energy | [kWh] |
278+
| Year External PM 1 Energy | e3dc/year/pm_1/energy | [kWh] |
269279
| Year Grid In Energy "Einspeisung" | e3dc/year/grid/energy/in | [kWh] |
270280
| Year Grid Out Energy "Netzbezug" | e3dc/year/grid/energy/out | [kWh] |
271281
| Year History Autarky | e3dc/history/<year#>/autarky | [%] |
272282
| Year History Battery Energy Charge | e3dc/history/<year#>/battery/energy/charge | [kWh] |
273283
| Year History Consumed Production | e3dc/history/<year#>/consumed | [%] |
274284
| Year History Energy Discharge | e3dc/history/<year#>/battery/energy/discharge | [kWh] |
285+
| Year History External PM 0 Energy | e3dc/history/<year#>/pm_0/energy | [kWh] |
286+
| Year History External PM 1 Energy | e3dc/history/<year#>/pm_1/energy | [kWh] |
275287
| Year History Grid In Energy "Einspeisung" | e3dc/history/<year#>/grid/energy/in | [kWh] |
276288
| Year History Grid Out Energy "Netzbezug" | e3dc/history/<year#>/grid/energy/out | [kWh] |
277289
| Year History Home Energy | e3dc/history/<year#>/home/energy | [kWh] |
@@ -283,6 +295,8 @@ All topics are listed with the default prefix "e3dc".
283295
| Yesterday Battery SOC | e3dc/yesterday/battery/rsoc | [%] |
284296
| Yesterday Consumed Production | e3dc/yesterday/consumed | [%] |
285297
| Yesterday Energy Discharge | e3dc/yesterday/battery/energy/discharge | [kWh] |
298+
| Yesterday External PM 0 Energy | e3dc/yesterday/pm_0/energy | [kWh] |
299+
| Yesterday External PM 1 Energy | e3dc/yesterday/pm_1/energy | [kWh] |
286300
| Yesterday Grid In Energy "Einspeisung" | e3dc/yesterday/grid/energy/in | [kWh] |
287301
| Yesterday Grid Out Energy "Netzbezug" | e3dc/yesterday/grid/energy/out | [kWh] |
288302
| Yesterday Home Energy | e3dc/yesterday/home/energy | [kWh] |
@@ -291,6 +305,7 @@ All topics are listed with the default prefix "e3dc".
291305
*) If your system has more than one battery string (e.g. S10 Pro), you have to configure the parameter BATTERY_STRINGS accordingly. Battery topics that belong to a battery string are extended by the number of the battery string. Battery modules (DCB topics) are numbered consecutively.
292306

293307
Energy topics are collected for today, yesterday and the current week, month, year and historical years if configured.
308+
294309
**) Historical data for a specific day can be queried by publishing "e3dc/set/request/day".
295310

296311
***) If more than one power meter exists (PM_INDEX configured multiple times), topics are extended by the number of the power meter

config.template

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ PM_EXTERN=false
7070
PM_INDEX=0
7171
PM_REQUESTS=true
7272

73+
#-Addon Power Meter
74+
#--correct unit (Wh or kWh) or divisor (1 or 1000) if the values do not fit
75+
CORRECT_PM_0_UNIT=Wh
76+
CORRECT_PM_0_DIVISOR=1
77+
CORRECT_PM_1_UNIT=kWh
78+
CORRECT_PM_1_DIVISOR=1000
79+
7380
#-Photovoltaic Inverter
7481
PVI_REQUESTS=true
7582
#--Number of PVI strings/trackers (disables the auto detection)

0 commit comments

Comments
 (0)