Skip to content

Commit 5dd43df

Browse files
committed
v3.24
1 parent 78ffb36 commit 5dd43df

File tree

8 files changed

+286
-35
lines changed

8 files changed

+286
-35
lines changed

DOCKER.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,24 @@ docker run -e TZ=Europe/Berlin --rm -v /path/to/your/.config:/opt/rscp2mqtt/.con
1717
```
1818
docker run -e TZ=Europe/Berlin --rm -v /path/to/your/.config:/opt/rscp2mqtt/.config pvtom/rscp2mqtt:latest-with-influxdb
1919
```
20+
21+
### Start the docker container with TLS to connect the MQTT broker
22+
23+
Depending on the configuration of your TLS environment, adopt your .config file.
24+
25+
Example:
26+
```
27+
MQTT_TLS=true
28+
MQTT_TLS_CAFILE=tls/ca.crt
29+
MQTT_TLS_CERTFILE=tls/client.crt
30+
MQTT_TLS_KEYFILE=tls/client.key
31+
```
32+
33+
Start with
34+
```
35+
docker run -e TZ=Europe/Berlin --rm -v /path/to/your/.config:/opt/rscp2mqtt/.config -v /path/to/your/tls:/opt/rscp2mqtt/tls pvtom/rscp2mqtt:latest
36+
```
37+
or with InfluxDB support
38+
```
39+
docker run -e TZ=Europe/Berlin --rm -v /path/to/your/.config:/opt/rscp2mqtt/.config -v /path/to/your/tls:/opt/rscp2mqtt/tls pvtom/rscp2mqtt:latest-with-influxdb
40+
```

