From 822100ae1645360c001dbd19bd05dd182bda4ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Koek?= Date: Tue, 26 Mar 2024 17:34:12 +0000 Subject: [PATCH] add more logic! exiting --- esphome/components/lora/lora.cpp | 12 ++++++++---- esphome/components/lora/lora.h | 3 +-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/esphome/components/lora/lora.cpp b/esphome/components/lora/lora.cpp index 2bf593f608..d8046ab1c2 100644 --- a/esphome/components/lora/lora.cpp +++ b/esphome/components/lora/lora.cpp @@ -5,7 +5,6 @@ namespace lora { void Lora::update() { can_send_message_(); get_mode_(); - check_for_message_(); if (!this->update_needed_) return; if (this->rssi_sensor_ != nullptr) @@ -147,7 +146,7 @@ void Lora::send_pin_info_(uint8_t pin, bool value) { this->setup_wait_response_(5000); ESP_LOGD(TAG, "Successfully put in queue"); } -void Lora::check_for_message_() { +void Lora::loop() { std::string buffer; std::vector data; bool pin_data_found = false; @@ -160,6 +159,7 @@ void Lora::check_for_message_() { buffer += (char) c; // indicates that there is pin data, lets capture that if (c == 0xA5) { + ESP_LOGD(TAG, "Found pin data!"); pin_data_found = true; } if (pin_data_found) @@ -167,18 +167,22 @@ void Lora::check_for_message_() { } } this->update_needed_ = true; - ESP_LOGD(TAG, "Got %s", buffer.c_str()); + if (!data.empty()) { ESP_LOGD(TAG, "Found pin data!"); ESP_LOGD(TAG, "PIN: %u ", data[1]); ESP_LOGD(TAG, "VALUE: %u ", data[2]); + } 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 - raw_message_ = buffer.substr(0, buffer.length() - 1); + if (!pin_data_found) { + raw_message_ = buffer.substr(0, buffer.length() - 1); + } } } // namespace lora } // namespace esphome diff --git a/esphome/components/lora/lora.h b/esphome/components/lora/lora.h index 6dd580a9e5..0fb0a8b1e8 100644 --- a/esphome/components/lora/lora.h +++ b/esphome/components/lora/lora.h @@ -31,7 +31,7 @@ class Lora : public PollingComponent, public uart::UARTDevice { void setup() override; float get_setup_priority() const override { return setup_priority::HARDWARE; } void update() override; - + void loop() override; void dump_config() override; /// Helper function to write the value of a pin. void digital_write(uint8_t pin, bool value); @@ -45,7 +45,6 @@ class Lora : public PollingComponent, public uart::UARTDevice { ModeType mode_ = MODE_INIT; // set WOR mode void set_mode_(ModeType mode); - void check_for_message_(); ModeType get_mode_(); // checks the aux port to see if it is done setting void setup_wait_response_(uint32_t timeout = 1000);