From 2204d3d6ee5791499468df11755adad044971b03 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 28 Feb 2020 18:26:20 +0100 Subject: [PATCH] BSB daemon: Frames should be ephemeral in MQTT --- bsb/daemon/burrow-bsbd.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/bsb/daemon/burrow-bsbd.c b/bsb/daemon/burrow-bsbd.c index 05e54ae..a387079 100644 --- a/bsb/daemon/burrow-bsbd.c +++ b/bsb/daemon/burrow-bsbd.c @@ -49,6 +49,22 @@ static void mqtt_publish(const char *topic, const char *fmt, ...) va_end(args); } +static void mqtt_publish_ephemeral(const char *topic, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + + if (mqtt_connected) { + char m[256]; + int l = vsnprintf(m, sizeof(m), fmt, args); + int err = mosquitto_publish(mosq, NULL, topic, l, m, 0, false); + if (err != MOSQ_ERR_SUCCESS) + msg(L_ERROR, "Mosquitto: Publish failed, error=%d", err); + } + + va_end(args); +} + static void mqtt_conn_callback(struct mosquitto *mosq UNUSED, void *obj UNUSED, int status) { if (!status) { @@ -162,7 +178,7 @@ static void process_stats(time_t t, byte *resp, uint len) { for (uint i=0; i < ARRAY_SIZE(stat_names) && 4*i + 3 < (uint) len; i++) { char item[64]; - snprintf(item, sizeof(item), "burrow/bsb/stats/%s", stat_names[i]); + snprintf(item, sizeof(item), "bsb/stats/%s", stat_names[i]); mqtt_publish(item, "%u", (uint) get_u32_le(resp+4*i), t); } } @@ -251,7 +267,7 @@ static void process_frame(time_t t, byte *pkt, uint len) char hex[3*len + 1]; mem_to_hex(hex, pkt, len, ' '); - mqtt_publish("bsb/frame", "%s", hex, t); + mqtt_publish_ephemeral("bsb/frame", "%s", hex, t); msg(L_DEBUG, "<< %s", hex); -- 2.39.2