Expose broker publish acknowledgments for MQTT validation

This commit is contained in:
mikecarper committed 2026-10-10 15:01:14 -07:00
1 parent 7acc637468
commit ef80f29337
6 files changed
+452 -9

No files matched your search

@@ -657,6 +657,11 @@ unsigned long PsychicMqttClient::getPublishOk()
return _publish_ok;
}
unsigned long PsychicMqttClient::getPublishAck()
{
return _publish_ack.load(std::memory_order_relaxed);
}
unsigned long PsychicMqttClient::getPublishErr()
{
return _publish_err;
@@ -832,6 +837,7 @@ void PsychicMqttClient::_onMessage(esp_mqtt_event_handle_t &event)
void PsychicMqttClient::_onPublish(esp_mqtt_event_handle_t &event)
{
_publish_ack.fetch_add(1, std::memory_order_relaxed);
ESP_LOGI(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
for (uint8_t i = 0; i < _onPublishUserCallbackCount; ++i)
{
@@ -31,6 +31,7 @@
* SOFTWARE.
*/
#include <atomic>
#include <functional>
#include "Arduino.h"
@@ -471,6 +472,13 @@ public:
*/
unsigned long getPublishOk();
/**
* @brief Cumulative QoS 1/2 publishes acknowledged by the broker during
* this client's lifetime. Counts MQTT_EVENT_PUBLISHED, not accepted writes
* or outbox expiry. MeshCore's QoS 1 status messages complete on PUBACK.
*/
unsigned long getPublishAck();
/**
* @brief Cumulative count of publishes that failed (negative return from the
* synchronous write or async enqueue -- socket error / network timeout). Monotonic.
@@ -495,6 +503,8 @@ private:
// Cumulative publish accept/fail counts (any QoS, sync or async path).
unsigned long _publish_ok = 0;
unsigned long _publish_err = 0;
// Written by the SDK event task and read by the bridge/CLI task.
std::atomic<unsigned long> _publish_ack{0};
// Multipart message reassembly. _buffer is lazily allocated at connect() time
// to match the configured buffer size, then reused for the client's lifetime.