Skip to content

Commit

Permalink
[ESP32] Fixed the documentation to use the Scan Response Data
Browse files Browse the repository at this point in the history
  • Loading branch information
shripad621git committed Dec 11, 2024
1 parent 29c6fd8 commit e4f17c6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions docs/platforms/esp32/ble_settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ advertising packets.

```
{
uint8_t scanResponse[31]; // 0x05, 0x09, a, b, c, d
scanResponse[0] = 0x05;
scanResponse[1] = 0x09;
scanResponse[2] = 0x61;
scanResponse[3] = 0x62;
scanResponse[4] = 0x63;
scanResponse[5] = 0x64;
// Max length is 31 bytes
// Enter data in (length, type, value) format
// 0x05 - length of data
// 0x09 - Type (Complete Local Name)
// 0x61, 0x62, 0x63, 0x64 - Data (a,b,c,d)
uint8_t scanResponse[] = { 0x05, 0x09, 0x61, 0x62, 0x63, 0x64};
chip::ByteSpan data(scanResponse);
CHIP_ERROR err = chip::DeviceLayer::Internal::BLEMgrImpl().ConfigureScanResponseData(data);
if (err != CHIP_NO_ERROR)
{
ESP_LOGE(TAG, "Failed to configure scan response, err:%" CHIP_ERROR_FORMAT, err.Format());
}
}
```

Note: Scan response should be configure before `InitServer`.
2 changes: 1 addition & 1 deletion src/platform/ESP32/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class BLEManagerImpl final : public BLEManager,
#endif // CONFIG_ENABLE_ESP32_BLE_CONTROLLER
{
public:
uint8_t scanResponseBuffer[MAX_SCAN_RSP_DATA_LEN];
BLEManagerImpl() {}
#ifdef CONFIG_ENABLE_ESP32_BLE_CONTROLLER
CHIP_ERROR ConfigureBle(uint32_t aAdapterId, bool aIsCentral);
Expand All @@ -146,6 +145,7 @@ class BLEManagerImpl final : public BLEManager,

private:
chip::Optional<chip::ByteSpan> mScanResponse;
uint8_t scanResponseBuffer[MAX_SCAN_RSP_DATA_LEN];

// Allow the BLEManager interface class to delegate method calls to
// the implementation methods provided by this class.
Expand Down
2 changes: 1 addition & 1 deletion src/platform/ESP32/nimble/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ CHIP_ERROR BLEManagerImpl::ConfigureScanResponseData(ByteSpan data)
return CHIP_ERROR_INVALID_ARGUMENT;
}
memcpy(scanResponseBuffer, data.data(), data.size());
ByteSpan scanResponseSpan(scanResponseBuffer);
ByteSpan scanResponseSpan(scanResponseBuffer, data.size());
mScanResponse = chip::Optional<ByteSpan>(scanResponseSpan);
return CHIP_NO_ERROR;
}
Expand Down

0 comments on commit e4f17c6

Please sign in to comment.