From 6e35116b3475840118fae53a75d711a3c246ea77 Mon Sep 17 00:00:00 2001 From: "Rob Swindell (on Windows)" <rob@synchro.net> Date: Tue, 12 Sep 2023 18:31:07 -0700 Subject: [PATCH] Fix log topic publishing when using MQTT v3 Apparently if you call mosquitto_publish_v5() with a non-NULL properties pointer, it'll only publish via protocol v5 and doesn't work if you're using protocol v3 connection. Thanks Ree. --- src/sbbs3/mqtt.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/sbbs3/mqtt.c b/src/sbbs3/mqtt.c index d19c6fe5df..f917eac53e 100644 --- a/src/sbbs3/mqtt.c +++ b/src/sbbs3/mqtt.c @@ -191,10 +191,12 @@ int mqtt_lputs(struct mqtt* mqtt, enum topic_depth depth, int level, const char* int result; char sub[128]; mqtt_topic(mqtt, depth, sub, sizeof(sub), "log/%d", level); - char timestamp[32]; mosquitto_property* props = NULL; - time_to_isoDateTimeStr(time(NULL), xpTimeZone_local(), timestamp, sizeof(timestamp)); - mosquitto_property_add_string_pair(&props, MQTT_PROP_USER_PROPERTY, "time", timestamp); + if(mqtt->cfg->mqtt.protocol_version >= 5) { + char timestamp[32]; + time_to_isoDateTimeStr(time(NULL), xpTimeZone_local(), timestamp, sizeof(timestamp)); + mosquitto_property_add_string_pair(&props, MQTT_PROP_USER_PROPERTY, "time", timestamp); + } result = mosquitto_publish_v5(mqtt->handle, /* mid: */NULL, /* topic: */sub, @@ -205,9 +207,11 @@ int mqtt_lputs(struct mqtt* mqtt, enum topic_depth depth, int level, const char* /* properties */props); if(result == MQTT_SUCCESS) { mqtt_topic(mqtt, depth, sub, sizeof(sub), "log"); - char lvl[32]; - sprintf(lvl, "%d", level); - mosquitto_property_add_string_pair(&props, MQTT_PROP_USER_PROPERTY, "level", lvl); + if(mqtt->cfg->mqtt.protocol_version >= 5) { + char lvl[32]; + sprintf(lvl, "%d", level); + mosquitto_property_add_string_pair(&props, MQTT_PROP_USER_PROPERTY, "level", lvl); + } result = mosquitto_publish_v5(mqtt->handle, /* mid: */NULL, /* topic: */sub, -- GitLab