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

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