Skip to content

Commit 8ee255f

Browse files
committed
v1.1: Multiple MQTT brokers
1 parent b80789b commit 8ee255f

File tree

120 files changed

+600
-482
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+600
-482
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 1.1 (2021-05-22)
4+
+ Supports multiple MQTT brokers
5+
36
## 1.0.1 (2021-02-08)
47
+ Changed HomeMatic value request URL from `sysvar.cgi?ise_id` to `state.cgi?datapoint_id` such that `homematic_subscribe` can fetch any datapoint values, not just system variables.
58

LICENSE_Tinkerforge

-123
This file was deleted.

README.md

+71-32
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Sensorlogger
22
Visit the [Sensorlogger website](https://tastyorange.de/projects/sensorlogger.htm) for a more structured documentation. (Auch auf [Deutsch](https://tastyorange.de/projekte/sensorlogger.htm) verfügbar.)
33

4-
Sensorlogger reads sensor data and creates statistical reports in logbook tables. It can redistribute incoming sensor values, but also statistical summary data, to an MQTT broker or to a HomeMatic CCU. Its original purpose was to serve as a logger for a weather station equipped with Tinkerforge sensors, where data has to be averaged and logged every 15 minutes. However, Sensorlogger is very flexible and can be configured to serve many more purposes.
4+
Sensorlogger reads sensor data and creates statistical reports in logbook tables. It can redistribute incoming sensor values, but also statistical summary data, to multiple MQTT brokers or to a HomeMatic CCU. Its original purpose was to serve as a logger for a weather station equipped with Tinkerforge sensors, where data has to be averaged and logged every 15 minutes. However, Sensorlogger is very flexible and can be configured to serve many other purposes.
55

66
![Concept illustration](concept.svg)
77

8-
Supported data sources are (selected) [Tinkerforge](https://www.tinkerforge.com) sensors and JSON structures that can be read via HTTP(s) or from local files. Additionally, you can subscribe to topics broadcast by an MQTT broker and read the values of system variables from a HomeMatic CCU. The values received by MQTT may also be embedded in their own JSON structures.
8+
Supported data sources are (selected) [Tinkerforge](https://www.tinkerforge.com) sensors and JSON structures that can be read via HTTP(s) or from local files. Additionally, you can subscribe to topics that are broadcast by MQTT brokers and read the values of system variables from a HomeMatic CCU. The values received via MQTT may also be embedded in their own JSON structures.
99

1010
In the following listing you see a very simple example for a logbook file. It keeps track of the mean outside temperature and humidity every 30 minutes.
1111

@@ -21,11 +21,11 @@ In the following listing you see a very simple example for a logbook file. It ke
2121

2222
## Data accumu­lation and statisti­cal summary
2323

24-
Sensorlogger is able to read values from Tinkerforge sensors and JSON structures in user-defined **time intervals.** After reading, these values can be forwarded immediately to an MQTT broker or HomeMatic CCU (the XML-API is used to set system variables using their ISE-ID). The values are also stored internally until they become irrelevant for any further statistical analysis.
24+
Sensorlogger is able to read values from Tinkerforge sensors and JSON structures in user-defined **time intervals.** After reading, these values can be forwarded immediately to MQTT brokers or to a HomeMatic CCU (the XML-API is used to set system variables using their ISE-ID). The values are also stored internally until they become irrelevant for any further statistical analysis.
2525

2626
Data can also be received via **interrupts,** for example from Tinkerforge IO bricklets or via subscriptions to MQTT topics.
2727

28-
Optionally, collected data can undergo **statistical processing.** Currently, Sensorlogger can calculate mean, median, sum, minimum, maximum, frequencies, counts and standard deviations. These are calculated for **logbook** columns that users can set up to their own liking in the configuration file. The statistical summary of a measurement cycle is then periodically written to a logbook file and/or broadcast to the MQTT broker or HomeMatic CCU.
28+
Optionally, collected data can undergo **statistical processing.** Currently, Sensorlogger can calculate mean, median, sum, minimum, maximum, frequencies, counts and standard deviations. These are calculated for **logbook** columns that users can set up to their own liking in the configuration file. The statistical summary of a measurement cycle is then periodically written to a logbook file and/or broadcast to the MQTT brokers or a HomeMatic CCU.
2929

3030
## Software requirements
3131

@@ -87,7 +87,7 @@ If you don’t provide the path to a configuration file, Sensorlogger will look
8787

8888
### Sensorlogger as a service
8989

90-
It is recommended to run Sensorlogger with restricted privileges. The setup procedure for an automatic startup at boot time depends on the distribution. For Debian/Raspbian, I use a service file for systemd like the one shown below. It assumes that the executable file named `sensorlogger` is located in the user’s home directory at `/home/username`. I would also use this directory to store the logging information.
90+
It is recommended to run Sensorlogger with restricted privileges. The setup procedure for an automatic startup at boot time depends on the distribution. For Debian/Raspbian, I use a service file for systemd like the one shown below. It assumes that the executable file named `sensorlogger` is located in the user’s home directory at `/home/username`. The configuration file called `config.json` is also located there in this example.
9191

9292
# /etc/systemd/system/sensorlogger.service
9393
# ------------------------------------------
@@ -99,7 +99,7 @@ It is recommended to run Sensorlogger with restricted privileges. The setup proc
9999

100100
[Service]
101101
WorkingDirectory=/home/username
102-
ExecStart=/home/username/sensorlogger
102+
ExecStart=/home/username/sensorlogger /home/username/config.json
103103
User=username
104104
Group=users
105105

@@ -118,7 +118,7 @@ Further below, you will find a complete example configuration. Any Sensorlogger
118118

119119
+ `general` is meant for general settings and remarks (you can add your own). Currently, it only specifies the global event log file for errors and warnings.
120120
+ `tinkerforge` contains the parameters for the connection to the Brick Daemon.
121-
+ `mqtt` contains the parameters for the connection to the MQTT broker.
121+
+ `mqtt` contains the parameters for connections to MQTT brokers.
122122
+ `homematic` contains the parameters for the connection to the XML-API of a HomeMatic CCU.
123123
+ `sensors` contains a description of all sensors from which data should be read. This is a JSON array that can contain an arbitrary number of sensor definition objects.
124124
+ `logbooks` defines logbook files and associated `columns`. It is also a JSON array that can contain an arbitrary number of logbook definitions and their proper columns.
@@ -167,17 +167,22 @@ Shown below is an example configuration file for the following scenario.
167167
"system_restart_command": null
168168
},
169169
170-
"mqtt": {
171-
"comment": "Connecting and communicating with the MQTT broker.",
172-
"host": "192.168.1.3",
173-
"port": 1883,
174-
"qos": 1,
175-
"retained": false,
176-
"connected_topic": "Sensorlogger/status",
177-
"connected_message": "online",
178-
"lwt_topic": "Sensorlogger/status",
179-
"lwt_message": "offline"
180-
},
170+
"mqtt": [
171+
{
172+
"comment": "Connecting and communicating with the MQTT broker.",
173+
"host": "192.168.1.3",
174+
"port": 1883,
175+
"qos": 1,
176+
"retained": false,
177+
"connected_topic": "Sensorlogger/status",
178+
"connected_message": "online",
179+
"lwt_topic": "Sensorlogger/status",
180+
"lwt_message": "offline",
181+
"enable_publish": true,
182+
"enable_subscribe": true,
183+
"topic_domain": ""
184+
}
185+
],
181186
182187
"homematic": {
183188
"comment": "URL of your HomeMatic's XML API",
@@ -318,7 +323,7 @@ Shown below is an example configuration file for the following scenario.
318323

319324
## Tinkerforge settings
320325

321-
Currently, version 2.1.31 (2021-01-15) of the [Tinkerforge](https://www.tinkerforge.com/) C/C++ bindings are used. The following Tinkerforge Bricklets are supported. The table also lists the channel IDs if a Bricklet supports different types of measurements.
326+
Currently, version 2.1.32 (2021-05-06) of the [Tinkerforge](https://www.tinkerforge.com/) C/C++ bindings are used. The following Tinkerforge Bricklets are supported. The table also lists the channel IDs if a Bricklet supports different types of measurements.
322327

323328
| Sensor | Channels |
324329
| ------------------------------ | ------------------------------------------------- |
@@ -580,19 +585,39 @@ Only Tinkerforge IO Bricklets are currently supported as external triggers.
580585

581586
## MQTT settings
582587

583-
The general `mqtt` section is used to configure the connection parameters to the MQTT broker.
588+
The general `mqtt` section is used to configure the parameters for the connections to the MQTT brokers. Any number of MQTT brokers can be set up. The following example shows a configuration for two separate brokers.
584589

585590
```
586-
"mqtt": {
587-
"host": "localhost",
588-
"port": 1883,
589-
"qos": 1,
590-
"retained": false,
591-
"connected_topic": "Sensorlogger/status",
592-
"connected_message": "online",
593-
"lwt_topic": "Sensorlogger/status",
594-
"lwt_message": "offline"
595-
}
591+
"mqtt": [
592+
{
593+
"comment": "Configuration for Broker #1",
594+
"host": "192.168.1.3",
595+
"port": 1883,
596+
"qos": 1,
597+
"retained": false,
598+
"connected_topic": "Sensorlogger/status",
599+
"connected_message": "online",
600+
"lwt_topic": "Sensorlogger/status",
601+
"lwt_message": "offline",
602+
"enable_publish": true,
603+
"enable_subscribe": false,
604+
"topic_domain": ""
605+
},
606+
{
607+
"comment": "Configuration for Broker #2",
608+
"host": "192.168.1.8",
609+
"port": 1883,
610+
"qos": 1,
611+
"retained": false,
612+
"connected_topic": "Sensorlogger/status",
613+
"connected_message": "online",
614+
"lwt_topic": "Sensorlogger/status",
615+
"lwt_message": "offline",
616+
"enable_publish": false,
617+
"enable_subscribe": true,
618+
"topic_domain": "House/Living_Room"
619+
}
620+
]
596621
```
597622

598623
+ `"host":` Hostname or IP address where the MQTT broker can be reached. May be omitted or set to `null` if you don’t want to configure any MQTT connection.
@@ -625,6 +650,18 @@ The general `mqtt` section is used to configure the connection parameters to the
625650

626651
Standard value: `null`
627652

653+
+ `"topic_domain":` Can be used to restrict this broker to a certain set of topics. All topics that this broker handles must start with this string. This parameter can be used as a filter mask when multiple MQTT brokers are defined. If the broker should handle all topics, an empty string can be used.
654+
655+
Standard value: `""`
656+
657+
+ `"enable_publish":` If set to `true`, all values that belong to the topic domain will be published to this MQTT broker. Can be set to `false` to disable publishing to this broker. The connected and LWT messages will be sent to the broker regardless of this parameter.
658+
659+
Standard value: `true`
660+
661+
+ `"enable_subscribe":` If set to `true`, this MQTT broker will be used to subscribe to topics that belong to its topic domain. Can be set to `false` to disable any subscriptions for this broker.
662+
663+
Standard value: `true`
664+
628665
### MQTT sensors
629666

630667
```
@@ -676,7 +713,7 @@ The general `mqtt` section is used to configure the connection parameters to the
676713

677714
Standard value: `false`
678715

679-
+ `"mqtt_publish":` Topic that is used to republish the received and possibly corrected sensor value via MQTT.
716+
+ `"mqtt_publish":` Topic that is used to republish the received and possibly corrected sensor value via MQTT. Cannot be the same topic as `mqtt_subscribe`.
680717

681718
Standard value: `null`
682719

@@ -851,7 +888,9 @@ The `logbooks` key in the configuration file is always a JSON array that may con
851888
]
852889
```
853890

854-
+ `"filename":` Specifies the path and filename where the logbook shall be saved. If set to `null`, the logbook will not be saved as a real file, but statistics will still be forwarded to an MQTT broker or HomeMatic CCU, if intended.
891+
+ `"filename":` Specifies the path and filename where the logbook shall be saved. If set to `null`, the logbook will not be saved as a real file, but statistics will still be published via MQTT or sent to the HomeMatic CCU, if intended.
892+
893+
Standard value: `null`
855894

856895
+ `"cycle_time":` Duration of a measurement cycle. Please note that the cycle time should be well above the rest period (polling intervals) of the individual sensors in order to accumulate some values for the statistics to make sense. The numerical part for this parameter is set under `"value"`, its unit under `"unit"`. The following units are allowed: `"ms"`, `"s"`, `"min"`, `"h"`, `"d"`.
857896

0 commit comments

Comments
 (0)