Skip to content

Commit 9b0d96d

Browse files
committed
Add option to set mqtt version
1 parent 0ed1946 commit 9b0d96d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ingest/api/send_mqtt.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
logger = logging.getLogger(__name__)
88

9+
10+
mqtt_protocols = {
11+
"3.1": mqtt_client.MQTTv31,
12+
"3.1.1": mqtt_client.MQTTv311,
13+
"5": mqtt_client.MQTTv5,
14+
}
15+
916
mqtt_topic_prepend = os.getenv("MQTT_TOPIC_PREPEND", "")
1017
if not mqtt_topic_prepend or mqtt_topic_prepend == "/":
1118
mqtt_topic_prepend = ""
@@ -24,7 +31,10 @@ def on_connect(client, userdata, flags, rc, properties=None):
2431
def on_disconnect(client, userdata, flags, rc, properties):
2532
logger.warning(f"Disconnected from MQTT broker with result code {str(rc)}")
2633

27-
client = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION2)
34+
client = mqtt_client.Client(
35+
mqtt_client.CallbackAPIVersion.VERSION2,
36+
protocol=mqtt_protocols[os.getenv("MQTT_PROTOCOL_VERSION", "5")],
37+
)
2838
client.enable_logger(logger)
2939
client.username_pw_set(mqtt_conf["username"], mqtt_conf["password"])
3040

0 commit comments

Comments
 (0)