feat: usb connection retries

This commit is contained in:
bullshit committed 2025-08-06 22:58:43 +02:00
1 parent 2740068bf0
commit e1a048d647
2 files changed
+14 -1

No files matched your search

+13 -1
View File
@@ -74,12 +74,24 @@ void NutUpsComponent::update() {
if (read_ups_data()) {
last_successful_read_ = millis();
consecutive_failures_ = 0;
update_sensors();
} else {
ESP_LOGW(TAG, "Failed to read UPS data");
consecutive_failures_++;
ESP_LOGW(TAG, "Failed to read UPS data (failure #%u)", consecutive_failures_.load());
// Implement exponential backoff for retries
if (consecutive_failures_ >= 3) {
ESP_LOGE(TAG, "Multiple consecutive failures, attempting protocol re-detection");
if (!detect_ups_protocol()) {
ESP_LOGE(TAG, "Protocol re-detection failed");
}
}
if (millis() - last_successful_read_ > protocol_timeout_ms_) {
ESP_LOGE(TAG, "UPS communication timeout, marking as disconnected");
connected_ = false;
consecutive_failures_ = 0;
}
}
}