mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	[esp32_ble_tracker] Optimize connection by promoting client immediately after scan stop trigger (#10061)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
		| @@ -238,10 +238,13 @@ void ESP32BLETracker::loop() { | |||||||
|         if (this->scanner_state_ == ScannerState::RUNNING) { |         if (this->scanner_state_ == ScannerState::RUNNING) { | ||||||
|           ESP_LOGD(TAG, "Stopping scan to make connection"); |           ESP_LOGD(TAG, "Stopping scan to make connection"); | ||||||
|           this->stop_scan_(); |           this->stop_scan_(); | ||||||
|         } else if (this->scanner_state_ == ScannerState::IDLE) { |           // Don't wait for scan stop complete - promote immediately. | ||||||
|  |           // This is safe because ESP-IDF processes BLE commands sequentially through its internal mailbox queue. | ||||||
|  |           // This guarantees that the stop scan command will be fully processed before any subsequent connect command, | ||||||
|  |           // preventing race conditions or overlapping operations. | ||||||
|  |         } | ||||||
|  |  | ||||||
|         ESP_LOGD(TAG, "Promoting client to connect"); |         ESP_LOGD(TAG, "Promoting client to connect"); | ||||||
|           // We only want to promote one client at a time. |  | ||||||
|           // once the scanner is fully stopped. |  | ||||||
| #ifdef USE_ESP32_BLE_SOFTWARE_COEXISTENCE | #ifdef USE_ESP32_BLE_SOFTWARE_COEXISTENCE | ||||||
|         ESP_LOGD(TAG, "Setting coexistence to Bluetooth to make connection."); |         ESP_LOGD(TAG, "Setting coexistence to Bluetooth to make connection."); | ||||||
|         if (!this->coex_prefer_ble_) { |         if (!this->coex_prefer_ble_) { | ||||||
| @@ -250,7 +253,6 @@ void ESP32BLETracker::loop() { | |||||||
|         } |         } | ||||||
| #endif | #endif | ||||||
|         client->set_state(ClientState::READY_TO_CONNECT); |         client->set_state(ClientState::READY_TO_CONNECT); | ||||||
|         } |  | ||||||
|         break; |         break; | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user