diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index 383ee1725..c7ed77152 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -1940,7 +1940,8 @@ bool MyMesh::completeNeighborDiscoverEntry() { size_t added = MQTTMessageBuilder::measureNeighborsMessageEntry(measured); if (neighbor_discover_publish_count > 0) added++; // array comma - if (neighbor_discover_json_size + added >= MQTTBridge::NEIGHBORS_JSON_BUFFER_SIZE) { + if (neighbor_discover_json_size + added >= MQTTBridge::NEIGHBORS_JSON_BUFFER_SIZE || + neighbor_discover_publish_count >= MQTTBridge::NEIGHBORS_MAX_PUBLISH_ENTRIES) { neighbor_discover_truncated = true; finishNeighborDiscover(); return false; @@ -2026,7 +2027,7 @@ static bool neighborPublishEntryComesBefore( // single-shot doc (overflow path removes+breaks, so no further growth after free). struct NeighborsDocAllocator : ArduinoJson::Allocator { size_t used = 0; - static const size_t kBudget = MQTTBridge::NEIGHBORS_JSON_BUFFER_SIZE; + static const size_t kBudget = MQTTBridge::NEIGHBORS_DOC_POOL_BUDGET; void* allocate(size_t size) override { if (used >= kBudget || size > kBudget - used) return nullptr; diff --git a/examples/simple_room_server/MyMesh.cpp b/examples/simple_room_server/MyMesh.cpp index 84d22eb79..302db12d7 100644 --- a/examples/simple_room_server/MyMesh.cpp +++ b/examples/simple_room_server/MyMesh.cpp @@ -1826,7 +1826,8 @@ bool MyMesh::completeNeighborDiscoverEntry() { size_t added = MQTTMessageBuilder::measureNeighborsMessageEntry(measured); if (neighbor_discover_publish_count > 0) added++; // array comma - if (neighbor_discover_json_size + added >= MQTTBridge::NEIGHBORS_JSON_BUFFER_SIZE) { + if (neighbor_discover_json_size + added >= MQTTBridge::NEIGHBORS_JSON_BUFFER_SIZE || + neighbor_discover_publish_count >= MQTTBridge::NEIGHBORS_MAX_PUBLISH_ENTRIES) { neighbor_discover_truncated = true; finishNeighborDiscover(); return false; @@ -1910,7 +1911,7 @@ static bool neighborPublishEntryComesBefore( // single-shot doc (overflow path removes+breaks, so no further growth after free). struct NeighborsDocAllocator : ArduinoJson::Allocator { size_t used = 0; - static const size_t kBudget = MQTTBridge::NEIGHBORS_JSON_BUFFER_SIZE; + static const size_t kBudget = MQTTBridge::NEIGHBORS_DOC_POOL_BUDGET; void* allocate(size_t size) override { if (used >= kBudget || size > kBudget - used) return nullptr; diff --git a/src/helpers/bridges/MQTTBridge.h b/src/helpers/bridges/MQTTBridge.h index afba2018f..446d864ad 100644 --- a/src/helpers/bridges/MQTTBridge.h +++ b/src/helpers/bridges/MQTTBridge.h @@ -515,6 +515,16 @@ public: // persistent buffer and the mesh's transient build buffer. static const size_t NEIGHBORS_JSON_BUFFER_SIZE = 10240; + // The ArduinoJson pool is NOT bounded by the text buffer: v7 hands out pool + // blocks in fixed 4096-byte chunks, so a table that just fits the text buffer + // can still need well over it in pool. Budgeting the pool at the text size + // starves it, and a starved pool sets doc.overflowed() — which drops the whole + // publish instead of truncating. Measured need is 12541 B for 50 entries. + static const size_t NEIGHBORS_DOC_POOL_BUDGET = 16384; + + // Entries per publish; the neighbour cache and text buffer are the real limit. + static const int NEIGHBORS_MAX_PUBLISH_ENTRIES = MAX_NEIGHBOURS; + // Called by the mesh (Core 1) once a neighbor-discovery pass has built the // table JSON. Copies it into the persistent PSRAM buffer and raises the // publish-pending flag for the MQTT task; a request is dropped if one is