diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index 13aeab59e..90b48d1f8 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -10,6 +10,7 @@ - overlapping while reading sequence of EMS1.0 telegrams - redundant telegram readings (because of offset overflow) - added missing RC30/Moduline400 [#243](https://github.com/emsesp/EMS-ESP32/issues/243) +- check received status before toggling fetch on empty telegram [#268][#282] ## Changed diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index d2c3e0d47..60a3a2d87 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -461,7 +461,7 @@ void EMSdevice::show_mqtt_handlers(uuid::console::Shell & shell) { // register a callback function for a specific telegram type void EMSdevice::register_telegram_type(const uint16_t telegram_type_id, const __FlashStringHelper * telegram_type_name, bool fetch, const process_function_p f) { - telegram_functions_.emplace_back(telegram_type_id, telegram_type_name, fetch, f); + telegram_functions_.emplace_back(telegram_type_id, telegram_type_name, fetch, false, f); } // add to device value library, also know now as a "device entity" @@ -1156,17 +1156,18 @@ const std::string EMSdevice::telegram_type_name(std::shared_ptr // take a telegram_type_id and call the matching handler // return true if match found bool EMSdevice::handle_telegram(std::shared_ptr telegram) { - for (const auto & tf : telegram_functions_) { + for (auto & tf : telegram_functions_) { if (tf.telegram_type_id_ == telegram->type_id) { - // if the data block is empty, assume that this telegram is not recognized by the bus master - // so remove it from the automatic fetch list - if (telegram->message_length == 0 && telegram->offset == 0) { + // if the data block is empty and we have not received data before, assume that this telegram + // is not recognized by the bus master. So remove it from the automatic fetch list + if (telegram->message_length == 0 && telegram->offset == 0 && !tf.received_) { EMSESP::logger().debug(F("This telegram (%s) is not recognized by the EMS bus"), read_flash_string(tf.telegram_type_name_).c_str()); - toggle_fetch(tf.telegram_type_id_, false); + tf.fetch_ = false; return false; } if (telegram->message_length > 0) { + tf.received_ = true; tf.process_function_(telegram); } diff --git a/src/emsdevice.h b/src/emsdevice.h index cea919fb3..dd936ccb1 100644 --- a/src/emsdevice.h +++ b/src/emsdevice.h @@ -407,12 +407,14 @@ class EMSdevice { uint16_t telegram_type_id_; // it's type_id const __FlashStringHelper * telegram_type_name_; // e.g. RC20Message bool fetch_; // if this type_id be queried automatically + bool received_; process_function_p process_function_; - TelegramFunction(uint16_t telegram_type_id, const __FlashStringHelper * telegram_type_name, bool fetch, const process_function_p process_function) + TelegramFunction(uint16_t telegram_type_id, const __FlashStringHelper * telegram_type_name, bool fetch, bool received, const process_function_p process_function) : telegram_type_id_(telegram_type_id) , telegram_type_name_(telegram_type_name) , fetch_(fetch) + , received_(received) , process_function_(process_function) { } };