Skip to content

Commit

Permalink
Wallbox (#12), InfluxDB (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvtom committed Apr 30, 2023
1 parent 4bc7e4f commit fc993cb
Show file tree
Hide file tree
Showing 9 changed files with 645 additions and 157 deletions.
52 changes: 52 additions & 0 deletions INFLUXDB.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## InfluxDB

This update implements the data transfer to an InfluxDB time-series database.
InfluxDB v1.x and v2.x are supported.

### Configuration for InfluxDB v1.x

Add these lines to the .config file and adjust the values according to your environment:

```
ENABLE_INFLUXDB=true
INFLUXDB_HOST=localhost
INFLUXDB_PORT=8086
INFLUXDB_VERSION=1
INFLUXDB_MEASUREMENT=e3dc
INFLUXDB_1_DB=e3dc
```

Start the influx client to prepare the database.

Create a database
```
create database e3dc
```

Access data using the influx client
```
precision rfc3339
use e3dc
select * from e3dc where topic = 'e3dc/solar/power' tz('Europe/Berlin')
```

Set a retention policy to limit data collection
```
CREATE RETENTION POLICY "one_day" ON "e3dc" DURATION 24h REPLICATION 1 DEFAULT
```

### Configuration for InfluxDB v2.x

Add and adjust the following lines in .config
```
ENABLE_INFLUXDB=true
INFLUXDB_HOST=localhost
INFLUXDB_PORT=8086
INFLUXDB_VERSION=2
INFLUXDB_MEASUREMENT=e3dc
INFLUXDB_2_ORGA=<my_orga>
INFLUXDB_2_BUCKET=<my_bucket>
INFLUXDB_2_TOKEN=<my_token>
```

Please use the web admin tool of the InfluxDB v2.x to configure the bucket, the orga and the token.
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
CXX=g++
ROOT_VALUE=rscp2mqtt
TARGET=rscp2mqtt

all: $(ROOT_VALUE)
all: $(TARGET)

$(ROOT_VALUE): clean
$(TARGET): clean
ifeq ($(WITH_INFLUXDB), yes)
$(CXX) -O3 RscpMqttMain.cpp RscpProtocol.cpp AES.cpp SocketConnection.cpp -pthread -lmosquitto -lcurl -o $@ -DINFLUXDB
else
$(CXX) -O3 RscpMqttMain.cpp RscpProtocol.cpp AES.cpp SocketConnection.cpp -pthread -lmosquitto -o $@

endif

clean:
-rm $(ROOT_VALUE) $(VECTOR)
-rm $(TARGET)
61 changes: 56 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ It uses the RSCP interface of the S10 device.

The solution is based on the RSCP sample application provided by E3/DC and was developed and tested with a Raspberry Pi and a Linux PC (x86_64).

The tool fetches the data cyclically from the S10 and publishes it to the MQTT broker under certain [topics](TOPICS.md). Only modified values will be published.
The tool fetches the data cyclically from the S10 and publishes it to the MQTT broker under certain [topics](TOPICS.md).

Supported topic areas are:

Expand All @@ -19,6 +19,13 @@ Supported topic areas are:
- Values of the photovoltaic inverter (PVI)
- Values of the emergency power supply (EP)

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

## Prerequisite

- An MQTT broker in your environment
Expand All @@ -28,20 +35,31 @@ Supported topic areas are:
sudo apt-get install libmosquitto-dev
```

If you like to transfer data to InfluxDB install the libcurl library:
```
sudo apt-get install curl libcurl4-openssl-dev
```

## Cloning the Repository

```
sudo apt-get install git # if necessary
git clone https://github.com/pvtom/rscp2mqtt.git
cd rscp2mqtt
```

## Compilation

To build a program version without InfluxDB use:
```
cd rscp2mqtt
make
```

To build a program version including InfluxDB support use:
```
make WITH_INFLUXDB=yes
```

## Installation

```
Expand Down Expand Up @@ -100,10 +118,19 @@ PVI_TRACKER=2
PM_REQUESTS=true
// Auto refresh, default is false
AUTO_REFRESH=false
// Dryrun (Test mode. S10 requests: yes - MQTT publications: no), default is false
DRYRUN=false
// Disable MQTT publish support (dryrun mode)
DISABLE_MQTT_PUBLISH=false
// Wallbox, default is false
WALLBOX=true
// topics to be published in each cycle (regular expressions)
FORCE_PUB=e3dc/[a-z]+/power
FORCE_PUB=e3dc/battery/rsoc
```

Find InfluxDB configurations in [InfluxDB](INFLUXDB.md).

The parameter FORCE_PUB can occur several times. You can use it to define topics that will be published in each cycle, even if the values do not change. To check the definition, look at the log output after the program start.

Start the program:

```
Expand Down Expand Up @@ -178,7 +205,7 @@ Be careful that the program runs only once.

## Logging

If stdout is redirected to another process, only the log information is passed (issue #10).
If stdout is redirected to another process or rscp2mqtt is started with option -s (silent mode), only the log information is passed (issue #10).

## Device Control

Expand Down Expand Up @@ -253,6 +280,29 @@ Turn on the functionality in the configuration file .config, add/change the foll
AUTO_REFRESH=true
```

## Wallbox Control

Set solar or mix mode with the current in [A] (6..32 Ampere)
```
mosquitto_pub -h localhost -p 1883 -t "e3dc/set/wallbox/control" -m "solar:16"
mosquitto_pub -h localhost -p 1883 -t "e3dc/set/wallbox/control" -m "mix:8"
```

Stop charging
```
mosquitto_pub -h localhost -p 1883 -t "e3dc/set/wallbox/control" -m "stop"
```

Set battery to car mode (true/1/false/0)
```
mosquitto_pub -h localhost -p 1883 -t "e3dc/set/wallbox/battery_to_car" -m true
```

Set battery before car mode (true/1/false/0)
```
mosquitto_pub -h localhost -p 1883 -t "e3dc/set/wallbox/battery_before_car" -m true
```

## System Commands

Post all topics and payloads to the MQTT broker again
Expand Down Expand Up @@ -281,3 +331,4 @@ mosquitto_pub -h localhost -t "e3dc/set/requests/pvi" -m true
- The RSCP example application comes from E3/DC. According to E3/DC it can be distributed under the following conditions: `The authors or copyright holders, and in special E3/DC can not be held responsible for any damage caused by the software. Usage of the software is at your own risk. It may not be issued in copyright terms as a separate work.`
- License of AES is included in the AES code files
- Eclipse Mosquitto (https://github.com/eclipse/mosquitto) with EPL-2.0
- libcurl (https://github.com/curl/curl/blob/master/COPYING)
17 changes: 16 additions & 1 deletion RscpMqttConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,28 @@ typedef struct _config_t {
bool mqtt_auth;
int mqtt_qos;
bool mqtt_retain;
#ifdef INFLUXDB
uint32_t influxdb_version;
char influxdb_host[128];
uint32_t influxdb_port;
char influxdb_db[128];
char influxdb_measurement[128];
char influxdb_orga[128];
char influxdb_bucket[128];
char influxdb_token[128];
#endif
char *logfile;
bool verbose;
int interval;
bool pvi_requests;
int pvi_tracker;
bool pm_requests;
bool wallbox;
bool daemon;
bool dryrun;
bool mqtt_pub;
#ifdef INFLUXDB
bool influxdb_on;
#endif
bool auto_refresh;
} config_t;

Expand Down
Loading

0 comments on commit fc993cb

Please sign in to comment.