From 21528df635bca9b4a798e23b50295975f277766b Mon Sep 17 00:00:00 2001 From: QRPp Date: Wed, 2 Jun 2021 12:05:42 +0100 Subject: [PATCH] Call all handlers matching an MQTT message Rather than only the one registered the most recently, as previously. --- src/mgos_mqtt_conn.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mgos_mqtt_conn.c b/src/mgos_mqtt_conn.c index d438804..a5f37db 100644 --- a/src/mgos_mqtt_conn.c +++ b/src/mgos_mqtt_conn.c @@ -165,19 +165,20 @@ static void mgos_mqtt_conn_queue_remove(struct mgos_mqtt_conn *c, static bool call_topic_handler(struct mgos_mqtt_conn *c, int ev, void *ev_data) { + bool handled = false; struct mg_mqtt_message *msg = (struct mg_mqtt_message *) ev_data; struct mgos_mqtt_subscription *s; SLIST_FOREACH(s, &c->subscriptions, next) { if ((ev == MG_EV_MQTT_SUBACK && s->sub_id == msg->message_id) || mg_mqtt_match_topic_expression(s->topic, msg->topic)) { - if (ev == MG_EV_MQTT_PUBLISH && msg->qos > 0) { + if (!handled && ev == MG_EV_MQTT_PUBLISH && msg->qos > 0) { mg_mqtt_puback(c->nc, msg->message_id); } s->handler(c->nc, ev, ev_data, s->user_data); - return true; + handled = true; } } - return false; + return handled; } static void call_conn_handlers(struct mgos_mqtt_conn *c, int ev,