INFLUXDB.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,17 @@ INFLUXDB_2_TOKEN=<my_token>
6363
```
6464

6565
Please use the web admin tool of the InfluxDB v2.x to configure the bucket, the orga and the token.
66+
67+
### TLS encryption
68+
69+
rscp2mqtt uses the library libcurl for the connection to InfluxDB. To establish a TLS connection, please use the following configuration parameters.
70+
```
71+
CURL_HTTPS=true
72+
CURL_OPT_SSL_VERIFYPEER=true
73+
CURL_OPT_SSL_VERIFYHOST=true
74+
CURL_OPT_CAINFO=
75+
CURL_OPT_SSLCERT=
76+
CURL_OPT_SSLKEY=
77+
```
78+
79+
For the configuration of the database look at the official InfluxDB documentation.

MQTT_TLS.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
## MQTT with TLS
2+
3+
rscp2mqtt can connect the MQTT broker using TLS.
4+
5+
### Configuration
6+
7+
Add these lines to the .config file and adjust the values according to your environment:
8+
9+
```
10+
MQTT_TLS=true
11+
MQTT_TLS_CAFILE=/home/pi/ca.crt
12+
MQTT_TLS_CERTFILE=/home/pi/client.crt
13+
MQTT_TLS_KEYFILE=/home/pi/client.key
14+
```
15+
16+
### Certificates and broker configuration
17+
18+
Please follow these commands to create an example environment on your computer with a running Mosquitto broker:
19+
20+
Switch to root
21+
```
22+
sudo -i
23+
```
24+
25+
Create server key file and certificate
26+
```
27+
cd /etc/mosquitto/ca_certificates
28+
29+
openssl genrsa -des3 -out ca.key 2048
30+
openssl req -new -x509 -days 1826 -key ca.key -out ca.crt
31+
32+
cd /etc/mosquitto/certs
33+
34+
openssl genrsa -out mosquitto.key 2048
35+
openssl req -new -out mosquitto.csr -key mosquitto.key
36+
37+
# Common Name = ip address of the server
38+
39+
openssl x509 -req -in mosquitto.csr -CA /etc/mosquitto/ca_certificates/ca.crt -CAkey /etc/mosquitto/ca_certificates/ca.key -CAcreateserial -out mosquitto.crt
40+
```
41+
42+
Create client key file and certificate
43+
```
44+
cd /etc/mosquitto/certs
45+
46+
openssl genrsa -out client.key 2048
47+
openssl req -new -out client.csr -key client.key
48+
49+
# Common Name = ip address of the server
50+
51+
openssl x509 -req -in client.csr -CA /etc/mosquitto/ca_certificates/ca.crt -CAkey /etc/mosquitto/ca_certificates/ca.key -CAcreateserial -out client.crt
52+
53+
chmod a+r *
54+
```
55+
56+
### Broker configuration
57+
```
58+
cd /etc/mosquitto/conf.d
59+
60+
nano 010-listener-with-tls.conf
61+
```
62+
63+
Please insert the following lines into 010-listener-with-tls.conf
64+
```
65+
listener 8883
66+
certfile /etc/mosquitto/certs/mosquitto.crt
67+
keyfile /etc/mosquitto/certs/mosquitto.key
68+
cafile /etc/mosquitto/ca_certificates/ca.crt
69+
require_certificate true
70+
```
71+
72+
Restart the MQTT broker
73+
```
74+
systemctl restart mosquitto.service
75+
```
76+
77+
### Prepare client
78+
79+
Copy client key and certificate
80+
```
81+
cd /home/pi
82+
sudo mv /etc/mosquitto/certs/client.* .
83+
sudo chown pi.pi client.*
84+
cp /etc/mosquitto/ca_certificates/ca.crt .
85+
```
86+
87+
Adjust .config to the ip address (according to the certificate definition) and the new port number
88+
```
89+
MQTT_HOST=192.168.178.123
90+
MQTT_PORT=8883
91+
```
92+
93+
Start rscp2mqtt
94+
95+
Subscribe to the MQTT broker
96+
```
97+
# use the ip address of the server
98+
mosquitto_sub -h 192.168.178.123 -p 8883 -t "#" --cafile /home/pi/ca.crt --cert /home/pi/client.crt --key /home/pi/client.key
99+
```

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ For continuous provision of values, you can configure several topics that are pu
4646
- Query of historical daily values
4747
- Multiple power meters
4848
- Switch between wallboxes
49+
- TLS connections ([MQTT broker](MQTT_TLS.md), InfluxDB)
4950

5051
Please also take a look at the [release notes](RELEASE.md).
5152

@@ -152,19 +153,19 @@ or to show the help page
152153
If everything works properly, you will see something like this:
153154

154155
```
155-
rscp2mqtt [3.23]
156+
rscp2mqtt [3.24]
156157
E3DC system >192.168.178.111:5033< user: >your E3DC user<
157-
MQTT broker >localhost:1883< qos = >0< retain = >false< client id >✗< prefix >e3dc<
158+
MQTT broker >localhost:1883< qos = >0< retain = >false< tls >✗< client id >✗< prefix >e3dc<
158159
Fetching data every second.
159160
Requesting PVI ✓ | PM (0) | DCB ✓ (1 battery string) | Wallbox (0) ✗ | Autorefresh ✓
160-
Log level = 0
161+
Log Level = 2 (BUFFERED)
161162
Stdout to terminal
162163
163-
[2024-05-12 19:00:00] pid=30230 ppid=1 RscpMqttMain.cpp(2952) Connecting to server 192.168.178.111:5033
164-
[2024-05-12 19:00:00] pid=30230 ppid=1 RscpMqttMain.cpp(2959) Success: E3DC connected.
165-
[2024-05-12 19:00:00] pid=30230 ppid=1 RscpMqttMain.cpp(1896) RSCP authentication level 10
166-
[2024-05-12 19:00:00] pid=30230 ppid=1 RscpMqttMain.cpp(2428) Connecting to broker localhost:1883
167-
[2024-05-12 19:00:00] pid=30230 ppid=1 RscpMqttMain.cpp(2440) Success: MQTT broker connected.
164+
[2024-06-01 09:00:00] pid=30240 ppid=1 RscpMqttMain.cpp(3022) Connecting to server 192.168.178.111:5033
165+
[2024-06-01 09:00:00] pid=30240 ppid=1 RscpMqttMain.cpp(3029) Success: E3DC connected.
166+
[2024-06-01 09:00:00] pid=30240 ppid=1 RscpMqttMain.cpp(1903) RSCP authentication level 10
167+
[2024-06-01 09:00:00] pid=30240 ppid=1 RscpMqttMain.cpp(2435) Connecting to broker localhost:1883
168+
[2024-06-01 09:00:00] pid=30240 ppid=1 RscpMqttMain.cpp(2456) Success: MQTT broker connected.
168169
```
169170

170171
Check the configuration if the connections are not established.

RELEASE.md

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

3+
### Release v3.24 (01.06.2024)
4+
5+
Bug fixes:
6+
- Prevention of a program crash when reconnecting to the MQTT broker
7+
8+
Features:
9+
- MQTT with TLS support
10+
- InfluxDB with https
11+
312
### Release v3.23 (12.05.2024)
413

514
Bug fixes:

RscpMqttConfig.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ typedef struct _config_t {
1616
char mqtt_user[128];
1717
char mqtt_password[128];
1818
bool mqtt_auth;
19+
char *mqtt_tls_cafile;
20+
char *mqtt_tls_capath;
21+
char *mqtt_tls_certfile;
22+
char *mqtt_tls_keyfile;
23+
char *mqtt_tls_password;
24+
bool mqtt_tls;
1925
int mqtt_qos;
2026
bool mqtt_retain;
2127
char mqtt_client_id[128];
@@ -32,6 +38,13 @@ typedef struct _config_t {
3238
char influxdb_orga[128];
3339
char influxdb_bucket[128];
3440
char influxdb_token[128];
41+
bool curl_https;
42+
char *curl_protocol;
43+
bool curl_opt_ssl_verifypeer;
44+
bool curl_opt_ssl_verifyhost;
45+
char *curl_opt_cainfo;
46+
char *curl_opt_sslcert;
47+
char *curl_opt_sslkey;
3548
#endif
3649
char prefix[25];
3750
int history_start_year;

0 commit comments

Comments
 (0)