Skip to content

Commit

Permalink
Stab at checking for OpenTherm Lite (OT/-) in response to #19
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeBear-nc committed Nov 30, 2024
1 parent 0a6b838 commit e9f83af
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
34 changes: 34 additions & 0 deletions components/opentherm/hub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ void OpenthermHub::setup() {
this->mark_failed();
return;
}
if (this->check_for_lite()) {
ESP_LOGE(TAG, "Failed to initialize OpenTherm hub. See previous log "
"messages for details.");
this->mark_failed();
return;
}

// Ensure that there is at least one request, as we are required to
// communicate at least once every second. Sending the status request is
Expand Down Expand Up @@ -293,6 +299,34 @@ void OpenthermHub::sync_loop_() {
this->read_response_();
}

bool OpenthermHub::check_for_lite(void) {
int32_t timeout = this->opentherm_->get_timeout();
auto request = this->build_request_(MessageId::STATUS);
ESP_LOGD(TAG, "Sending request with id %d (%s)", request.id,
this->opentherm_->message_id_to_str((MessageId)request.id));
this->opentherm_->debug_data(request);

this->opentherm_->set_timeout(5000);
// Send the request
this->last_conversation_start_ = millis();
this->opentherm_->send(request);

this->opentherm_->listen();
auto now = millis();

this->opentherm_->set_timeout(timeout);

if (this->opentherm_->is_timeout()) {
this->handle_timeout_error_();
ESP_LOGE(TAG, "Possible OpenTherm-Lite detected");
ESP_LOGE(TAG, "Device failed to respond within %s seconds",
(now - this->last_conversation_start_) / 1000);
return true;
// Should a protocol error also flag OT/- ?
}
return false;
}

bool OpenthermHub::check_timings_(uint32_t cur_time) {
if (this->last_conversation_start_ > 0 && (cur_time - this->last_conversation_start_) > 1150) {
ESP_LOGW(TAG,
Expand Down
1 change: 1 addition & 0 deletions components/opentherm/hub.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class OpenthermHub : public Component {
void stop_opentherm_();
void start_conversation_();
void read_response_();
bool check_for_lite();
bool check_timings_(uint32_t cur_time);
bool should_skip_loop_(uint32_t cur_time) const;
void sync_loop_();
Expand Down
3 changes: 3 additions & 0 deletions components/opentherm/opentherm.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ class OpenTherm {
static void esp8266_timer_isr();
#endif

void set_timeout(int32_t value) { this->device_timeout_ = value; }
int32_t get_timeout(void) { return this->device_timeout_; }

private:
InternalGPIOPin *in_pin_;
InternalGPIOPin *out_pin_;
Expand Down

0 comments on commit e9f83af

Please sign in to comment.