Skip to content

Commit

Permalink
add mqtt integration config file
Browse files Browse the repository at this point in the history
  • Loading branch information
john30 committed Jan 29, 2022
1 parent 6b576c7 commit d868c42
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 0 deletions.
145 changes: 145 additions & 0 deletions contrib/etc/ebusd/mqtt-integration.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Configuration file for ebusd MQTT integration.

# This file allows flexible construction of MQTT topics and payloads depending on message and field definitions as well
# as global status topics.
# It is a set of named variables (or constants) with the name on the left of an equal sign and the value on the right,
# where only the value is allowed to contain references to other variables.
# A reference to a variable is escaped by a leading "%" character in front of the variable name consisting of only
# alphabetic characters or the underscore. A double percent character "%%" is replaced by a single "%" in the value.
# Every variable without an underscore in the name is automatically made available as well with an uppercase name and a
# normalized value composed of only alphanumeric characters or underscore (i.e. suitable for being part of a topic).
# When using "?=" instead of only the equal sign in a variable definition, the variable value is set to empty when one
# of the variables referred to is empty or missing.

# The variable replacements are constructed for each message and/or field (depending on whether the topic is field
# specific or not) in the following order:

# 1. predefined constants from ebusd, i.e.
# %version the ebusd version number.
# %prefix the invariable prefix part of the "--mqtttopic" configuration option, defaults to "ebusd/".
# %prefixn the same as %prefix but without trailing slashes or underscores.

# 2. variables referring to constants only (directly or indirectly).

# 3. circuit and message specific variables:
# %circuit the circuit name.
# %name the message name.
# %priority the message poll priority (or 0).
# %level the message access level (or empty).
# %messagecomment the message comment.
# %direction the message direction ("r", "w", "u", or "uw").
# %topic the message update topic built from the mqtttopic configuration option (only if the topic is not field
# specific) and/or the %topic variable defined here.

# 4. the direction mapped from variables named "direction_map-%direction" with the actual direction in the suffix.
# Available as "%direction_map".

# 5. the field type mapped from variables named "type_map-%direction-%type" or "type_map-%type" as fallback with the
# field type and the optional direction in the suffix. The variable including the direction is evaluated first and
# if it is missing or the result is empty, the variable excluding the direction is used instead.
# This is also an implicit field type filter as missing or empty mappings are not published at all.
# Available as "%type_map".

# 6. other field specific variables for each field (only once for each message if the topic is field specific):
# %index the field index (excluding ignored fields).
# %field the field name (or the field index if no name is defined or the names are not unique in the message).
# %type the field type (one of "number", "list", "string", "date", "time", or "datetime").
# %basetype the base data type ID (e.g. "UCH").
# %comment the field comment (if any).
# %unit the field unit (if any).
# %min and %max the minimum/maximum possible value for number fields.
# %topic the field (or message) update topic built from the mqtttopic configuration option and/or the %topic variable
# defined here.

# 7. optional field type switch in "%type_switch" using the value of the variable named "type_switch-by" and matching it
# against the value lines of the variable named "type_switch-%type" with the field type in the suffix.
# The value of such a variable needs to be a constant list of string pairs with one pair per line. Each pair is
# separated by "=" and the left part is the value set to the "type_switch" variable when the wildcard pattern in the
# right part matches the value of the "type_switch-by" value. The list is traversed from top to bottom with the
# first match stopping the evaluation. Optionally, "type_switch-names" can be used to define a list of variable
# names to be set in addition to the "type_switch" variable, in which case a list of variable names (comma
# separated) is expected as "type_switch-names" value and the appropriate values to set on the left side of each
# match list entry.
# Available as "%type_switch" and optionally by the set of fields as defined in "%type_switch-names".

# 8. optional field type part mapping in "%type_part" for each field type in variables named "type_part-%type" with the
# field type in the suffix (or the value of the "type_part-by" variable).

# 9. if the %fields_payload variable is used, then it is set to the concatenation of all fields of the message:
# %field_payload is expected to build a single field payload.
# %field-separator is the separator placed between consecutive field payloads.
# %fields_payload is set to the concatenation of all fields of the message, separated by %field-separator.

# 10. %definition-topic, %definition-payload, and %definition-retain to build the message definition topic and payload
# and determine the retain value.


# Before constructing the variable replacements, the messages and fields can optionally be filtered in order to use
# certain message definitions only:

# include only messages having data sent at least once.
filter-seen = 1
# include only messages having a priority less than or equal to the specified value.
#filter-priority =
# include only messages having the specified circuit (partial match, alternatives and wildcard supported).
#filter-circuit =
# include only messages having the specified name (partial match, alternatives and wildcard supported).
#filter-name =
# include only messages having the specified level (partial match, alternatives and wildcard supported).
#filter-level =
# include only messages having the specified direction ("r", "w", "u", or "uw". partial match, alternatives and wildcard supported).
filter-direction = r|u
# include only fields having the specified name (partial match, alternatives and wildcard supported).
#filter-field =



# the field type mapped from variables named "type_map-%direction-%type" or "type_map-%type" as fallback with the
# field type and the optional direction in the suffix. The variable including the direction is evaluated first and
# if it is missing or the result is empty, the variable excluding the direction is used instead.
# This is also an implicit field type filter as missing or empty mappings are not published at all.

type_map-number = number
type_map-list = string
type_map-string = string
type_map-date = string
type_map-time = string
type_map-datetime = string


# the message definition config topic, payload, and retain setting.
definition-topic = %prefixn/config/%CIRCUIT/%NAME/%FIELD
definition-payload = {
"name":"%prefixn %circuit %name %field",
"topic":"%topic"
}
definition-retain = 0


# the message value topic (if other than the default). If set here, it will be replaced by the "--mqtttopic"
# configuration option only if that one contains at least one variable. If the the "--mqtttopic" configuration option
# does not contain any variable, it is taken as prefix and can be used here as well.
#topic=%prefix/%circuit/%name


# the common global config topic, payload, and retain setting (used by running, version, signal, uptime, updatecheck,
# and scan if not otherwise defined explicitly).
def_global-topic = %prefixn/config/global/%FIELD
def_global-payload = {
"name":"%prefixn global %field",
"topic":"%topic"
}
def_global-retain = 0

# individual global running, version, signal, uptime, updatecheck, and scan config topic, payload, and retain setting.
#def_global_running-...
#def_global_version-...
#def_global_signal-...
#def_global_uptime-...
#def_global_updatecheck-...
#def_global_scan-...


# the topic and payload to listen to in order to republish all config messages.
#config_restart-topic =
#config_restart-payload =
13 changes: 13 additions & 0 deletions make_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,18 @@ if [ -n "$reusebuilddir" ] || [ -z "$keepbuilddir" ]; then
fi
make DESTDIR="$PWD/$RELEASE" install-strip || exit 1
extralibs=
mqtt=
ldd $RELEASE/usr/bin/ebusd | egrep -q libmosquitto.so.0
if [ $? -eq 0 ]; then
extralibs=', libmosquitto0'
PACKAGE="${PACKAGE}_mqtt0"
mqtt=1
else
ldd $RELEASE/usr/bin/ebusd | egrep -q libmosquitto.so.1
if [ $? -eq 0 ]; then
extralibs=', libmosquitto1'
PACKAGE="${PACKAGE}_mqtt1"
mqtt=1
fi
fi

Expand Down Expand Up @@ -105,6 +108,10 @@ cp contrib/debian/systemd/ebusd.service $RELEASE/lib/systemd/system/ebusd.servic
mkdir -p $RELEASE/etc/init.d || exit 1
cp contrib/debian/init.d/ebusd $RELEASE/etc/init.d/ebusd || exit 1
cp contrib/debian/default/ebusd $RELEASE/etc/default/ebusd || exit 1
if [ -n "$mqtt" ]; then
mkdir -p $RELEASE/etc/ebusd || exit 1
cp contrib/etc/ebusd/mqtt*.cfg $RELEASE/etc/ebusd/ || exit 1
fi
cp contrib/etc/logrotate.d/ebusd $RELEASE/etc/logrotate.d/ || exit 1
cp ChangeLog.md $RELEASE/DEBIAN/changelog || exit 1
cat <<EOF > $RELEASE/DEBIAN/control
Expand Down Expand Up @@ -132,6 +139,12 @@ EOF
cat <<EOF > $RELEASE/DEBIAN/conffiles
/etc/default/ebusd
EOF
if [ -n "$mqtt" ]; then
echo '/etc/ebusd' >> $RELEASE/DEBIAN/dirs
for i in contrib/etc/ebusd/mqtt*.cfg; do
echo "${i##contrib}" >> $RELEASE/DEBIAN/conffiles
done
fi
cat <<EOF > $RELEASE/DEBIAN/postinst
#!/bin/sh
if [ -d /run/systemd/system ]; then
Expand Down

0 comments on commit d868c42

Please sign in to comment.