fix bridge and i2c logging
This commit is contained in:
1 parent
6fcc4a0d80
commit
a5fad9573a
3 files changed
+55
-14
No files matched your search
Binary file not shown.
@@ -50,6 +50,7 @@ bool CultivarEnv::begin(TwoWire &wire, uint8_t sda, uint8_t scl, uint8_t bme_add
|
|||||||
#else
|
#else
|
||||||
_wire->begin(_sda, _scl);
|
_wire->begin(_sda, _scl);
|
||||||
#endif
|
#endif
|
||||||
|
_wire->setClock(100000); // 100 kHz — begin() resets clock; re-apply before init
|
||||||
|
|
||||||
bme_ok = _initBME690();
|
bme_ok = _initBME690();
|
||||||
scd4x_ok = _initSCD4x();
|
scd4x_ok = _initSCD4x();
|
||||||
@@ -113,6 +114,7 @@ bool CultivarEnv::_forcedRead(struct bme69x_data &data) {
|
|||||||
// ── _readAmbient ──────────────────────────────────────────────────────────
|
// ── _readAmbient ──────────────────────────────────────────────────────────
|
||||||
bool CultivarEnv::_readAmbient(CultivarAmbient &out) {
|
bool CultivarEnv::_readAmbient(CultivarAmbient &out) {
|
||||||
out.valid = false;
|
out.valid = false;
|
||||||
|
if (!bme_ok) return false;
|
||||||
|
|
||||||
_conf.os_temp = BME69X_OS_8X;
|
_conf.os_temp = BME69X_OS_8X;
|
||||||
_conf.os_pres = BME69X_OS_16X;
|
_conf.os_pres = BME69X_OS_16X;
|
||||||
@@ -372,21 +374,21 @@ void CultivarEnv::printPayload(const CultivarEnvPayload &p) {
|
|||||||
|
|
||||||
// ── scanI2C ───────────────────────────────────────────────────────────────
|
// ── scanI2C ───────────────────────────────────────────────────────────────
|
||||||
void CultivarEnv::scanI2C() {
|
void CultivarEnv::scanI2C() {
|
||||||
Serial.println("\n── I2C Bus Scan ──────────────────────");
|
CULTIVAR_SERIAL_PRINTF("\n── I2C Bus Scan ──────────────────────\n");
|
||||||
int found = 0;
|
int found = 0;
|
||||||
for (uint8_t addr = 1; addr < 127; addr++) {
|
for (uint8_t addr = 1; addr < 127; addr++) {
|
||||||
_wire->beginTransmission(addr);
|
_wire->beginTransmission(addr);
|
||||||
if (_wire->endTransmission() == 0) {
|
if (_wire->endTransmission() == 0) {
|
||||||
CULTIVAR_SERIAL_PRINTF(" 0x%02X", addr);
|
CULTIVAR_SERIAL_PRINTF(" 0x%02X", addr);
|
||||||
if (addr == 0x62) Serial.print(" ← SCD43");
|
if (addr == 0x62) CULTIVAR_SERIAL_PRINTF(" <- SCD43");
|
||||||
if (addr == 0x76 || addr == 0x77) Serial.print(" ← BME690");
|
if (addr == 0x76 || addr == 0x77) CULTIVAR_SERIAL_PRINTF(" <- BME690");
|
||||||
if (addr == 0x6B) Serial.print(" ← QMI8658C IMU");
|
if (addr == 0x6B) CULTIVAR_SERIAL_PRINTF(" <- QMI8658C IMU");
|
||||||
Serial.println();
|
CULTIVAR_SERIAL_PRINTF("\n");
|
||||||
found++;
|
found++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) Serial.println(" No devices found");
|
if (!found) CULTIVAR_SERIAL_PRINTF(" No devices found\n");
|
||||||
Serial.println("─────────────────────────────────────");
|
CULTIVAR_SERIAL_PRINTF("─────────────────────────────────────\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Bosch API I2C callbacks ───────────────────────────────────────────────
|
// ── Bosch API I2C callbacks ───────────────────────────────────────────────
|
||||||
@@ -395,7 +397,7 @@ int8_t CultivarEnv::_i2cRead(uint8_t reg_addr, uint8_t *data,
|
|||||||
CultivarI2CHandle *h = (CultivarI2CHandle *)intf_ptr;
|
CultivarI2CHandle *h = (CultivarI2CHandle *)intf_ptr;
|
||||||
h->wire->beginTransmission(h->addr);
|
h->wire->beginTransmission(h->addr);
|
||||||
h->wire->write(reg_addr);
|
h->wire->write(reg_addr);
|
||||||
if (h->wire->endTransmission(false) != 0) return -1;
|
if (h->wire->endTransmission(true) != 0) return -1; // true=STOP; Zephyr Wire may not support repeated starts
|
||||||
h->wire->requestFrom(h->addr, (uint8_t)len);
|
h->wire->requestFrom(h->addr, (uint8_t)len);
|
||||||
for (uint32_t i = 0; i < len; i++) {
|
for (uint32_t i = 0; i < len; i++) {
|
||||||
if (!h->wire->available()) return -1;
|
if (!h->wire->available()) return -1;
|
||||||
|
|||||||
@@ -31,18 +31,55 @@ static unsigned long lastCollect = 0;
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
|
delay(500); // let arduino-router finish boot chatter before we print
|
||||||
Monitor.println("[cultivar] ENV bridge starting...");
|
Monitor.println("[cultivar] ENV bridge starting...");
|
||||||
|
|
||||||
server.begin();
|
server.begin();
|
||||||
Monitor.println("[cultivar] TCP server ready on :5678");
|
Monitor.println("[cultivar] TCP server ready on :5678");
|
||||||
|
|
||||||
Wire1.begin(); // explicit begin before setClock
|
Wire1.begin();
|
||||||
Wire1.setClock(100000); // 100 kHz — safer than default 400 kHz on longer runs
|
Wire1.setClock(100000);
|
||||||
if (!env.begin(Wire1, SDA, SCL)) {
|
|
||||||
Monitor.println("[WARN] BME690 init failed — check wiring/address/I2C bus");
|
// 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("[cultivar] BME690=");
|
||||||
Monitor.print(env.bme_ok ? "OK" : "FAIL");
|
Monitor.print(env.bme_ok ? "OK" : "FAIL");
|
||||||
@@ -82,6 +119,7 @@ void loop() {
|
|||||||
if (env.collect(payload)) {
|
if (env.collect(payload)) {
|
||||||
env.toJSON(payload, jsonBuf, sizeof(jsonBuf));
|
env.toJSON(payload, jsonBuf, sizeof(jsonBuf));
|
||||||
client.println(jsonBuf);
|
client.println(jsonBuf);
|
||||||
|
Monitor.print(jsonBuf);
|
||||||
Monitor.print("[cultivar] payload sent — ");
|
Monitor.print("[cultivar] payload sent — ");
|
||||||
Monitor.print("T="); Monitor.print(payload.ambient.temperature, 1);
|
Monitor.print("T="); Monitor.print(payload.ambient.temperature, 1);
|
||||||
Monitor.print("C RH="); Monitor.print(payload.ambient.humidity, 1);
|
Monitor.print("C RH="); Monitor.print(payload.ambient.humidity, 1);
|
||||||
@@ -94,5 +132,6 @@ void loop() {
|
|||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
Monitor.println("[cultivar] daemon disconnected — will re-accept");
|
Monitor.println("[cultivar] daemon disconnected — restarting server");
|
||||||
|
server.begin();
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user