Skip to content

Commit 0a38762

Browse files
committed
fix: checkAndAutoHealSensors skips non-DS18B20 types + BME280 boot timeout
- AppManager_Sensors.cpp: 1-Wire ROM check now skips DHT22/BME280 sensors, preventing false 'Sensor missing' warnings every 60s for non-1-Wire types. - BME280Driver.h: added I2C timeout (50ms) and ACK probe before chip reset. Prevents boot hang when BME280 is configured but not physically present. begin() returns gracefully with _compLoaded=false if no device ACKs.
1 parent 89080f5 commit 0a38762

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

src/AppManager_Sensors.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ void AppManager::checkAndAutoHealSensors( ) {
2323
for (uint8_t gpio = 0; gpio < MAX_SENSORS; gpio++) {
2424
if (!cfg.sensors[gpio].active) continue;
2525

26+
/* 1-Wire ROM check only applies to DS18B20 sensors.
27+
* DHT22, BME280, and other types use their own driver-specific
28+
* error detection — don't flag them as missing here. */
29+
if (cfg.sensors[gpio].sensorType != TYPE_DS18B20) continue;
30+
2631
uint8_t foundRom[8];
2732
#if SIMUT_SENSOR_DS18B20
2833
if (_sensorMgr->identifyPhysicalSensor(gpio, foundRom)) {
@@ -34,7 +39,7 @@ void AppManager::checkAndAutoHealSensors( ) {
3439
_sensorMgr->setHardwareMismatch(gpio, false);
3540
}
3641
} else {
37-
/* Sensor configured but not found on the physical bus */
42+
/* DS18B20 configured but not found on the 1-Wire bus */
3843
static uint32_t lastMissingLog[MAX_SENSORS] = {0};
3944
if (timeSince(lastMissingLog[gpio], 60000)) {
4045
lastMissingLog[gpio] = millis( );

src/sensors/BME280Driver.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,32 @@ struct BME280Driver {
9999

100100
/* ── Initialization ───────────────────────────────────────────────── */
101101
void begin( ) {
102-
/* Soft-reset the sensor */
103-
writeReg(BME280_I2C_ADDR_PRIMARY, BME280_REG_RESET, BME280_RESET_CMD);
102+
/* Set short I2C timeout — prevents boot hang if BME280 absent */
103+
_wire->setTimeout(50); /* 50ms per operation */
104+
105+
/* Quick probe: does ANY device ACK at primary or secondary address? */
106+
_wire->beginTransmission(BME280_I2C_ADDR_PRIMARY);
107+
bool primaryAck = (_wire->endTransmission() == 0);
108+
_wire->beginTransmission(BME280_I2C_ADDR_SECONDARY);
109+
bool secondaryAck = (_wire->endTransmission() == 0);
110+
111+
if (!primaryAck && !secondaryAck) {
112+
_compLoaded = false;
113+
return; /* No BME280 on bus — silent, safe */
114+
}
115+
116+
/* Soft-reset the sensor at the responding address */
117+
uint8_t addr = primaryAck ? BME280_I2C_ADDR_PRIMARY : BME280_I2C_ADDR_SECONDARY;
118+
writeReg(addr, BME280_REG_RESET, BME280_RESET_CMD);
104119
delay(10);
105-
/* Try primary address; fall back to secondary */
120+
121+
/* Verify chip ID */
106122
uint8_t chipId = 0;
107-
if (!readRegs(BME280_I2C_ADDR_PRIMARY, BME280_REG_CHIP_ID, &chipId, 1)
123+
if (!readRegs(addr, BME280_REG_CHIP_ID, &chipId, 1)
108124
|| chipId != BME280_CHIP_ID) {
109-
if (!readRegs(BME280_I2C_ADDR_SECONDARY, BME280_REG_CHIP_ID, &chipId, 1)
125+
/* Try the other address */
126+
uint8_t altAddr = primaryAck ? BME280_I2C_ADDR_SECONDARY : BME280_I2C_ADDR_PRIMARY;
127+
if (!readRegs(altAddr, BME280_REG_CHIP_ID, &chipId, 1)
110128
|| chipId != BME280_CHIP_ID) {
111129
_compLoaded = false;
112130
return;

0 commit comments

Comments
 (0)