Skip to content
Snippets Groups Projects
Commit cb58a718 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 de03c0c6
No related branches found
No related tags found
No related merge requests found
...@@ -190,21 +190,23 @@ int mqtt_lputs(struct mqtt* mqtt, enum topic_depth depth, int level, const char* ...@@ -190,21 +190,23 @@ int mqtt_lputs(struct mqtt* mqtt, enum topic_depth depth, int level, const char*
if(mqtt->handle != NULL && str != NULL) { if(mqtt->handle != NULL && str != NULL) {
int result; int result;
char sub[128]; char sub[128];
if(mqtt->cfg->mqtt.protocol_version < 5) { mqtt_topic(mqtt, depth, sub, sizeof(sub), "log/%d", level);
mqtt_topic(mqtt, depth, sub, sizeof(sub), "log/%d", level); char timestamp[32];
result = mosquitto_publish_v5(mqtt->handle, mosquitto_property* props = NULL;
/* mid: */NULL, time_to_isoDateTimeStr(time(NULL), xpTimeZone_local(), timestamp, sizeof(timestamp));
/* topic: */sub, mosquitto_property_add_string_pair(&props, MQTT_PROP_USER_PROPERTY, "time", timestamp);
/* payloadlen */strlen(str), result = mosquitto_publish_v5(mqtt->handle,
/* payload */str, /* mid: */NULL,
/* qos */mqtt->cfg->mqtt.publish_qos, /* topic: */sub,
/* retain */true, /* payloadlen */strlen(str),
/* properties */NULL); /* payload */str,
} else { /* qos */mqtt->cfg->mqtt.publish_qos,
/* retain */true,
/* properties */props);
if(result == MQTT_SUCCESS) {
mqtt_topic(mqtt, depth, sub, sizeof(sub), "log"); mqtt_topic(mqtt, depth, sub, sizeof(sub), "log");
char lvl[32]; char lvl[32];
sprintf(lvl, "%d", level); sprintf(lvl, "%d", level);
mosquitto_property* props = NULL;
mosquitto_property_add_string_pair(&props, MQTT_PROP_USER_PROPERTY, "level", lvl); mosquitto_property_add_string_pair(&props, MQTT_PROP_USER_PROPERTY, "level", lvl);
result = mosquitto_publish_v5(mqtt->handle, result = mosquitto_publish_v5(mqtt->handle,
/* mid: */NULL, /* mid: */NULL,
...@@ -214,8 +216,8 @@ int mqtt_lputs(struct mqtt* mqtt, enum topic_depth depth, int level, const char* ...@@ -214,8 +216,8 @@ int mqtt_lputs(struct mqtt* mqtt, enum topic_depth depth, int level, const char*
/* qos */mqtt->cfg->mqtt.publish_qos, /* qos */mqtt->cfg->mqtt.publish_qos,
/* retain */true, /* retain */true,
/* properties */props); /* properties */props);
mosquitto_property_free_all(&props);
} }
mosquitto_property_free_all(&props);
return result; return result;
} }
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment