From a36d323f2bf4aa44d7ed2c7076bb90d696eaa10e Mon Sep 17 00:00:00 2001 From: Orne Brocaar Date: Thu, 19 Jan 2023 12:01:20 +0000 Subject: [PATCH] Migrate to topic prefix instead of individual topic config. This makes the configuration easier, as well if new topics are added in the future, there is no need to update all the configuration files again to add the missing topic configuration. --- chirpstack/configuration/region_as923.toml | 11 ++++---- chirpstack/configuration/region_as923_2.toml | 11 ++++---- chirpstack/configuration/region_as923_3.toml | 11 ++++---- chirpstack/configuration/region_as923_4.toml | 11 ++++---- chirpstack/configuration/region_au915_0.toml | 11 ++++---- chirpstack/configuration/region_au915_1.toml | 11 ++++---- chirpstack/configuration/region_au915_2.toml | 11 ++++---- chirpstack/configuration/region_au915_3.toml | 11 ++++---- chirpstack/configuration/region_au915_4.toml | 11 ++++---- chirpstack/configuration/region_au915_5.toml | 11 ++++---- chirpstack/configuration/region_au915_6.toml | 11 ++++---- chirpstack/configuration/region_au915_7.toml | 11 ++++---- chirpstack/configuration/region_cn470_0.toml | 11 ++++---- chirpstack/configuration/region_cn470_1.toml | 11 ++++---- chirpstack/configuration/region_cn470_10.toml | 11 ++++---- chirpstack/configuration/region_cn470_11.toml | 11 ++++---- chirpstack/configuration/region_cn470_2.toml | 11 ++++---- chirpstack/configuration/region_cn470_3.toml | 11 ++++---- chirpstack/configuration/region_cn470_4.toml | 11 ++++---- chirpstack/configuration/region_cn470_5.toml | 11 ++++---- chirpstack/configuration/region_cn470_6.toml | 11 ++++---- chirpstack/configuration/region_cn470_7.toml | 11 ++++---- chirpstack/configuration/region_cn470_8.toml | 11 ++++---- chirpstack/configuration/region_cn470_9.toml | 11 ++++---- chirpstack/configuration/region_cn779.toml | 11 ++++---- chirpstack/configuration/region_eu433.toml | 11 ++++---- chirpstack/configuration/region_eu868.toml | 11 ++++---- chirpstack/configuration/region_in865.toml | 11 ++++---- chirpstack/configuration/region_ism2400.toml | 11 ++++---- chirpstack/configuration/region_kr920.toml | 11 ++++---- chirpstack/configuration/region_ru864.toml | 11 ++++---- chirpstack/configuration/region_us915_0.toml | 11 ++++---- chirpstack/configuration/region_us915_1.toml | 11 ++++---- chirpstack/configuration/region_us915_2.toml | 11 ++++---- chirpstack/configuration/region_us915_3.toml | 11 ++++---- chirpstack/configuration/region_us915_4.toml | 11 ++++---- chirpstack/configuration/region_us915_5.toml | 11 ++++---- chirpstack/configuration/region_us915_6.toml | 11 ++++---- chirpstack/configuration/region_us915_7.toml | 11 ++++---- chirpstack/src/config.rs | 6 ++--- chirpstack/src/gateway/backend/mqtt.rs | 25 +++++++++++++++++-- 41 files changed, 260 insertions(+), 200 deletions(-) diff --git a/chirpstack/configuration/region_as923.toml b/chirpstack/configuration/region_as923.toml index 045be3d0..0992c004 100644 --- a/chirpstack/configuration/region_as923.toml +++ b/chirpstack/configuration/region_as923.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="as923/gateway/+/event/+" - - # Command topic template. - command_topic="as923/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="as923" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_as923_2.toml b/chirpstack/configuration/region_as923_2.toml index 83044b95..04f865e1 100644 --- a/chirpstack/configuration/region_as923_2.toml +++ b/chirpstack/configuration/region_as923_2.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="as923_2/gateway/+/event/+" - - # Command topic template. - command_topic="as923_2/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="as923_2" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_as923_3.toml b/chirpstack/configuration/region_as923_3.toml index c16038cc..7792267d 100644 --- a/chirpstack/configuration/region_as923_3.toml +++ b/chirpstack/configuration/region_as923_3.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="as923_3/gateway/+/event/+" - - # Command topic template. - command_topic="as923_3/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="as923_3" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_as923_4.toml b/chirpstack/configuration/region_as923_4.toml index 3b37e355..d8a17f7a 100644 --- a/chirpstack/configuration/region_as923_4.toml +++ b/chirpstack/configuration/region_as923_4.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="as923_4/gateway/+/event/+" - - # Command topic template. - command_topic="as923_4/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="as923_4" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_au915_0.toml b/chirpstack/configuration/region_au915_0.toml index 79f9dab1..29f903bb 100644 --- a/chirpstack/configuration/region_au915_0.toml +++ b/chirpstack/configuration/region_au915_0.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="au915_0/gateway/+/event/+" - - # Command topic template. - command_topic="au915_0/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="au915_0" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_au915_1.toml b/chirpstack/configuration/region_au915_1.toml index 2395a6da..6d2e31d6 100644 --- a/chirpstack/configuration/region_au915_1.toml +++ b/chirpstack/configuration/region_au915_1.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="au915_1/gateway/+/event/+" - - # Command topic template. - command_topic="au915_1/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="au915_1" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_au915_2.toml b/chirpstack/configuration/region_au915_2.toml index 8e4f56ae..3d1e5e76 100644 --- a/chirpstack/configuration/region_au915_2.toml +++ b/chirpstack/configuration/region_au915_2.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="au915_2/gateway/+/event/+" - - # Command topic template. - command_topic="au915_2/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="au915_2" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_au915_3.toml b/chirpstack/configuration/region_au915_3.toml index 297bbad8..c1098c7b 100644 --- a/chirpstack/configuration/region_au915_3.toml +++ b/chirpstack/configuration/region_au915_3.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="au915_3/gateway/+/event/+" - - # Command topic template. - command_topic="au915_3/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="au915_3" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_au915_4.toml b/chirpstack/configuration/region_au915_4.toml index 755446c7..ec51fef9 100644 --- a/chirpstack/configuration/region_au915_4.toml +++ b/chirpstack/configuration/region_au915_4.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="au915_4/gateway/+/event/+" - - # Command topic template. - command_topic="au915_4/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="au915_4" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_au915_5.toml b/chirpstack/configuration/region_au915_5.toml index 06178a6a..59b5f404 100644 --- a/chirpstack/configuration/region_au915_5.toml +++ b/chirpstack/configuration/region_au915_5.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="au915_5/gateway/+/event/+" - - # Command topic template. - command_topic="au915_5/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="au915_5" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_au915_6.toml b/chirpstack/configuration/region_au915_6.toml index 97eb774c..21813443 100644 --- a/chirpstack/configuration/region_au915_6.toml +++ b/chirpstack/configuration/region_au915_6.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="au915_6/gateway/+/event/+" - - # Command topic template. - command_topic="au915_6/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="au915_6" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_au915_7.toml b/chirpstack/configuration/region_au915_7.toml index 5009cfc2..09c5dbab 100644 --- a/chirpstack/configuration/region_au915_7.toml +++ b/chirpstack/configuration/region_au915_7.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="au915_7/gateway/+/event/+" - - # Command topic template. - command_topic="au915_7/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="au915_7" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_cn470_0.toml b/chirpstack/configuration/region_cn470_0.toml index 06457d04..5686f6ee 100644 --- a/chirpstack/configuration/region_cn470_0.toml +++ b/chirpstack/configuration/region_cn470_0.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="cn470_0/gateway/+/event/+" - - # Command topic template. - command_topic="cn470_0/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="cn470_0" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_cn470_1.toml b/chirpstack/configuration/region_cn470_1.toml index 4f6c0d26..277b900f 100644 --- a/chirpstack/configuration/region_cn470_1.toml +++ b/chirpstack/configuration/region_cn470_1.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="cn470_1/gateway/+/event/+" - - # Command topic template. - command_topic="cn470_1/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="cn470_1" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_cn470_10.toml b/chirpstack/configuration/region_cn470_10.toml index 13a80317..bd02dd10 100644 --- a/chirpstack/configuration/region_cn470_10.toml +++ b/chirpstack/configuration/region_cn470_10.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="cn470_10/gateway/+/event/+" - - # Command topic template. - command_topic="cn470_10/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="cn470_10" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_cn470_11.toml b/chirpstack/configuration/region_cn470_11.toml index 0ffbe778..fb043c6a 100644 --- a/chirpstack/configuration/region_cn470_11.toml +++ b/chirpstack/configuration/region_cn470_11.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="cn470_11/gateway/+/event/+" - - # Command topic template. - command_topic="cn470_11/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="cn470_11" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_cn470_2.toml b/chirpstack/configuration/region_cn470_2.toml index 809d5368..bc308251 100644 --- a/chirpstack/configuration/region_cn470_2.toml +++ b/chirpstack/configuration/region_cn470_2.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="cn470_2/gateway/+/event/+" - - # Command topic template. - command_topic="cn470_2/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="cn470_2" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_cn470_3.toml b/chirpstack/configuration/region_cn470_3.toml index 5c09a574..6efc24d7 100644 --- a/chirpstack/configuration/region_cn470_3.toml +++ b/chirpstack/configuration/region_cn470_3.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="cn470_3/gateway/+/event/+" - - # Command topic template. - command_topic="cn470_3/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="cn470_3" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_cn470_4.toml b/chirpstack/configuration/region_cn470_4.toml index 5e04b9e8..17f46b85 100644 --- a/chirpstack/configuration/region_cn470_4.toml +++ b/chirpstack/configuration/region_cn470_4.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="cn470_4/gateway/+/event/+" - - # Command topic template. - command_topic="cn470_4/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="cn470_4" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_cn470_5.toml b/chirpstack/configuration/region_cn470_5.toml index eb4d2a51..75256fd9 100644 --- a/chirpstack/configuration/region_cn470_5.toml +++ b/chirpstack/configuration/region_cn470_5.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="cn470_5/gateway/+/event/+" - - # Command topic template. - command_topic="cn470_5/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="cn470_5" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_cn470_6.toml b/chirpstack/configuration/region_cn470_6.toml index fe31e8e9..b1d66930 100644 --- a/chirpstack/configuration/region_cn470_6.toml +++ b/chirpstack/configuration/region_cn470_6.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="cn470_6/gateway/+/event/+" - - # Command topic template. - command_topic="cn470_6/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="cn470_6" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_cn470_7.toml b/chirpstack/configuration/region_cn470_7.toml index 96affe41..70937cf8 100644 --- a/chirpstack/configuration/region_cn470_7.toml +++ b/chirpstack/configuration/region_cn470_7.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="cn470_7/gateway/+/event/+" - - # Command topic template. - command_topic="cn470_7/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="cn470_7" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_cn470_8.toml b/chirpstack/configuration/region_cn470_8.toml index 332bca68..8fcf3b03 100644 --- a/chirpstack/configuration/region_cn470_8.toml +++ b/chirpstack/configuration/region_cn470_8.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="cn470_8/gateway/+/event/+" - - # Command topic template. - command_topic="cn470_8/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="cn470_8" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_cn470_9.toml b/chirpstack/configuration/region_cn470_9.toml index e00e08b3..87973f70 100644 --- a/chirpstack/configuration/region_cn470_9.toml +++ b/chirpstack/configuration/region_cn470_9.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="cn470_9/gateway/+/event/+" - - # Command topic template. - command_topic="cn470_9/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="cn470_9" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_cn779.toml b/chirpstack/configuration/region_cn779.toml index 42826b2a..94aa1635 100644 --- a/chirpstack/configuration/region_cn779.toml +++ b/chirpstack/configuration/region_cn779.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="cn779/gateway/+/event/+" - - # Command topic template. - command_topic="cn779/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="cn779" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_eu433.toml b/chirpstack/configuration/region_eu433.toml index f59e50b8..c471542c 100644 --- a/chirpstack/configuration/region_eu433.toml +++ b/chirpstack/configuration/region_eu433.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="eu433/gateway/+/event/+" - - # Command topic template. - command_topic="eu433/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="eu433" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_eu868.toml b/chirpstack/configuration/region_eu868.toml index 4b97832a..c87f268a 100644 --- a/chirpstack/configuration/region_eu868.toml +++ b/chirpstack/configuration/region_eu868.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="eu868/gateway/+/event/+" - - # Command topic template. - command_topic="eu868/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="eu868" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_in865.toml b/chirpstack/configuration/region_in865.toml index 8e6b6f1a..6b0930b2 100644 --- a/chirpstack/configuration/region_in865.toml +++ b/chirpstack/configuration/region_in865.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="in865/gateway/+/event/+" - - # Command topic template. - command_topic="in865/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="in865" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_ism2400.toml b/chirpstack/configuration/region_ism2400.toml index 85569a50..9b37d2db 100644 --- a/chirpstack/configuration/region_ism2400.toml +++ b/chirpstack/configuration/region_ism2400.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="ism2400/gateway/+/event/+" - - # Command topic template. - command_topic="ism2400/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="ism2400" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_kr920.toml b/chirpstack/configuration/region_kr920.toml index 2b171fdb..c20a9dbb 100644 --- a/chirpstack/configuration/region_kr920.toml +++ b/chirpstack/configuration/region_kr920.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="kr920/gateway/+/event/+" - - # Command topic template. - command_topic="kr920/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="kr920" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_ru864.toml b/chirpstack/configuration/region_ru864.toml index c173e589..071be02e 100644 --- a/chirpstack/configuration/region_ru864.toml +++ b/chirpstack/configuration/region_ru864.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="ru864/gateway/+/event/+" - - # Command topic template. - command_topic="ru864/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="ru864" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_us915_0.toml b/chirpstack/configuration/region_us915_0.toml index 57260e55..0bca96fd 100644 --- a/chirpstack/configuration/region_us915_0.toml +++ b/chirpstack/configuration/region_us915_0.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="us915_0/gateway/+/event/+" - - # Command topic template. - command_topic="us915_0/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="us915_0" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_us915_1.toml b/chirpstack/configuration/region_us915_1.toml index 84af517c..2ed6b3fe 100644 --- a/chirpstack/configuration/region_us915_1.toml +++ b/chirpstack/configuration/region_us915_1.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="us915_1/gateway/+/event/+" - - # Command topic template. - command_topic="us915_1/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="us915_1" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_us915_2.toml b/chirpstack/configuration/region_us915_2.toml index fe62a5e3..7d906cd6 100644 --- a/chirpstack/configuration/region_us915_2.toml +++ b/chirpstack/configuration/region_us915_2.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="us915_2/gateway/+/event/+" - - # Command topic template. - command_topic="us915_2/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="us915_2" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_us915_3.toml b/chirpstack/configuration/region_us915_3.toml index 68dd36c4..708e810b 100644 --- a/chirpstack/configuration/region_us915_3.toml +++ b/chirpstack/configuration/region_us915_3.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="us915_3/gateway/+/event/+" - - # Command topic template. - command_topic="us915_3/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="us915_3" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_us915_4.toml b/chirpstack/configuration/region_us915_4.toml index 518f1177..bd0ac39c 100644 --- a/chirpstack/configuration/region_us915_4.toml +++ b/chirpstack/configuration/region_us915_4.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="us915_4/gateway/+/event/+" - - # Command topic template. - command_topic="us915_4/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="us915_4" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_us915_5.toml b/chirpstack/configuration/region_us915_5.toml index f1f69ceb..3d27aaf6 100644 --- a/chirpstack/configuration/region_us915_5.toml +++ b/chirpstack/configuration/region_us915_5.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="us915_5/gateway/+/event/+" - - # Command topic template. - command_topic="us915_5/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="us915_5" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_us915_6.toml b/chirpstack/configuration/region_us915_6.toml index b2a621d7..d02d935c 100644 --- a/chirpstack/configuration/region_us915_6.toml +++ b/chirpstack/configuration/region_us915_6.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="us915_6/gateway/+/event/+" - - # Command topic template. - command_topic="us915_6/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="us915_6" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/configuration/region_us915_7.toml b/chirpstack/configuration/region_us915_7.toml index 7f83bbfd..f563ce3f 100644 --- a/chirpstack/configuration/region_us915_7.toml +++ b/chirpstack/configuration/region_us915_7.toml @@ -30,11 +30,12 @@ # MQTT configuration. [regions.gateway.backend.mqtt] - # Event topic template. - event_topic="us915_7/gateway/+/event/+" - - # Command topic template. - command_topic="us915_7/gateway/{{ gateway_id }}/command/{{ command }}" + # Topic prefix. + # + # The topic prefix can be used to define the region of the gateway. + # Note, there is no need to add a trailing '/' to the prefix. The trailing + # '/' is automatically added to the prefix if it is configured. + topic_prefix="us915_7" # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) server="tcp://$MQTT_BROKER_HOST:1883" diff --git a/chirpstack/src/config.rs b/chirpstack/src/config.rs index 786a7fea..f46c7cf4 100644 --- a/chirpstack/src/config.rs +++ b/chirpstack/src/config.rs @@ -542,9 +542,7 @@ impl Default for Region { backend: GatewayBackend { enabled: "mqtt".into(), mqtt: GatewayBackendMqtt { - event_topic: "eu868/gateway/+/event/+".into(), - command_topic: "eu868/gateway/{{ gateway_id }}/command/{{ command }}" - .into(), + topic_prefix: "eu868".into(), ..Default::default() }, }, @@ -621,6 +619,7 @@ pub struct GatewayBackend { #[derive(Serialize, Deserialize, Clone)] #[serde(default)] pub struct GatewayBackendMqtt { + pub topic_prefix: String, pub event_topic: String, pub command_topic: String, pub server: String, @@ -639,6 +638,7 @@ pub struct GatewayBackendMqtt { impl Default for GatewayBackendMqtt { fn default() -> Self { GatewayBackendMqtt { + topic_prefix: "".into(), event_topic: "".into(), command_topic: "".into(), server: "tcp://127.0.0.1:1883/".into(), diff --git a/chirpstack/src/gateway/backend/mqtt.rs b/chirpstack/src/gateway/backend/mqtt.rs index fa114557..27cfdae6 100644 --- a/chirpstack/src/gateway/backend/mqtt.rs +++ b/chirpstack/src/gateway/backend/mqtt.rs @@ -85,7 +85,19 @@ impl<'a> MqttBackend<'a> { ) -> Result> { // topic templates let mut templates = Handlebars::new(); - templates.register_template_string("command_topic", &conf.command_topic)?; + templates.register_template_string( + "command_topic", + if conf.command_topic.is_empty() { + let command_topic = "gateway/{{ gateway_id }}/command/{{ command }}".to_string(); + if conf.topic_prefix.is_empty() { + command_topic + } else { + format!("{}/{}", conf.topic_prefix, command_topic) + } + } else { + conf.command_topic.clone() + }, + )?; // get client id, this will generate a random client_id when no client_id has been // configured. @@ -211,7 +223,16 @@ impl<'a> MqttBackend<'a> { // (Re)subscribe loop. tokio::spawn({ let region_config_id = region_config_id.to_string(); - let event_topic = conf.event_topic.clone(); + let event_topic = if conf.event_topic.is_empty() { + let event_topic = "gateway/+/event/+".to_string(); + if conf.topic_prefix.is_empty() { + event_topic + } else { + format!("{}/{}", conf.topic_prefix, event_topic) + } + } else { + conf.event_topic.clone() + }; let client = b.client.clone(); let qos = conf.qos as i32;