From cb58a71895845860f7eb9a10cd63730c2da83199 Mon Sep 17 00:00:00 2001 From: "Rob Swindell (on Windows)" <rob@synchro.net> Date: Tue, 12 Sep 2023 17:37:05 -0700 Subject: [PATCH] Always publish log messages to both .../logs and .../logs/<level> topics ... regardless of the configured MQTT protocol version (v5 or v3.x). Also include an MQTT v5 user-property ("time") with the message's origination time/date stamp in ISO-8601 format in all log messages (to both topics). This will at least double the amount of MQTT log traffic to the broker. When MQTT v5 is used, the additional user-properties will increase it even a little more. Is this what you were suggesting Ree? --- src/sbbs3/mqtt.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/sbbs3/mqtt.c b/src/sbbs3/mqtt.c index fb24170ea7..d19c6fe5df 100644 --- a/src/sbbs3/mqtt.c +++ b/src/sbbs3/mqtt.c @@ -190,21 +190,23 @@ int mqtt_lputs(struct mqtt* mqtt, enum topic_depth depth, int level, const char* if(mqtt->handle != NULL && str != NULL) { int result; char sub[128]; - if(mqtt->cfg->mqtt.protocol_version < 5) { - mqtt_topic(mqtt, depth, sub, sizeof(sub), "log/%d", level); - result = mosquitto_publish_v5(mqtt->handle, - /* mid: */NULL, - /* topic: */sub, - /* payloadlen */strlen(str), - /* payload */str, - /* qos */mqtt->cfg->mqtt.publish_qos, - /* retain */true, - /* properties */NULL); - } else { + 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); + result = mosquitto_publish_v5(mqtt->handle, + /* mid: */NULL, + /* topic: */sub, + /* payloadlen */strlen(str), + /* payload */str, + /* qos */mqtt->cfg->mqtt.publish_qos, + /* retain */true, + /* properties */props); + if(result == MQTT_SUCCESS) { mqtt_topic(mqtt, depth, sub, sizeof(sub), "log"); char lvl[32]; sprintf(lvl, "%d", level); - mosquitto_property* props = NULL; mosquitto_property_add_string_pair(&props, MQTT_PROP_USER_PROPERTY, "level", lvl); result = mosquitto_publish_v5(mqtt->handle, /* mid: */NULL, @@ -214,8 +216,8 @@ int mqtt_lputs(struct mqtt* mqtt, enum topic_depth depth, int level, const char* /* qos */mqtt->cfg->mqtt.publish_qos, /* retain */true, /* properties */props); - mosquitto_property_free_all(&props); } + mosquitto_property_free_all(&props); return result; } #endif -- GitLab