diff --git a/esphome/components/ebyte_lora/ebyte_lora.cpp b/esphome/components/ebyte_lora/ebyte_lora.cpp index 12b5148a3a..2c6f4101b6 100644 --- a/esphome/components/ebyte_lora/ebyte_lora.cpp +++ b/esphome/components/ebyte_lora/ebyte_lora.cpp @@ -4,6 +4,16 @@ namespace ebyte_lora { static const uint8_t SWITCH_PUSH = 0x55; static const uint8_t SWITCH_INFO = 0x66; static const uint8_t PROGRAM_CONF = 0xC1; +void EbyteLoraComponent::update() { + if (get_mode_() != NORMAL) { + if (this->config.command == 0) { + ESP_LOGD(TAG, "Config not set yet!"); + } + ESP_LOGD(TAG, "Mode was not set right"); + set_mode_(NORMAL); + } + send_switch_info_(); +} void EbyteLoraComponent::setup() { this->pin_aux_->setup(); this->pin_m0_->setup(); @@ -15,25 +25,24 @@ void EbyteLoraComponent::get_current_config_() { set_mode_(CONFIGURATION); uint8_t data[3] = {PROGRAM_CONF, 0x00, 0x08}; this->write_array(data, sizeof(data)); - RegisterConfig buffer; if (!this->available()) { return; } - if (read_array((uint8_t *) &buffer, sizeof(buffer))) { + if (read_array((uint8_t *) &this->config, sizeof(this->config))) { ESP_LOGD(TAG, "Found config"); - ESP_LOGD(TAG, buffer.addh_description_().c_str()); - ESP_LOGD(TAG, buffer.addl_description_().c_str()); - ESP_LOGD(TAG, buffer.reg_0.air_data_rate_description_().c_str()); - ESP_LOGD(TAG, buffer.reg_0.uart_baud_description_().c_str()); - ESP_LOGD(TAG, buffer.reg_0.parity_description_().c_str()); - ESP_LOGD(TAG, buffer.reg_1.rssi_noise_description_().c_str()); - ESP_LOGD(TAG, buffer.reg_1.sub_packet_description_().c_str()); - ESP_LOGD(TAG, buffer.reg_1.transmission_power_description_().c_str()); - ESP_LOGD(TAG, buffer.channel_description_().c_str()); - ESP_LOGD(TAG, buffer.reg_3.enable_lbt_description_().c_str()); - ESP_LOGD(TAG, buffer.reg_3.wor_period_description_().c_str()); - ESP_LOGD(TAG, buffer.reg_3.enable_rssi_description_().c_str()); - ESP_LOGD(TAG, buffer.reg_3.transmission_type_description_().c_str()); + ESP_LOGD(TAG, this->config.addh_description_().c_str()); + ESP_LOGD(TAG, this->config.addl_description_().c_str()); + ESP_LOGD(TAG, this->config.reg_0.air_data_rate_description_().c_str()); + ESP_LOGD(TAG, this->config.reg_0.uart_baud_description_().c_str()); + ESP_LOGD(TAG, this->config.reg_0.parity_description_().c_str()); + ESP_LOGD(TAG, this->config.reg_1.rssi_noise_description_().c_str()); + ESP_LOGD(TAG, this->config.reg_1.sub_packet_description_().c_str()); + ESP_LOGD(TAG, this->config.reg_1.transmission_power_description_().c_str()); + ESP_LOGD(TAG, this->config.channel_description_().c_str()); + ESP_LOGD(TAG, this->config.reg_3.enable_lbt_description_().c_str()); + ESP_LOGD(TAG, this->config.reg_3.wor_period_description_().c_str()); + ESP_LOGD(TAG, this->config.reg_3.enable_rssi_description_().c_str()); + ESP_LOGD(TAG, this->config.reg_3.transmission_type_description_().c_str()); set_mode_(NORMAL); } else { ESP_LOGW(TAG, "Junk on wire. Throwing away partial message"); diff --git a/esphome/components/ebyte_lora/ebyte_lora.h b/esphome/components/ebyte_lora/ebyte_lora.h index 60b7f8ee66..8fcaa9f004 100644 --- a/esphome/components/ebyte_lora/ebyte_lora.h +++ b/esphome/components/ebyte_lora/ebyte_lora.h @@ -24,7 +24,7 @@ class EbyteLoraSwitch; class EbyteLoraComponent : public PollingComponent, public uart::UARTDevice { public: void setup() override; - void update() override { send_switch_info_(); } + void update() override; float get_setup_priority() const override { return setup_priority::HARDWARE; } void loop() override; void dump_config() override; @@ -55,6 +55,7 @@ class EbyteLoraComponent : public PollingComponent, public uart::UARTDevice { uint32_t starting_to_check_; uint32_t time_out_after_; std::string raw_message_; + RegisterConfig config; sensor::Sensor *rssi_sensor_{nullptr}; GPIOPin *pin_aux_; GPIOPin *pin_m0_;