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

Public log messages over MQTT with the 'retain' flag set to true

This can be useful when debugging issues (e.g. crashes) and an MQTT consuming/logging client wasn't connected at the time.
parent 1fc7f464
No related branches found
No related tags found
No related merge requests found
......@@ -2482,7 +2482,7 @@ void output_thread(void* arg)
}
/* Spy on the user remotely */
if(sbbs->cfg.mqtt.enabled) {
int result = mqtt_pub_message(&mqtt, TOPIC_BBS, spy_topic, buf+bufbot, i);
int result = mqtt_pub_message(&mqtt, TOPIC_BBS, spy_topic, buf+bufbot, i, /* retain: */false);
if(result != MQTT_SUCCESS)
lprintf(LOG_WARNING, "%s ERROR %d (%d) publishing node output (%u bytes): %s"
,node, result, errno, i, spy_topic);
......
......@@ -174,7 +174,7 @@ int mqtt_lputs(struct mqtt* mqtt, enum topic_depth depth, int level, const char*
/* payloadlen */strlen(str),
/* payload */str,
/* qos */mqtt->cfg->mqtt.publish_qos,
/* retain */false,
/* retain */true,
/* properties */NULL);
mqtt_topic(mqtt, depth, sub, sizeof(sub), "log");
mosquitto_property* props = NULL;
......@@ -185,7 +185,7 @@ int mqtt_lputs(struct mqtt* mqtt, enum topic_depth depth, int level, const char*
/* payloadlen */strlen(str),
/* payload */str,
/* qos */mqtt->cfg->mqtt.publish_qos,
/* retain */false,
/* retain */true,
/* properties */props);
mosquitto_property_free_all(&props);
return result;
......@@ -266,7 +266,7 @@ int mqtt_pub_uintval(struct mqtt* mqtt, enum topic_depth depth, const char* key,
return MQTT_FAILURE;
}
int mqtt_pub_message(struct mqtt* mqtt, enum topic_depth depth, const char* key, const void* buf, size_t len)
int mqtt_pub_message(struct mqtt* mqtt, enum topic_depth depth, const char* key, const void* buf, size_t len, BOOL retain)
{
if(mqtt == NULL || mqtt->cfg == NULL)
return MQTT_FAILURE;
......@@ -282,7 +282,7 @@ int mqtt_pub_message(struct mqtt* mqtt, enum topic_depth depth, const char* key,
/* payloadlen */len,
/* payload */buf,
/* qos */mqtt->cfg->mqtt.publish_qos,
/* retain */false,
/* retain */retain,
/* properties */NULL);
}
#endif
......
......@@ -53,14 +53,14 @@ struct mqtt {
enum topic_depth {
TOPIC_OTHER,
TOPIC_ROOT, // sbbs/*
TOPIC_BBS, // sbbs/BBS-ID/*
TOPIC_BBS_LEVEL, // sbbs/BBS-ID
TOPIC_HOST, // sbbs/BBS-ID/hostname/*
TOPIC_HOST_LEVEL, // sbbs/BBS-DI/hostname
TOPIC_EVENT, // sbbs/BBS-ID/event/*
TOPIC_SERVER, // sbbs/BBS-ID/server/*
TOPIC_SERVER_LEVEL, // sbbs/BBS-ID/server
TOPIC_ROOT, // sbbs/*
TOPIC_BBS, // sbbs/BBSID/*
TOPIC_BBS_LEVEL, // sbbs/BBSID
TOPIC_HOST, // sbbs/BBSID/host/HOSTNAME/*
TOPIC_HOST_LEVEL, // sbbs/BBSID/host/HOSTNAME
TOPIC_EVENT, // sbbs/BBSID/event/*
TOPIC_SERVER, // sbbs/BBSID/server/SERVER/*
TOPIC_SERVER_LEVEL, // sbbs/BBSID/server/SERVER
};
#define MQTT_SUCCESS 0 // Same as MOSQ_ERR_SUCCESS
......@@ -85,7 +85,7 @@ DLLEXPORT int mqtt_lputs(struct mqtt*, enum topic_depth, int level, const char*
DLLEXPORT int mqtt_pub_noval(struct mqtt*, enum topic_depth, const char* key);
DLLEXPORT int mqtt_pub_strval(struct mqtt*, enum topic_depth, const char* key, const char* str);
DLLEXPORT int mqtt_pub_uintval(struct mqtt*, enum topic_depth, const char* key, ulong value);
DLLEXPORT int mqtt_pub_message(struct mqtt*, enum topic_depth, const char* key, const void* buf, size_t len);
DLLEXPORT int mqtt_pub_message(struct mqtt*, enum topic_depth, const char* key, const void* buf, size_t len, BOOL retain);
DLLEXPORT int mqtt_open(struct mqtt*);
DLLEXPORT void mqtt_close(struct mqtt*);
DLLEXPORT int mqtt_connect(struct mqtt*, const char* bind_address);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment