trying chunked json

This commit is contained in:
grove5_admin committed 2026-05-01 17:33:50 -07:00
1 parent 53ec8c6021
commit 9a8a07b17d
1 file changed
+16 -8
+16 -8
View File
@@ -53,13 +53,10 @@ void setup() {
#else
Serial.begin(115200);
#endif
DBG.println("[cultivar] ENV bridge starting...");
Wire1.begin(); // needed for I2C scan + chip probe before env.begin()
// I2C scan — confirms bus and devices before sensor init
DBG.println("\n[cultivar] I2C scan on Wire1:");
DBG.println("[cultivar] I2C scan on Wire1:");
int i2c_found = 0;
for (uint8_t addr = 1; addr < 127; addr++) {
Wire1.beginTransmission(addr);
@@ -126,11 +123,22 @@ void loop() {
if (env.collect(payload)) {
env.toJSON(payload, jsonBuf, sizeof(jsonBuf));
#ifdef ARDUINO_ARCH_ZEPHYR
client.println(jsonBuf);
client.flush(); // push buffered bytes to the bridge — without this,
// payload sits in the 4096-byte buffer until full
#endif
// Chunk writes to stay under Bridge RPC message size limit (~1KB)
size_t len = strlen(jsonBuf);
size_t pos = 0;
while (pos < len) {
size_t chunk = min((size_t)256, len - pos);
size_t sent = client.write((const uint8_t*)(jsonBuf + pos), chunk);
if (sent == 0) {
DBG.println("[cultivar] TCP write failed!");
break;
}
pos += sent;
}
// Send newline separately (readline() needs this delimiter)
client.write((uint8_t)'\n');
DBG.println(jsonBuf);
#endif
} else {
DBG.println("[WARN] collect failed — BME690 read returned false");
}