From a869f4167220d84224ed44a1a07ea2b6ed781c4d Mon Sep 17 00:00:00 2001 From: ElVit Date: Sun, 16 Feb 2025 11:38:15 +0100 Subject: [PATCH] improved log_uart_hex --- components/panasonic_heatpump/README.md | 4 +++ .../panasonic_heatpump/panasonic_heatpump.cpp | 36 ++++++++++++++----- .../panasonic_heatpump/panasonic_heatpump.h | 12 +++++-- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/components/panasonic_heatpump/README.md b/components/panasonic_heatpump/README.md index 2895639..4084656 100644 --- a/components/panasonic_heatpump/README.md +++ b/components/panasonic_heatpump/README.md @@ -546,6 +546,10 @@ select: name: "Set Bivalent Mode" ``` +## Known Issues + +When the ESP controller is connected initially to the heatpump, the heatpump may not respond to any request messages. If the CZ-TAW1 is also connected to the ESP controller you will probably see some requests like 31 05 10 01 ... These are initial request messages. If the heatpump is not responding, it may help to turn off and on the power of the heatpump (switching the heatpump off is not enough). After a power on the heatpump should respond to the requests. + ## Sources :heart: A big THANKS to [Egyras](https://github.com/Egyras) and the work done on the repository [HeishaMon](https://github.com/Egyras/HeishaMon) for decoding the panasonic uart protocol and providing information to build hardware based on an ESP Chip. diff --git a/components/panasonic_heatpump/panasonic_heatpump.cpp b/components/panasonic_heatpump/panasonic_heatpump.cpp index 712efcd..138f211 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.cpp +++ b/components/panasonic_heatpump/panasonic_heatpump.cpp @@ -78,7 +78,7 @@ namespace esphome // Check if message is complete if (this->response_message_.size() > 2 && this->response_message_.size() == this->response_payload_length_ + 3) { - this->log_uart_hex("<<<", this->response_message_, ','); + this->log_uart_hex(UART_LOG_RX, this->response_message_, ','); this->decode_response(this->response_message_); this->response_message_.clear(); this->response_receiving_ = false; @@ -92,7 +92,7 @@ namespace esphome if (this->next_request_ == 2) // command { - this->log_uart_hex(">>>", this->command_message_, ','); + this->log_uart_hex(UART_LOG_RX, this->command_message_, ','); this->write_array(this->command_message_); this->flush(); return; @@ -103,13 +103,13 @@ namespace esphome if (this->next_request_ == 0) // initial { // Probably not necessary but CZ-TAW1 sends this query on boot - this->log_uart_hex(">>>", PanasonicCommand::InitialMessage, REQUEST_INIT_MSG_SIZE, ','); + this->log_uart_hex(UART_LOG_RX, PanasonicCommand::InitialMessage, REQUEST_INIT_MSG_SIZE, ','); this->write_array(PanasonicCommand::InitialMessage, REQUEST_INIT_MSG_SIZE); this->flush(); } else if (this->next_request_ == 1) // polling { - this->log_uart_hex(">>>", PanasonicCommand::PollingMessage, REQUEST_DATA_MSG_SIZE, ','); + this->log_uart_hex(UART_LOG_RX, PanasonicCommand::PollingMessage, REQUEST_DATA_MSG_SIZE, ','); this->write_array(PanasonicCommand::PollingMessage, REQUEST_DATA_MSG_SIZE); this->flush(); } @@ -155,20 +155,40 @@ namespace esphome // Check if message is complete if (this->request_message_.size() > 2 && this->request_message_.size() == this->request_payload_length_ + 3) { - this->log_uart_hex(">>>", this->request_message_, ','); + this->log_uart_hex(UART_LOG_TX, this->request_message_, ','); this->request_message_.clear(); this->request_receiving_ = false; } } } - void PanasonicHeatpumpComponent::log_uart_hex(std::string prefix, const uint8_t *data, size_t length, uint8_t separator) + void PanasonicHeatpumpComponent::log_uart_hex(UartLogDirection direction, const uint8_t *data, size_t length, uint8_t separator) { if (this->log_uart_msg_ == false) return; std::string logStr; + std::string msgDir = direction == UART_LOG_TX ? ">>>" : "<<<"; + std::string msgType = "response"; + if (direction == UART_LOG_TX) + { + switch(data[0]) + { + case 0x31: + msgType = "initial_request"; + break; + case 0x71: + msgType = "polling_request"; + break; + case 0xF1: + msgType = "command_request"; + break; + default: + msgType = "request"; + }; + } + logStr = "[" + std::to_string(length) + "]"; - ESP_LOGI(TAG, "%s %s", prefix.c_str(), logStr.c_str()); + ESP_LOGI(TAG, "%s %s%s", msgDir.c_str(), msgType.c_str(), logStr.c_str()); delay(10); logStr = ""; @@ -183,7 +203,7 @@ namespace esphome size_t chunkSize = 90; for (size_t i = 0; i < logStr.length(); i += chunkSize) { - ESP_LOGI(TAG, "%s %s", prefix.c_str(), logStr.substr(i, chunkSize).c_str()); + ESP_LOGD(TAG, "%s %s", msgDir.c_str(), logStr.substr(i, chunkSize).c_str()); delay(10); } } diff --git a/components/panasonic_heatpump/panasonic_heatpump.h b/components/panasonic_heatpump/panasonic_heatpump.h index d7f1d3b..e72fccb 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.h +++ b/components/panasonic_heatpump/panasonic_heatpump.h @@ -32,6 +32,12 @@ namespace esphome { namespace panasonic_heatpump { + enum UartLogDirection + { + UART_LOG_RX, + UART_LOG_TX, + }; + class PanasonicHeatpumpComponent : public PollingComponent, public uart::UARTDevice { public: @@ -284,11 +290,11 @@ namespace esphome void publish_number(std::vector bytes); void publish_select(std::vector bytes); void publish_switch(std::vector bytes); - void log_uart_hex(std::string prefix, const std::vector &data, uint8_t separator) + void log_uart_hex(UartLogDirection direction, const std::vector &data, uint8_t separator) { - this->log_uart_hex(prefix, &data[0], data.size(), separator); + this->log_uart_hex(direction, &data[0], data.size(), separator); } - void log_uart_hex(std::string prefix, const uint8_t *data, size_t length, uint8_t separator); + void log_uart_hex(UartLogDirection direction, const uint8_t *data, size_t length, uint8_t separator); }; } // namespace panasonic_heatpump } // namespace esphome