Skip to content

Commit

Permalink
fix #16, new topics
Browse files Browse the repository at this point in the history
  • Loading branch information
pvtom committed May 7, 2023
1 parent eafbb5d commit adf1744
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 8 deletions.
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
# InfluxDB Support: docker build --build-arg "with_influxdb=yes" -t rscp2mqtt .

FROM alpine
ARG with_influxdb=no

# Install packages
RUN apk --no-cache add \
bash \
g++ \
make \
mosquitto-dev
mosquitto-dev \
curl-dev

RUN mkdir -p /tmp/rscp2mqtt
COPY ./ /tmp/rscp2mqtt
WORKDIR /tmp/rscp2mqtt
RUN make
RUN make WITH_INFLUXDB=${with_influxdb}

RUN mkdir -p /opt/rscp2mqtt
RUN cp -a rscp2mqtt /opt/rscp2mqtt
RUN cp config.template /opt/rscp2mqtt/.config
RUN chown -R nobody:99 /opt/rscp2mqtt

FROM alpine
RUN apk --no-cache add libstdc++ mosquitto-libs
RUN apk --no-cache add libstdc++ mosquitto-libs libcurl
COPY --from=0 /opt/rscp2mqtt /opt/rscp2mqtt

# Switch to use a non-root user from here on
USER nobody

WORKDIR /opt/rscp2mqtt

