dallas: bus not idle error handling

This commit is contained in:
MichaelDvP
2021-01-29 11:27:56 +01:00
parent ddfb7b76bb
commit 61c67be510
2 changed files with 20 additions and 6 deletions

View File

@@ -70,9 +70,19 @@ void DallasSensor::loop() {
bus_.skip(); bus_.skip();
bus_.write(CMD_CONVERT_TEMP, parasite_ ? 1 : 0); bus_.write(CMD_CONVERT_TEMP, parasite_ ? 1 : 0);
state_ = State::READING; state_ = State::READING;
scanretry_ = 0;
} else { } else {
// no sensors found // no sensors found
// LOG_ERROR(F("Bus reset failed")); // uncomment for debug if (sensors_.size()) {
sensorfails_++;
if (++scanretry_ > SCAN_MAX) { // every 30 sec
scanretry_ = 0;
LOG_ERROR(F("Bus reset failed"));
for (auto & sensor : sensors_) {
sensor.temperature_c = EMS_VALUE_SHORT_NOTSET;
}
}
}
} }
last_activity_ = time_now; last_activity_ = time_now;
} }
@@ -142,7 +152,7 @@ void DallasSensor::loop() {
bus_.depower(); bus_.depower();
} }
// check for missing sensors after some samples // check for missing sensors after some samples
if (++scancnt_ > 5) { if (++scancnt_ > SCAN_MAX) {
for (auto & sensor : sensors_) { for (auto & sensor : sensors_) {
if (!sensor.read) { if (!sensor.read) {
sensor.temperature_c = EMS_VALUE_SHORT_NOTSET; sensor.temperature_c = EMS_VALUE_SHORT_NOTSET;
@@ -151,11 +161,11 @@ void DallasSensor::loop() {
sensor.read = false; sensor.read = false;
} }
scancnt_ = 0; scancnt_ = 0;
} else if (scancnt_ == -2) { // startup } else if (scancnt_ == SCAN_START + 1) { // startup
firstscan_ = sensors_.size(); firstscan_ = sensors_.size();
LOG_DEBUG(F("Adding %d dallassensor(s) from first scan"), firstscan_); LOG_DEBUG(F("Adding %d dallassensor(s) from first scan"), firstscan_);
} else if ((scancnt_ <= 0) && (firstscan_ != sensors_.size())) { // check 2 times for no change of sensor # } else if ((scancnt_ <= 0) && (firstscan_ != sensors_.size())) { // check 2 times for no change of sensor #
scancnt_ = -3; scancnt_ = SCAN_START;
sensors_.clear(); // restart scaning and clear to get correct numbering sensors_.clear(); // restart scaning and clear to get correct numbering
} }
state_ = State::IDLE; state_ = State::IDLE;

View File

@@ -95,6 +95,9 @@ class DallasSensor {
static constexpr uint8_t CMD_CONVERT_TEMP = 0x44; static constexpr uint8_t CMD_CONVERT_TEMP = 0x44;
static constexpr uint8_t CMD_READ_SCRATCHPAD = 0xBE; static constexpr uint8_t CMD_READ_SCRATCHPAD = 0xBE;
static constexpr int8_t SCAN_START = -3;
static constexpr int8_t SCAN_MAX = 5;
static uuid::log::Logger logger_; static uuid::log::Logger logger_;
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
@@ -114,12 +117,13 @@ class DallasSensor {
bool registered_ha_[MAX_SENSORS]; bool registered_ha_[MAX_SENSORS];
int8_t scancnt_ = -3; int8_t scancnt_ = SCAN_START;
uint8_t firstscan_ = 0; uint8_t firstscan_ = 0;
uint8_t dallas_gpio_ = 0; uint8_t dallas_gpio_ = 0;
bool parasite_ = false; bool parasite_ = false;
bool changed_ = false; bool changed_ = false;
uint32_t sensorfails_ = 0; uint32_t sensorfails_ = 0;
int8_t scanretry_ = 0;
}; };
} // namespace emsesp } // namespace emsesp