diff --git a/sonoff/xsns_07_sht1x.ino b/sonoff/xsns_07_sht1x.ino index 40a76e7a8..2c0099c9b 100644 --- a/sonoff/xsns_07_sht1x.ino +++ b/sonoff/xsns_07_sht1x.ino @@ -175,13 +175,14 @@ void ShtEverySecond() if (sht_type && !(uptime %3)) { // Update every 3 seconds if (!ShtRead()) { AddLogMissed(sht_types, sht_valid); +// if (!sht_valid) { sht_type = 0; } } } } void ShtShow(boolean json) { - if (sht_type && sht_valid) { + if (sht_valid) { char temperature[10]; char humidity[10]; diff --git a/sonoff/xsns_08_htu21.ino b/sonoff/xsns_08_htu21.ino index ecb127dc6..0f3cfc735 100644 --- a/sonoff/xsns_08_htu21.ino +++ b/sonoff/xsns_08_htu21.ino @@ -234,6 +234,7 @@ void HtuEverySecond() if (htu_type) { if (!HtuRead()) { AddLogMissed(htu_types, htu_valid); +// if (!htu_valid) { htu_type = 0; } } } } @@ -241,7 +242,7 @@ void HtuEverySecond() void HtuShow(boolean json) { - if (htu_type && htu_valid) { + if (htu_valid) { char temperature[10]; char humidity[10]; diff --git a/sonoff/xsns_10_bh1750.ino b/sonoff/xsns_10_bh1750.ino index 9c02f02e0..aa2cee37d 100644 --- a/sonoff/xsns_10_bh1750.ino +++ b/sonoff/xsns_10_bh1750.ino @@ -33,14 +33,20 @@ uint8_t bh1750_address; uint8_t bh1750_addresses[] = { BH1750_ADDR1, BH1750_ADDR2 }; uint8_t bh1750_type = 0; +uint8_t bh1750_valid = 0; +uint16_t bh1750_illuminance = 0; +char bh1750_types[] = "BH1750"; -uint16_t Bh1750ReadLux() +bool Bh1750Read() { - Wire.requestFrom(bh1750_address, (uint8_t)2); + if (bh1750_valid) { bh1750_valid--; } + + if (2 != Wire.requestFrom(bh1750_address, (uint8_t)2)) { return false; } byte msb = Wire.read(); byte lsb = Wire.read(); - uint16_t value = ((msb << 8) | lsb) / 1.2; - return value; + bh1750_illuminance = ((msb << 8) | lsb) / 1.2; + bh1750_valid = SENSOR_MAX_MISS; + return true; } /********************************************************************************************/ @@ -57,31 +63,46 @@ void Bh1750Detect() Wire.write(BH1750_CONTINUOUS_HIGH_RES_MODE); if (!Wire.endTransmission()) { bh1750_type = 1; - snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "BH1750", bh1750_address); + snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, bh1750_types, bh1750_address); AddLog(LOG_LEVEL_DEBUG); break; } } } +void Bh1750EverySecond() +{ + if (90 == (uptime %100)) { + Bh1750Detect(); + } + else if (uptime &1) { + if (bh1750_type) { + if (!Bh1750Read()) { + AddLogMissed(bh1750_types, bh1750_valid); +// if (!bh1750_valid) { bh1750_type = 0; } + } + } + } +} + #ifdef USE_WEBSERVER const char HTTP_SNS_ILLUMINANCE[] PROGMEM = - "%s{s}BH1750 " D_ILLUMINANCE "{m}%d " D_UNIT_LUX "{e}"; // {s} =