mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 17:05:36 +00:00
[esp32_ble_tracker] Restart BLE scan after OTA failure
When OTA starts, stop_scan() is called which clears the scan_continuous_ flag. If OTA fails or aborts, the scan was never restarted because scan_continuous_ was already false. This left the device without BLE scanning until reboot. Save the scan_continuous_ state before stopping and restore it on OTA_ERROR or OTA_ABORT to resume scanning.
This commit is contained in:
@@ -88,12 +88,19 @@ void ESP32BLETracker::setup() {
|
||||
#ifdef USE_OTA_STATE_LISTENER
|
||||
void ESP32BLETracker::on_ota_global_state(ota::OTAState state, float progress, uint8_t error, ota::OTAComponent *comp) {
|
||||
if (state == ota::OTA_STARTED) {
|
||||
this->scan_continuous_before_ota_ = this->scan_continuous_;
|
||||
this->stop_scan();
|
||||
#ifdef ESPHOME_ESP32_BLE_TRACKER_CLIENT_COUNT
|
||||
for (auto *client : this->clients_) {
|
||||
client->disconnect();
|
||||
}
|
||||
#endif
|
||||
} else if (state == ota::OTA_ERROR || state == ota::OTA_ABORT) {
|
||||
if (this->scan_continuous_before_ota_) {
|
||||
this->scan_continuous_before_ota_ = false;
|
||||
this->scan_continuous_ = true;
|
||||
this->start_scan();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -436,6 +436,7 @@ class ESP32BLETracker : public Component,
|
||||
ScannerState scanner_state_{ScannerState::IDLE};
|
||||
bool scan_continuous_;
|
||||
bool scan_active_;
|
||||
bool scan_continuous_before_ota_{false};
|
||||
bool ble_was_disabled_{true};
|
||||
bool raw_advertisements_{false};
|
||||
bool parse_advertisements_{false};
|
||||
|
||||
Reference in New Issue
Block a user