final chunking

This commit is contained in:
grove5_admin committed 2026-05-01 17:50:58 -07:00
1 parent 9a8a07b17d
commit 393d390853
1 file changed
+4 -8
+4 -8
View File
@@ -123,19 +123,15 @@ void loop() {
if (env.collect(payload)) { if (env.collect(payload)) {
env.toJSON(payload, jsonBuf, sizeof(jsonBuf)); env.toJSON(payload, jsonBuf, sizeof(jsonBuf));
#ifdef ARDUINO_ARCH_ZEPHYR #ifdef ARDUINO_ARCH_ZEPHYR
// Chunk writes to stay under Bridge RPC message size limit (~1KB) // Chunk to stay under Bridge RPC MsgPack limits (~4KB limit)
size_t len = strlen(jsonBuf); size_t len = strlen(jsonBuf);
size_t pos = 0; size_t pos = 0;
while (pos < len) { while (pos < len && client.connected()) {
size_t chunk = min((size_t)256, len - pos); size_t chunk = min((size_t)512, len - pos);
size_t sent = client.write((const uint8_t*)(jsonBuf + pos), chunk); size_t sent = client.write((const uint8_t*)(jsonBuf + pos), chunk);
if (sent == 0) { if (sent == 0) break;
DBG.println("[cultivar] TCP write failed!");
break;
}
pos += sent; pos += sent;
} }
// Send newline separately (readline() needs this delimiter)
client.write((uint8_t)'\n'); client.write((uint8_t)'\n');
DBG.println(jsonBuf); DBG.println(jsonBuf);
#endif #endif