Skip to content

Commit f7ef817

Browse files
authored
Configuration rework (#19)
* Configuration rework (using Viper) * Docker fixes
1 parent d534ea6 commit f7ef817

File tree

30 files changed

+517
-498
lines changed

30 files changed

+517
-498
lines changed

.github/workflows/testing.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
go-version: "^1.17"
2222

2323
- name: Build
24-
run: go build --tags=dev -v ./...
24+
run: go build --tags=dev .
2525

2626
- name: Test
27-
run: go test --short --tags=dev -v ./...
27+
run: go test --short --tags=dev -v ./...

ReadMe.md

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ requires installation of a few C libraries.
1010
ChargePi-go client can be deployed/run in multiple ways:
1111

1212
- standalone
13-
- Docker 🐳 by building the image and running the container
14-
- Docker-compose with SteVe Central System and Watchtower (**recommended for testing only**)
15-
- Docker-compose (client only)
13+
- Docker 🐳 and docker-compose
1614

1715
## 🔌 Charge point specifications
1816

@@ -28,8 +26,10 @@ default settings which require minimal configuration.
2826

2927
### 📑 Logging
3028

31-
ChargePi supports multiple logging outputs. Configure the `logging` property in the [settings](/configs/settings.json)
32-
file. Check out the list below:
29+
Debugging and insight of the charge point made simple. ChargePi supports multiple logging outputs specifying the format
30+
the [settings](/configs/settings.json) file.
31+
32+
Supported formats:
3333

3434
| Logging type | Supported |
3535
|:-----------------------------------:|:---------:|
@@ -41,38 +41,14 @@ For details, check out the [logging](/docs/logging/logging.md) docs.
4141

4242
## ⚡ Quickstart
4343

44-
1. If you want to run SteVe on the same host (_Not recommended in production_):
45-
46-
```bash
47-
git clone https://github.com/RWTH-i5-IDSG/steve
48-
```
49-
50-
Replace SteVe's default Dockerfile with Dockerfile provided [here](build/SteVe/Steve.Dockerfile) to run on
51-
Raspberry Pi.
44+
1. Wire your hardware according to the provided [schematics](/docs/hardware/hardware.md).
5245

53-
2. Wire your hardware according to the provided [schematics](/docs/hardware/hardware.md).
46+
2. Install the [libraries](/docs/client/installing-libraries.md) (if needed).
5447

55-
3. Install the [libraries](/docs/client/installing-libraries.md) (if needed).
56-
57-
4. Configure the settings files according to the hardware and desired functionality:
48+
3. Configure the settings files according to the hardware and desired functionality:
5849
- [client configuration](/docs/client/configuration.md)
5950
- [OCPP configuration](/docs/ocpp/ocpp-16.md)
6051

61-
5. Run the client.
62-
63-
## 🏃 Running standalone
64-
65-
Running the client:
66-
67-
```bash
68-
go run .
69-
```
70-
71-
or compiling and executing the client:
72-
73-
```bash
74-
go build -o chargepi .
75-
./chargepi
76-
```
52+
4. Run the client.
7753

78-
More options available in the [client startup guide](docs/client/running-the-client.md).
54+
Details on how to run the client are described in the [client startup guide](docs/client/running-the-client.md).

build/package/Dockerfile

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,37 @@
1-
FROM golang:1.17-alpine as base
1+
FROM golang:1.17 as base
22

3-
RUN apt-get update \
4-
apt-get upgrade \
5-
apt-get install git \
6-
apt-get install cmake \
3+
COPY . /ChargePi/src
4+
WORKDIR /ChargePi/src
75

8-
# Install dependencies
9-
COPY ../../docs/install-dependencies.sh ~/
10-
RUN chmod +x /install-dependencies.sh
11-
RUN ./install-dependencies.sh 0
6+
ARG READER_CONNECTION_TYPE
7+
ENV READER_CONNECTION_TYPE=$READER_CONNECTION_TYPE
128

13-
COPY ../.. /ChargePi/src
14-
WORKDIR /ChargePi/src
9+
# Install dependencies
10+
RUN chmod +x ./scripts/install-dependencies.sh
11+
RUN ./scripts/install-dependencies.sh $READER_CONNECTION_TYPE 0
1512

1613
# Compile the client
17-
RUN cd ~
18-
RUN go build -o ChargePi .
14+
RUN go mod download
15+
RUN go mod verify
16+
RUN go build -tags="rpi" -o ChargePi .
1917

2018
FROM base as dev
21-
ENTRYPOINT ["go","run","."]
19+
ENTRYPOINT ["go","run", "-tags=rpi","."]
2220

2321
FROM alpine as chargepi
2422

25-
# Reinstall the dependencies because the image is alpine
26-
RUN apt-get update \
27-
apt-get upgrade \
28-
apt-get install git \
29-
apt-get install cmake \
23+
WORKDIR /etc/ChargePi
24+
25+
ARG READER_CONNECTION_TYPE
26+
ENV READER_CONNECTION_TYPE=$READER_CONNECTION_TYPE
3027

3128
# Install dependencies
32-
COPY ../../docs/install-dependencies.sh ~/
33-
RUN chmod +x /install-dependencies.sh
34-
RUN ./install-dependencies.sh 0
29+
RUN chmod +x ./scripts/install-dependencies.sh
30+
RUN ./scripts/install-dependencies.sh $READER_CONNECTION_TYPE 0
3531

3632
COPY --from=base /ChargePi/src/configs /etc/ChargePi/configs
3733
COPY --from=base /ChargePi/src/ChargePi /usr/bin/ChargePi
3834

39-
WORKDIR /etc/ChargePi
40-
4135
ENTRYPOINT ["./chargepi"]
4236

4337
# Test the client
@@ -46,4 +40,4 @@ RUN cp -r configs/ test/ \
4640
&& cd test/ \
4741
&& chmod +x create-test-certs.sh \
4842
&& ./create-test-certs.sh \
49-
CMD ["go", "test","-v"]
43+
CMD ["go", "test","-v", "-tags=dev" ,"./..."]

deployments/docker-compose.steve.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services:
1717
ipv4_address: 172.0.1.120
1818
steve:
1919
build:
20-
dockerfile: ../build/SteVe/Steve.Dockerfile
20+
dockerfile: ./build/SteVe/Steve.Dockerfile
2121
context: ..
2222
volumes:
2323
- ./steve:/code

deployments/docker-compose.yaml

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,8 @@ services:
77
target: chargepi
88
restart: always
99
volumes:
10-
- /configs/:/ChargePi/configs/
11-
labels:
12-
- "com.centurylinklabs.watchtower.enable=true" # change to false if you do not wish to get automatic updates
10+
- ./configs/:/ChargePi/configs/
1311
devices:
1412
- /dev/ttyAMA0:/dev/ttyAMA0
1513
- /dev/mem:/dev/mem
16-
privileged: true
17-
networks:
18-
ocpp_network:
19-
ipv4_address: 172.0.1.124
20-
watchtower:
21-
image: containrrr/watchtower:latest
22-
volumes:
23-
- /var/run/docker.sock:/var/run/docker.sock
24-
volumes:
25-
chargepi:
26-
networks:
27-
ocpp_network:
28-
ipam:
29-
config:
30-
- subnet: 172.0.1.0/24
14+
privileged: true

docs/client/configuration.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
# 🛠️ Configuration
22

3+
## 🚩 Flags and environment variables
4+
5+
Available flags:
6+
7+
| Flag | Short | Description | Default value |
8+
|:-------------------:|:-----:|:-------------------------------:|:-------------:|
9+
| `-settings` | / | Path to the settings file. | |
10+
| `-connector-folder` | / | Path to the connector folder. | |
11+
| `-ocpp-config` | / | Path to the OCPP configuration. | |
12+
| `-auth` | / | Path to the authorization file. | |
13+
| `-debug` | `--d` | Debug mode | false |
14+
| `-api` | `--a` | Expose the API | false |
15+
| `-api-address` | / | API address | "localhost" |
16+
| `-api-port` | / | API port | 4269 |
17+
18+
Environment variables are created automatically thanks to [Viper](https://github.com/spf13/viper) and are prefixed
19+
with `CHARGEPI`. Only the settings (not the ocpp configuration or connectors) are bound to the env
20+
variables. Debug mode and API settings flags are also bound to the environment variables.
21+
22+
Example environment variable: `CHARGEPI_CHARGEPOINT_INFO_ID`.
23+
24+
## 🛠 Configuration files
25+
326
There are three **required** configuration files:
427

528
1. [`settings`](../../configs/settings.json)
629
2. [`configuration`](../../configs/configuration.json)
730
3. [`connector`](../../configs/connectors/connector-1.json)
831

9-
The settings files are supported in `YAML`, `JSON` or `TOML` format. All files must be only in one format. The format is
10-
configurable though program flags.
32+
The settings files are supported in `YAML`, `JSON` or `TOML` format.
1133

12-
## The `settings` file
34+
### The `settings` file
1335

1436
The `settings` file contains basic information about the charge point and provides connectivity details:
1537

@@ -95,7 +117,7 @@ Example settings:
95117
}
96118
```
97119

98-
## 🔌 The `connector` file(s) - EVSEs and connectors
120+
### 🔌 The `connector` file(s) - EVSEs and connectors
99121

100122
EVSE and connector settings files can be found in the `connectors` folder. To add and configure the connector, simply
101123
add a new file that contains the structure, defined in [attributes](#attributes) and modify it to your specs. The client
@@ -104,7 +126,7 @@ will scan the folder at boot and configure the connectors from the files if all
104126
Note: A Charge point can have multiple EVSEs, each oh which can have multiple connectors, but only one connector of the
105127
EVSE can charge at a time.
106128

107-
### Attributes
129+
#### Attributes
108130

109131
`Connector` object contains a connector type and an ID of the connector, which must start with 1 and increment by one.
110132
The status attribute changes according to the OCPP specification. The `session` represents a Charging session and is

docs/client/installing-libraries.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
The process of installing the dependencies was automated by creating a [script](../install-dependencies.sh) for
66
installing the necessary dependencies. The script has the following arguments:
77

8-
| Argument | Default value | Description |
9-
|:--------:|:-------------:|:-----------------------------------------------------------------------------------------------------------:|
10-
| 0 | "pn532_i2c" | The libnfc configuration for PN532 RFID card reader. Possible values are: pn532_uart, pn532_i2c, pn532_spi. |
11-
| 1 | false (0) | Whether or not to install Go on the system using a shell script. |
8+
| Argument | Default value | Description |
9+
|:--------:|:-------------:|:-----------------------------------------------------------------------------------------------------------------:|
10+
| 0 | "pn532_i2c" | The libnfc configuration for PN532 RFID card reader. Possible values are: `pn532_uart`, `pn532_i2c`, `pn532_spi`. |
11+
| 1 | false (0) | Whether or not to install Go on the system using a shell script. |
1212

1313
Example usage:
1414

docs/client/running-the-client.md

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,26 @@
11
# 🏃 Running the client
22

3+
This guide assumes you already have a working OCPP management/central system. If you do not have one already,
4+
check out [SteVe](https://github.com/RWTH-i5-IDSG/steve) and set it up according to their guide.
5+
36
## Standalone
47

5-
This client uses **[SteVe](https://github.com/RWTH-i5-IDSG/steve)** for the Central System, but can connect to other
6-
Central Systems as well. Before you run/connect the client, make sure the backend is available and the charge point is
7-
registered.
8+
Before you run/connect the client, make sure the backend is available and the charge point is
9+
registered. Also, **libnfc** should be installed (a convenience script is available).
810

9-
1. Running the program in Golang:
11+
Running the client:
1012

1113
```bash
12-
go run .
14+
go run -tags=rpi .
1315
```
1416

15-
2. Compiling and executing the program:
17+
or compiling and executing the client:
1618

1719
```bash
18-
go build -o chargepi .
20+
go build -tags=rpi -o chargepi .
1921
./chargepi
2022
```
2123

22-
### 🚩 Client flags/options
23-
24-
| Flag | Short | Description | Default value |
25-
|:-------------------:|:-----:|:-------------------------------:|:-------------:|
26-
| `-settings` | / | Path to the settings file. | |
27-
| `-connector-folder` | / | Path to the connector folder. | |
28-
| `-ocpp-config` | / | Path to the OCPP configuration. | |
29-
| `-auth` | / | Path to the authorization file. | |
30-
| `-debug` | `--d` | Debug mode | false |
31-
| `-api` | `--a` | Expose the API | false |
32-
| `-api-address` | / | API address | "localhost" |
33-
| `-api-port` | / | API port | 4269 |
34-
3524
## 🐳 Deploying on Docker
3625

3726
1. Build the client image on Docker:
@@ -49,20 +38,14 @@ registered.
4938

5039
## Deploying using docker-compose
5140

52-
Alternatively, you can run the client, SteVe server and Watchtower on the same Pi using **docker-compose**.
53-
The **[Watchtower](https://github.com/containrrr/watchtower)** service will automatically pull the newest image and run
54-
it when it is available.
55-
56-
1. Change the IP address under __serverUri__ in the settings file to **172.0.1.121**.
57-
58-
2. Build services:
41+
2. Build the ChargePi client:
5942

6043
```bash
61-
docker-compose build
44+
docker-compose -f ./deployments build .
6245
```
6346

6447
3. Run services in daemon mode:
6548

6649
```bash
67-
docker-compose up -d
50+
docker-compose -f ./deployments up -d
6851
```

docs/contribution/adding-support-for-hardware.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ➡️Adding support for hardware
1+
# ➡️Adding hardware support
22

33
There are four hardware component groups that are included in the project:
44

0 commit comments

Comments
 (0)