fix bridge and i2c logging

This commit is contained in:
grove5_admin committed 2026-04-30 14:22:43 -07:00
1 parent 6fcc4a0d80
commit a5fad9573a
3 files changed
+55 -14

No files matched your search

+45 -6
View File
@@ -31,18 +31,55 @@ static unsigned long lastCollect = 0;
void setup() {
Bridge.begin();
delay(500); // let arduino-router finish boot chatter before we print
Monitor.println("[cultivar] ENV bridge starting...");
server.begin();
Monitor.println("[cultivar] TCP server ready on :5678");
Wire1.begin(); // explicit begin before setClock
Wire1.setClock(100000); // 100 kHz — safer than default 400 kHz on longer runs
if (!env.begin(Wire1, SDA, SCL)) {
Monitor.println("[WARN] BME690 init failed — check wiring/address/I2C bus");
Wire1.begin();
Wire1.setClock(100000);
// I2C scan via Monitor (visible on Linux side) before sensor init
Monitor.println("\n[cultivar] I2C scan on Wire1:");
int i2c_found = 0;
for (uint8_t addr = 1; addr < 127; addr++) {
Wire1.beginTransmission(addr);
if (Wire1.endTransmission() == 0) {
Monitor.print(" 0x");
if (addr < 0x10) Monitor.print("0");
Monitor.print(addr, HEX);
if (addr == 0x76 || addr == 0x77) Monitor.print(" <- BME690");
if (addr == 0x62) Monitor.print(" <- SCD43");
if (addr == 0x6B) Monitor.print(" <- IMU");
Monitor.println();
i2c_found++;
}
}
if (!i2c_found) Monitor.println(" No devices found — check wiring");
Monitor.println("[cultivar] I2C scan done");
// Raw chip ID probe — BME690 register 0xD0 should return 0x61
Wire1.beginTransmission(0x76);
Wire1.write(0xD0);
Wire1.endTransmission(true);
Wire1.requestFrom((uint8_t)0x76, (uint8_t)1);
if (Wire1.available()) {
uint8_t chip_id = Wire1.read();
Monitor.print("[cultivar] BME690 chip_id=0x");
Monitor.print(chip_id, HEX);
Monitor.println(chip_id == 0x61 ? " (OK)" : " (WRONG — expected 0x61)");
} else {
Monitor.println("[cultivar] BME690 chip_id read failed — no data");
}
env.scanI2C();
if (!env.begin(Wire1, SDA, SCL)) {
Monitor.print("[WARN] BME690 init failed — bme_status=");
Monitor.println(env.bme_status);
}
// env.begin() calls Wire1.begin() internally on Zephyr, resetting the clock.
// Re-apply 100 kHz so all sensor reads use the safe rate.
Wire1.setClock(100000);
Monitor.print("[cultivar] BME690=");
Monitor.print(env.bme_ok ? "OK" : "FAIL");
@@ -82,6 +119,7 @@ void loop() {
if (env.collect(payload)) {
env.toJSON(payload, jsonBuf, sizeof(jsonBuf));
client.println(jsonBuf);
Monitor.print(jsonBuf);
Monitor.print("[cultivar] payload sent — ");
Monitor.print("T="); Monitor.print(payload.ambient.temperature, 1);
Monitor.print("C RH="); Monitor.print(payload.ambient.humidity, 1);
@@ -94,5 +132,6 @@ void loop() {
delay(100);
}
Monitor.println("[cultivar] daemon disconnected — will re-accept");
Monitor.println("[cultivar] daemon disconnected — restarting server");
server.begin();
}