From 76b276516a9115f153fda36df8f95c1f0b0430fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Koek?= Date: Tue, 26 Mar 2024 17:47:05 +0000 Subject: [PATCH] Update lora.cpp --- esphome/components/lora/lora.cpp | 36 +++++++++++++------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/esphome/components/lora/lora.cpp b/esphome/components/lora/lora.cpp index 096d8a0131..23a1b3f827 100644 --- a/esphome/components/lora/lora.cpp +++ b/esphome/components/lora/lora.cpp @@ -148,39 +148,31 @@ void Lora::send_pin_info_(uint8_t pin, bool value) { void Lora::loop() { std::string buffer; std::vector data; - bool pin_data_found = false; if (!this->available()) return; ESP_LOGD(TAG, "Reading serial"); while (this->available()) { uint8_t c; - if (this->read_byte(&c)) { - buffer += (char) c; - // indicates that there is pin data, lets capture that - data.push_back(c); - } + this->read_byte(&c); + data.push_back(c); } - this->update_needed_ = true; - - if (!data.empty()) { - auto it = data.begin(); - ESP_LOGD(TAG, "PIN: %u ", data[0]); + if (data.size() >= 4) { + ESP_LOGD(TAG, "start bit: %u ", data[0]); ESP_LOGD(TAG, "PIN: %u ", data[1]); ESP_LOGD(TAG, "VALUE: %u ", data[2]); ESP_LOGD(TAG, "RSSI: %u ", data[3]); - pin_data_found = true; - } else { - ESP_LOGD(TAG, "Got %s", buffer.c_str()); - } - char *ptr; - // set the rssi - rssi_ = strtol(buffer.substr(buffer.length() - 1, 1).c_str(), &ptr, 2); - ESP_LOGD(TAG, "RSSI: %u ", rssi_); - // set the raw message - if (!pin_data_found) { - raw_message_ = buffer.substr(0, buffer.length() - 1); + ESP_LOGD(TAG, "WEIRD "); } + + // char *ptr; + // // set the rssi + // rssi_ = strtol(buffer.substr(buffer.length() - 1, 1).c_str(), &ptr, 2); + // ESP_LOGD(TAG, "RSSI: %u ", rssi_); + // // set the raw message + // if (!pin_data_found) { + // raw_message_ = buffer.substr(0, buffer.length() - 1); + // } } } // namespace lora } // namespace esphome