Add timeout while waiting for answer
This commit is contained in:
parent
189fd539f1
commit
f72e0ea591
|
@ -9,6 +9,7 @@ namespace esphome {
|
||||||
namespace tw7100 {
|
namespace tw7100 {
|
||||||
|
|
||||||
bool waiting_for_answer = false;
|
bool waiting_for_answer = false;
|
||||||
|
unsigned long waiting_for_answer_since = 0;
|
||||||
std::deque<std::string> cmd_queue;
|
std::deque<std::string> cmd_queue;
|
||||||
unsigned long last_set_cmd_timestamp;
|
unsigned long last_set_cmd_timestamp;
|
||||||
|
|
||||||
|
@ -138,10 +139,15 @@ void tw7100Component::loop() {
|
||||||
flush();
|
flush();
|
||||||
if (cmd.find("?") != std::string::npos) { // only wait for response on CMD? requests
|
if (cmd.find("?") != std::string::npos) { // only wait for response on CMD? requests
|
||||||
waiting_for_answer = true;
|
waiting_for_answer = true;
|
||||||
|
waiting_for_answer_since = millis();
|
||||||
} else {
|
} else {
|
||||||
last_set_cmd_timestamp = millis();
|
last_set_cmd_timestamp = millis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (waiting_for_answer && (millis() - waiting_for_answer_since > 1000)) {
|
||||||
|
ESP_LOGE(TAG, "no response for last request since 1000ms, timing out!");
|
||||||
|
waiting_for_answer = false;
|
||||||
|
}
|
||||||
} else { // response found, handle eventual errors
|
} else { // response found, handle eventual errors
|
||||||
ESP_LOGV(TAG, "buffer content: %s", response.c_str());
|
ESP_LOGV(TAG, "buffer content: %s", response.c_str());
|
||||||
std::pair<std::string, std::string> parsed_response = parse_response(response);
|
std::pair<std::string, std::string> parsed_response = parse_response(response);
|
||||||
|
|
Loading…
Reference in a new issue