CMD ["/opt/rscp2mqtt/rscp2mqtt", "-d"]
CMD ["/opt/rscp2mqtt/rscp2mqtt"]
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# RSCP2MQTT - Bridge between an E3/DC S10 device and an MQTT broker
[![GitHub sourcecode](https://img.shields.io/badge/Source-GitHub-green)](https://github.com/pvtom/rscp2mqtt/)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/pvtom/rscp2mqtt)](https://github.com/pvtom/rscp2mqtt/releases/latest)
[![GitHub last commit](https://img.shields.io/github/last-commit/pvtom/rscp2mqtt)](https://github.com/pvtom/rscp2mqtt/commits)
[![GitHub issues](https://img.shields.io/github/issues/pvtom/rscp2mqtt)](https://github.com/pvtom/rscp2mqtt/issues)
[![GitHub pull requests](https://img.shields.io/github/issues-pr/pvtom/rscp2mqtt)](https://github.com/pvtom/rscp2mqtt/pulls)
[![GitHub](https://img.shields.io/github/license/pvtom/rscp2mqtt)](https://github.com/pvtom/rscp2mqtt/blob/main/LICENSE)

This software module connects a home power station from E3/DC to an MQTT broker.
It uses the RSCP interface of the S10 device.
Expand All @@ -18,13 +24,15 @@ Supported topic areas are:
- Values of the power meter (PM)
- Values of the photovoltaic inverter (PVI)
- Values of the emergency power supply (EP)
- Values of the wallbox (WB)

For continuous provision of values, you can configure several topics that are published in each cycle. Default: Only modified values will be published.

## New Features

- E3/DC [wallbox](WALLBOX.md) topics
- [InfluxDB](INFLUXDB.md) support
- Topics for temperatures (battery, PVI)

## Prerequisite

Expand Down Expand Up @@ -124,7 +132,7 @@ DISABLE_MQTT_PUBLISH=false
WALLBOX=true
// topics to be published in each cycle (regular expressions)
FORCE_PUB=e3dc/[a-z]+/power
FORCE_PUB=e3dc/battery/rsoc
FORCE_PUB=e3dc/battery/soc
```

Find InfluxDB configurations in [InfluxDB](INFLUXDB.md).
Expand Down
1 change: 1 addition & 0 deletions RscpMqttConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ typedef struct _config_t {
int interval;
bool pvi_requests;
int pvi_tracker;
int pvi_temp_count;
bool pm_requests;
bool wallbox;
bool daemon;
Expand Down
21 changes: 21 additions & 0 deletions RscpMqttMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ int createRequest(SRscpFrameBuffer * frameBuffer) {
protocol.appendValue(&rootValue, TAG_EMS_REQ_MODE);
protocol.appendValue(&rootValue, TAG_EMS_REQ_STATUS);
protocol.appendValue(&rootValue, TAG_EMS_REQ_BALANCED_PHASES);
protocol.appendValue(&rootValue, TAG_EMS_REQ_BAT_SOC);

// Wallbox
if (cfg.wallbox) {
Expand Down Expand Up @@ -480,6 +481,8 @@ int createRequest(SRscpFrameBuffer * frameBuffer) {
if (!e3dc_ts) protocol.appendValue(&batteryContainer, TAG_BAT_REQ_DEVICE_NAME);
protocol.appendValue(&batteryContainer, TAG_BAT_REQ_DCB_COUNT);
protocol.appendValue(&batteryContainer, TAG_BAT_REQ_TRAINING_MODE);
protocol.appendValue(&batteryContainer, TAG_BAT_REQ_MAX_DCB_CELL_TEMPERATURE);
protocol.appendValue(&batteryContainer, TAG_BAT_REQ_MIN_DCB_CELL_TEMPERATURE);
protocol.appendValue(&rootValue, batteryContainer);
protocol.destroyValueData(batteryContainer);

Expand Down Expand Up @@ -529,6 +532,12 @@ int createRequest(SRscpFrameBuffer * frameBuffer) {
protocol.appendValue(&PVIContainer, TAG_PVI_REQ_AC_CURRENT, (uint8_t)0);
protocol.appendValue(&PVIContainer, TAG_PVI_REQ_AC_CURRENT, (uint8_t)1);
protocol.appendValue(&PVIContainer, TAG_PVI_REQ_AC_CURRENT, (uint8_t)2);
if (!cfg.pvi_temp_count) {
protocol.appendValue(&PVIContainer, TAG_PVI_REQ_TEMPERATURE_COUNT);
}
for (uint8_t i = 0; i < cfg.pvi_temp_count; i++) {
protocol.appendValue(&PVIContainer, TAG_PVI_REQ_TEMPERATURE, i);
}
protocol.appendValue(&rootValue, PVIContainer);
protocol.destroyValueData(PVIContainer);
}
Expand Down Expand Up @@ -828,6 +837,7 @@ int handleResponseValue(RscpProtocol *protocol, SRscpValue *response) {
logMessage(cfg.logfile, (char *)__FILE__, __LINE__, (char *)"Error: Tag 0x%08X received error code %u.\n", response->tag, uiErrorCode);
} else {
switch (containerData[i].tag) {
case TAG_PVI_TEMPERATURE:
case TAG_PVI_AC_VOLTAGE:
case TAG_PVI_AC_CURRENT:
case TAG_PVI_AC_POWER:
Expand All @@ -847,6 +857,16 @@ int handleResponseValue(RscpProtocol *protocol, SRscpValue *response) {
protocol->destroyValueData(container);
break;
}
case TAG_PVI_TEMPERATURE_COUNT: {
cfg.pvi_temp_count = protocol->getValueAsUChar8(&containerData[i]);
storeResponseValue(RSCP_MQTT::RscpMqttCache, protocol, &(containerData[i]), response->tag, 0);
for (uint8_t c = 0; c < cfg.pvi_temp_count; c++) {
RSCP_MQTT::cache_t cache = {TAG_PVI_TEMPERATURE, TAG_PVI_VALUE, c, "", "%0.1f", "", RSCP::eTypeFloat32, 1, 0, false};
sprintf(cache.topic, "e3dc/pvi/temperature/%d", c + 1);
RSCP_MQTT::RscpMqttCache.push_back(cache);
}
break;
}
case TAG_PVI_ON_GRID: {
storeResponseValue(RSCP_MQTT::RscpMqttCache, protocol, &(containerData[i]), response->tag, 0);
break;
Expand Down Expand Up @@ -1132,6 +1152,7 @@ int main(int argc, char *argv[]){
cfg.interval = 1;
cfg.pvi_requests = true;
cfg.pvi_tracker = 2;
cfg.pvi_temp_count = 0;
cfg.pm_requests = true;
cfg.wallbox = false;
cfg.auto_refresh = false;
Expand Down
7 changes: 5 additions & 2 deletions RscpMqttMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ cache_t cache[] = {
{ 0, TAG_EMS_POWER_HOME, 0, "e3dc/home/power", "%i", "", RSCP::eTypeInt32, 1, 0, 0 },
{ 0, TAG_EMS_POWER_GRID, 0, "e3dc/grid/power", "%i", "", RSCP::eTypeInt32, 1, 0, 0 },
{ 0, TAG_EMS_POWER_ADD, 0, "e3dc/addon/power", "%i", "", RSCP::eTypeInt32, 1, 0, 0 },
{ 0, TAG_EMS_BAT_SOC, 0, "e3dc/battery/soc", "%i", "", RSCP::eTypeUChar8, 1, 0, 0 },
{ 0, TAG_EMS_STATUS, 0, "e3dc/ems/charging_lock", "%s", "", RSCP::eTypeUInt32, 1, 1, 0 },
{ 0, TAG_EMS_STATUS, 0, "e3dc/ems/discharging_lock", "%s", "", RSCP::eTypeUInt32, 1, 2, 0 },
{ 0, TAG_EMS_STATUS, 0, "e3dc/ems/emergency_power_available", "%s", "", RSCP::eTypeUInt32, 1, 4, 0 },
Expand All @@ -62,6 +63,8 @@ cache_t cache[] = {
{ TAG_BAT_DATA, TAG_BAT_DEVICE_NAME, 0, "e3dc/battery/name", "%s", "", RSCP::eTypeString, 1, 0, 0 },
{ TAG_BAT_DATA, TAG_BAT_DCB_COUNT, 0, "e3dc/battery/dcb_count", "%i", "", RSCP::eTypeUChar8, 1, 0, 0 },
{ TAG_BAT_DATA, TAG_BAT_TRAINING_MODE, 0, "e3dc/battery/training", "%i", "", RSCP::eTypeUChar8, 1, 0, 0 },
{ TAG_BAT_DATA, TAG_BAT_MAX_DCB_CELL_TEMPERATURE, 0, "e3dc/battery/temperature/max", "%0.1f", "", RSCP::eTypeFloat32, 1, 0, 0 },
{ TAG_BAT_DATA, TAG_BAT_MIN_DCB_CELL_TEMPERATURE, 0, "e3dc/battery/temperature/min", "%0.1f", "", RSCP::eTypeFloat32, 1, 0, 0 },
// CONTAINER TAG_EMS_GET_POWER_SETTINGS ------------------------------------------------------
{ TAG_EMS_GET_POWER_SETTINGS, TAG_EMS_MAX_CHARGE_POWER, 0, "e3dc/ems/max_charge/power", "%u", "", RSCP::eTypeUInt32, 1, 0, 0 },
{ TAG_EMS_GET_POWER_SETTINGS, TAG_EMS_MAX_DISCHARGE_POWER, 0, "e3dc/ems/max_discharge/power", "%u", "", RSCP::eTypeUInt32, 1, 0, 0 },
Expand Down Expand Up @@ -102,6 +105,7 @@ cache_t cache[] = {
{ TAG_PVI_AC_CURRENT, TAG_PVI_VALUE, 0, "e3dc/pvi/current/L1", "%0.2f", "", RSCP::eTypeFloat32, 1, 0, 0 },
{ TAG_PVI_AC_CURRENT, TAG_PVI_VALUE, 1, "e3dc/pvi/current/L2", "%0.2f", "", RSCP::eTypeFloat32, 1, 0, 0 },
{ TAG_PVI_AC_CURRENT, TAG_PVI_VALUE, 2, "e3dc/pvi/current/L3", "%0.2f", "", RSCP::eTypeFloat32, 1, 0, 0 },
{ TAG_PVI_DATA, TAG_PVI_TEMPERATURE_COUNT, 0, "e3dc/pvi/temperature/count", "%i", "", RSCP::eTypeUChar8, 1, 0, false },
{ TAG_PVI_DATA, TAG_PVI_ON_GRID, 0, "e3dc/pvi/on_grid", "%s", "", RSCP::eTypeBool, 1, 0, 0 },
// CONTAINER TAG_SE_EP_RESERVE ---------------------------------------------------------------
{ TAG_SE_EP_RESERVE, TAG_SE_PARAM_EP_RESERVE, 0, "e3dc/reserve/percent", "%0.2f", "", RSCP::eTypeFloat32, 1, 0, 0 },
Expand All @@ -118,7 +122,6 @@ cache_t cache[] = {
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_CONSUMPTION, 0, "e3dc/home/energy", "%0.2f", "", RSCP::eTypeFloat32, 1000, 0, 0 },
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_PM_0_POWER, 0, "e3dc/pm_0/energy", "%0.1f", "", RSCP::eTypeFloat32, 1, 0, 0 },
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_PM_1_POWER, 0, "e3dc/pm_1/energy", "%0.1f", "", RSCP::eTypeFloat32, 1, 0, 0 },
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_BAT_CHARGE_LEVEL, 0, "e3dc/battery/soc", "%0.1f", "", RSCP::eTypeFloat32, 1, 0, 0 },
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_CONSUMED_PRODUCTION, 0, "e3dc/consumed", "%0.1f", "", RSCP::eTypeFloat32, 1, 0, 0 },
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_AUTARKY, 0, "e3dc/autarky", "%0.1f", "", RSCP::eTypeFloat32, 1, 0, 0 },
// YESTERDAY
Expand All @@ -130,7 +133,7 @@ cache_t cache[] = {
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_CONSUMPTION, 1, "e3dc/yesterday/home/energy", "%0.2f", "", RSCP::eTypeFloat32, 1000, 0, 0 },
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_PM_0_POWER, 1, "e3dc/yesterday/pm_0/energy", "%0.1f", "", RSCP::eTypeFloat32, 1, 0, 0 },
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_PM_1_POWER, 1, "e3dc/yesterday/pm_1/energy", "%0.1f", "", RSCP::eTypeFloat32, 1, 0, 0 },
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_BAT_CHARGE_LEVEL, 1, "e3dc/yesterday/battery/soc", "%0.1f", "", RSCP::eTypeFloat32, 1, 0, 0 },
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_BAT_CHARGE_LEVEL, 1, "e3dc/yesterday/battery/rsoc", "%0.1f", "", RSCP::eTypeFloat32, 1, 0, 0 },
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_CONSUMED_PRODUCTION, 1, "e3dc/yesterday/consumed", "%0.1f", "", RSCP::eTypeFloat32, 1, 0, 0 },
{ TAG_DB_HISTORY_DATA_DAY, TAG_DB_AUTARKY, 1, "e3dc/yesterday/autarky", "%0.1f", "", RSCP::eTypeFloat32, 1, 0, 0 },
// WEEK
Expand Down
8 changes: 7 additions & 1 deletion TOPICS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
| Battery RSOC | e3dc/battery/rsoc | [%] |
| Battery SOC | e3dc/battery/soc | [%] |
| Battery Status Code | e3dc/battery/status | |
| Battery Temperature Max | e3dc/battery/temperature/max | [°C] |
| Battery Temperature Min | e3dc/battery/temperature/min | [°C] |
| Battery Training Mode | e3dc/battery/training | (0-2) |
| Consumed Production | e3dc/consumed | [%] |
| EMS Addon Power | e3dc/addon/power | [W] |
Expand Down Expand Up @@ -87,6 +89,10 @@
| PVI String2 Current | e3dc/pvi/current/string_2 | [A] |
| PVI String2 Power | e3dc/pvi/power/string_2 | [W] |
| PVI String2 Voltage | e3dc/pvi/voltage/string_2 | [V] |
| PVI Temperature 1 | e3dc/pvi/temperature/1 | [°C] |
| PVI Temperature 2 | e3dc/pvi/temperature/2 | [°C] |
| PVI Temperature 3 | e3dc/pvi/temperature/3 | [°C] |
| PVI Temperature 4 | e3dc/pvi/temperature/4 | [°C] |
| PVI Voltage L1 | e3dc/pvi/voltage/L1 | [V] |
| PVI Voltage L2 | e3dc/pvi/voltage/L2 | [V] |
| PVI Voltage L3 | e3dc/pvi/voltage/L3 | [V] |
Expand Down Expand Up @@ -125,7 +131,7 @@
| Year Solar Energy | e3dc/year/solar/energy | [kWh] |
| Yesterday Autarky | e3dc/yesterday/autarky | [%] |
| Yesterday Battery Energy Charge | e3dc/yesterday/battery/energy/charge | [kWh] |
| Yesterday Battery SOC | e3dc/yesterday/battery/soc | [%] |
| Yesterday Battery SOC | e3dc/yesterday/battery/rsoc | [%] |
| Yesterday Consumed Production | e3dc/yesterday/consumed | [%] |
| Yesterday Energy Discharge | e3dc/yesterday/battery/energy/discharge | [kWh] |
| Yesterday Grid In Energy | e3dc/yesterday/grid/energy/in | [kWh] |
Expand Down

0 comments on commit adf1744

Please sign in to comment.