Skip to content

Commit

Permalink
v2.0: new topics, docker
Browse files Browse the repository at this point in the history
  • Loading branch information
pvtom committed Sep 23, 2023
1 parent b992700 commit 34d0876
Show file tree
Hide file tree
Showing 10 changed files with 662 additions and 305 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: docker

on:
push:
tags:
- "*"
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
${{ github.repository }}
ghcr.io/${{ github.repository }}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ github.actor }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to Github Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/386,linux/arm64,linux/arm
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
15 changes: 15 additions & 0 deletions DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Docker

A Docker image is available at https://hub.docker.com/r/pvtom/s10m

### Configuration

Create a `.config` file as described in the [Readme](README.md).

### Start the docker container

```
docker run --rm -v /path/to/your/.config:/app/.config pvtom/s10m:latest
```

Thanks to [felix1507](https://github.com/felix1507/s10m-docker) for developing the Dockerfile!
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM debian:latest as build-basis

WORKDIR /build

# Install dependencies
RUN apt-get update && \
apt-get install -y build-essential git automake autoconf libtool libmosquitto-dev

FROM build-basis as build-libmodbus

WORKDIR /libmodbus

RUN git clone https://github.com/stephane/libmodbus.git . && \
bash autogen.sh && \
./configure && \
make install

FROM build-libmodbus as build-s10m

WORKDIR /build_s10m
COPY . .

RUN make

FROM debian:latest as runtime

WORKDIR /app
COPY --from=build-s10m /build_s10m/s10m /usr/bin
COPY --from=build-libmodbus /usr/local/lib/* /usr/local/lib/

RUN apt-get update && \
apt-get install -y libmosquitto-dev

CMD [ "s10m" ]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Thomas Heiny, Wolfsburg, Germany
Copyright (c) 2022,2023 Thomas Heiny, Wolfsburg, Germany

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ $(PRG): clean
$(CC) -O3 s10m.c $(MODBUS_CFLAGS) -lmosquitto $(MODBUS_LIBS) -o $@

clean:
-rm $(PRG)
-rm -f $(PRG)
144 changes: 111 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
# s10m - E3/DC S10 Modbus to MQTT connector
[![GitHub sourcecode](https://img.shields.io/badge/Source-GitHub-green)](https://github.com/pvtom/s10m/)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/pvtom/s10m)](https://github.com/pvtom/s10m/releases/latest)
[![GitHub last commit](https://img.shields.io/github/last-commit/pvtom/s10m)](https://github.com/pvtom/s10m/commits)
[![GitHub issues](https://img.shields.io/github/issues/pvtom/s10m)](https://github.com/pvtom/s10m/issues)
[![GitHub pull requests](https://img.shields.io/github/issues-pr/pvtom/s10m)](https://github.com/pvtom/s10m/pulls)
[![GitHub](https://img.shields.io/github/license/pvtom/s10m)](https://github.com/pvtom/s10m/blob/main/LICENSE)

This software module connects a E3/DC S10 home power station with a MQTT broker. It uses the Modbus interface of the S10 device.
This software module connects a home power station from E3/DC to an MQTT broker. It uses the Modbus interface of the S10 device.

Developed and tested with a Raspberry Pi.
Developed and tested with a Raspberry Pi and a Linux PC (x86_64).

The tool s10m queries the data from the home power station and sends it to the MQTT broker. The following topics are supported:

- s10/autarky
- s10/consumption
- s10/battery/charging/limit
- s10/battery/charging/lock
- s10/battery/discharging/lock
- s10/emergency/ready
- s10/battery/weather_regulation
- s10/grid/limit
- s10/idle_period/charging/active
- s10/idle_period/discharging/active
- s10/battery/soc
- s10/battery/power
- s10/battery/state
Expand All @@ -24,18 +32,55 @@ The tool s10m queries the data from the home power station and sends it to the M
- s10/grid/power/L2
- s10/grid/power/L3
- s10/home/power
- s10/addon/power
- s10/manufacturer
- s10/model
- s10/serial_number
- s10/solar/power
- s10/string_1/current
- s10/string_2/current
- s10/string_1/power
- s10/string_2/power
- s10/string_1/voltage
- s10/string_2/voltage

Only modified values will be published.
- s10/current/string_1
- s10/current/string_2
- s10/power/string_1
- s10/power/string_2
- s10/voltage/string_1
- s10/voltage/string_2
- s10/pvi/apparent_power/L1
- s10/pvi/apparent_power/L2
- s10/pvi/apparent_power/L3
- s10/pvi/active_power/L1
- s10/pvi/active_power/L2
- s10/pvi/active_power/L3
- s10/pvi/reactive_power/L1
- s10/pvi/reactive_power/L2
- s10/pvi/reactive_power/L3
- s10/pvi/voltage/L1
- s10/pvi/voltage/L2
- s10/pvi/voltage/L3
- s10/pvi/current/L1
- s10/pvi/current/L2
- s10/pvi/current/L3
- s10/grid/frequency
- s10/pvi/power/string_1
- s10/pvi/power/string_2
- s10/pvi/voltage/string_1
- s10/pvi/voltage/string_2
- s10/pvi/current/string_1
- s10/pvi/current/string_2

If one or more E3/DC wallboxes are available:

- s10/wallbox/[0-7]/available
- s10/wallbox/[0-7]/sun_mode
- s10/wallbox/[0-7]/ready
- s10/wallbox/[0-7]/charging
- s10/wallbox/[0-7]/1phase
- s10/wallbox/total/power
- s10/wallbox/solar/power

The prefix of the topics can be configured by the attribute ROOT_TOPIC. By default all topics start with "s10". This can be changed to any other string that MQTT accepts as a topic.

## Docker

Instead of installing the package you can use the [Docker image](DOCKER.md).

## Prerequisite

Expand All @@ -44,13 +89,12 @@ Only modified values will be published.
- s10m needs the library libmosquitto. To install it on a Raspberry Pi enter:

```
sudo apt-get install libmosquitto-dev
sudo apt-get install -y build-essential git automake autoconf libtool libmosquitto-dev
```
- s10m connects the S10 via the Modbus protocol, so you have to install a Modbus library:
```
git clone https://github.com/stephane/libmodbus.git
cd libmodbus/
sudo apt-get install libtool # when autogen or configure fail
./autogen.sh
./configure
sudo make install
Expand All @@ -63,25 +107,6 @@ sudo apt-get install git # if necessary
git clone https://github.com/pvtom/s10m.git
```

## Configuration

Please check the configuration values in the source code file s10m.h and adjust them to your needs.
```
// Host name of the E3/DC S10 device
MODBUS_HOST=e3dc
// Port of the E3/DC S10 device, default is 502
MODBUS_PORT=502
// Target MQTT broker
MQTT_HOST=localhost
// Default port is 1883
MQTT_PORT=1883
// MQTT parameters
MQTT_QOS=0
MQTT_RETAIN=false
// Interval requesting the E3/DC S10 device in seconds
POLL_INTERVAL=1
```

## Compilation

```
Expand All @@ -101,6 +126,47 @@ Adjust user and group (pi:pi) if you use another user.
cp -a s10m /opt/s10m
```

## Configuration

Copy the config template file into the directory `/opt/s10m`
```
cp config.template /opt/s10m/.config
```

Please change to the directory `/opt/s10m` and edit `.config` to adjust to your configuration:

```
cd /opt/s10m
nano .config
```

```
// Host name of the E3/DC S10 device
MODBUS_HOST=e3dc
// Port of the E3/DC S10 device, default is 502
MODBUS_PORT=502
// Target MQTT broker
MQTT_HOST=localhost
// Default port is 1883
MQTT_PORT=1883
// MQTT user / password authentication necessary? Depends on the MQTT broker configuration.
MQTT_AUTH=false
// if true, then enter here
MQTT_USER=
MQTT_PASSWORD=
// MQTT parameters
MQTT_QOS=0
MQTT_RETAIN=false
// Interval requesting the E3/DC S10 device in seconds
INTERVAL=1
// Root topic
ROOT_TOPIC=s10
// Force mode (publish also unchanged topics)
FORCE=false
```

s10m will also start wihout a `.config` file. In this case s10m will use the default values.

## Test

Start the program:
Expand Down Expand Up @@ -169,7 +235,7 @@ Start the program in daemon mode:
./s10m -d
```

If you like to start `s10m` during the system start, use `/etc/rc.local`. Add the following line before `exit 0`.
If you like to start s10m during the system start, use `/etc/rc.local`. Add the following line before `exit 0`.

```
(cd /opt/s10m ; /usr/bin/sudo -H -u pi /opt/s10m/s10m -d)
Expand All @@ -182,6 +248,18 @@ pkill s10m
```
Be careful that the program runs only once.

Alternatively, s10m can be managed by systemd. To do this, copy the file `s10m.service` to the systemd directory:
```
sudo cp -a s10m.service /etc/systemd/system/
```
Configure the service `sudo nano s10m.service` (adjust user 'User=pi'), if needed.

Register the service and start it with:
```
sudo systemctl start s10m
sudo systemctl enable s10m
```

## Used external libraries

- Eclipse Mosquitto (https://github.com/eclipse/mosquitto)
Expand Down
12 changes: 12 additions & 0 deletions config.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
MODBUS_HOST=e3dc
MODBUS_PORT=502
MQTT_HOST=mqttbroker
MQTT_PORT=1883
MQTT_AUTH=false
MQTT_USER=
MQTT_PASSWORD=
MQTT_RETAIN=false
MQTT_QOS=0
INTERVAL=1
ROOT_TOPIC=s10
FORCE=false
Loading

0 comments on commit 34d0876

Please sign in to comment.