From 70906ab18fee72f3cbe1fee6656097e8fe1ad651 Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Thu, 31 Oct 2024 17:31:30 +0800 Subject: [PATCH] example: Fix ble advertisement refresh after ble disconnection for light_wifi_prov example --- .../platform/ESP32_custom/BLEManagerImpl.h | 2 ++ .../platform/ESP32_custom/nimble/BLEManagerImpl.cpp | 8 ++++++++ .../main/wifi_prov_scheme/protocomm_matter_ble.cpp | 1 + 3 files changed, 11 insertions(+) diff --git a/examples/common/secondary_ble_adv/platform/ESP32_custom/BLEManagerImpl.h b/examples/common/secondary_ble_adv/platform/ESP32_custom/BLEManagerImpl.h index e5480505c..1f64bb46d 100644 --- a/examples/common/secondary_ble_adv/platform/ESP32_custom/BLEManagerImpl.h +++ b/examples/common/secondary_ble_adv/platform/ESP32_custom/BLEManagerImpl.h @@ -186,6 +186,8 @@ class BLEManagerImpl final : public BLEManager, mSecondaryBleSmSc = bleSmSc; } + void RefreshAdv(void); + private: chip::Optional mScanResponse; diff --git a/examples/common/secondary_ble_adv/platform/ESP32_custom/nimble/BLEManagerImpl.cpp b/examples/common/secondary_ble_adv/platform/ESP32_custom/nimble/BLEManagerImpl.cpp index 75328ddb3..a2c934db0 100644 --- a/examples/common/secondary_ble_adv/platform/ESP32_custom/nimble/BLEManagerImpl.cpp +++ b/examples/common/secondary_ble_adv/platform/ESP32_custom/nimble/BLEManagerImpl.cpp @@ -1365,6 +1365,14 @@ CHIP_ERROR BLEManagerImpl::HandleGAPConnect(struct ble_gap_event * gapEvent) #endif } +void BLEManagerImpl::RefreshAdv(void) +{ + mFlags.Set(Flags::kAdvertisingRefreshNeeded); + mFlags.Clear(Flags::kAdvertisingConfigured); + + PlatformMgr().ScheduleWork(DriveBLEState, 0); +} + CHIP_ERROR BLEManagerImpl::HandleGAPDisconnect(struct ble_gap_event * gapEvent) { ChipLogProgress(DeviceLayer, "BLE GAP connection terminated (con %u reason 0x%02x)", gapEvent->disconnect.conn.conn_handle, diff --git a/examples/light_wifi_prov/main/wifi_prov_scheme/protocomm_matter_ble.cpp b/examples/light_wifi_prov/main/wifi_prov_scheme/protocomm_matter_ble.cpp index 260944843..6e7f0b754 100644 --- a/examples/light_wifi_prov/main/wifi_prov_scheme/protocomm_matter_ble.cpp +++ b/examples/light_wifi_prov/main/wifi_prov_scheme/protocomm_matter_ble.cpp @@ -402,6 +402,7 @@ static int protocomm_matter_ble_gap_event(struct ble_gap_event *event, void *arg break; case BLE_GAP_EVENT_DISCONNECT: transport_matter_ble_disconnect(event, arg); + chip::DeviceLayer::Internal::BLEMgrImpl().RefreshAdv(); break; case BLE_GAP_EVENT_MTU: transport_matter_ble_set_mtu(event, arg);