Skip to content
Snippets Groups Projects
Commit 207ed413 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

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?
parent bbe3042a
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #4706 passed
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment