Skip to content

samples: bluetooth: fixes and cleanup central samples#799

Open
anhmolt wants to merge 5 commits into
nrfconnect:mainfrom
anhmolt:fixes-central-samples
Open

samples: bluetooth: fixes and cleanup central samples#799
anhmolt wants to merge 5 commits into
nrfconnect:mainfrom
anhmolt:fixes-central-samples

Conversation

@anhmolt
Copy link
Copy Markdown
Contributor

@anhmolt anhmolt commented May 20, 2026

  • Cleanup of ble_hrs_central and ble_nus_central main source files.
  • Fix an issue where the address of connected target was printed reversed and the target_periph_addr had wrong endianness in the ble_hrs_central sample.
  • Add missing address scan filter code to the ble_nus_central sample.
  • Align ble_nus_central sample to use button 1 to disconnect from peripheral device.

@github-actions github-actions Bot added the doc-required PR must not be merged without tech writer approval. label May 20, 2026
@github-actions
Copy link
Copy Markdown

You can find the documentation preview for this PR here.

@anhmolt anhmolt force-pushed the fixes-central-samples branch 3 times, most recently from c0e87c9 to 4de76da Compare May 22, 2026 14:45
@anhmolt anhmolt marked this pull request as ready for review May 26, 2026 12:15
@anhmolt anhmolt requested review from a team as code owners May 26, 2026 12:15
Copy link
Copy Markdown
Contributor

@eivindj-nordic eivindj-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

case BLE_NUS_CLIENT_EVT_DISCONNECTED:
LOG_INF("Disconnected");
(void)scan_start();
LOG_INF("NUS Disconnected");
Copy link
Copy Markdown
Contributor

@eivindj-nordic eivindj-nordic May 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NUS disconnected (lower case in disconnected) to align with others.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

/* GATT queue instance. */
BLE_GQ_DEF(ble_gq);
/* DB discovery module instance. */
/* Database discovery instance. */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra whitespace after /*

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@anhmolt anhmolt force-pushed the fixes-central-samples branch from 4de76da to 1905014 Compare May 27, 2026 08:22
Comment on lines +599 to +601
nrf_err = ble_scan_filter_add(&ble_scan, BLE_SCAN_NAME_FILTER, &filter_data);
if (nrf_err) {
LOG_ERR("nrf_ble_scan_filter_add name failed, nrf_error %#x", nrf_err);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function being logged does not match the function being called?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Fixed in both samples.

anhmolt added 5 commits May 27, 2026 15:16
* Update header include list. Remove unused and reorder list.
* Update return type of scan_start and delete_bonds functions to
  void because the returned error values are not used.
* Update some comments.
* Align names some event handlers and init functions.
* Align setup of scan filters with other central samples.
* Move initialization of buttons and leds to a static function
  to align with other central samples.
* Use BLE_GAP_WHITELIST_ADDR_MAX_COUNT instead of hardcoding
  length of arrays used for allow lists to 8.
* Remove some duplicate logs.
* Remove gatt_init static function "shell" and set conn_params
  event handler directly from main.

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
* Update header include list. Add missing and reorder.
* Update return type of scan_start function to void because the
  returned error values are not used.
* Align the placement of const keyword for some parameters and
  variables.
* Align names some event handlers and init functions.
* Align setup of scan filters with other central samples.
* Removed call to ble_nus_client_handles_assign from
  BLE_GAP_EVT_CONNECTED evt handling (it is done from
  BLE_NUS_CLIENT_EVT_DISCOVERY_COMPLETE event handling) and
  moved a call to scan_start() from BLE_NUS_CLIENT_EVT_DISCONNECTED
  event handling to BLE_GAP_EVT_DISCONNECTED event handling to align
  with ble_hrs_central sample.
* Removed application specific handling of the
  BLE_GAP_EVT_PHY_UPDATE_REQUEST event. It is now handled by
  the conn_params library.
* Removed some duplicate logging of ATT MTU and data length updates.

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
The address set with the CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR Kconfig
was incorrectly converted to big-endian before being passed to the
SoftDevice API (which uses little-endian for the address).
In turn, the address printed on a BLE_SCAN_EVT_CONNECTED event was
also incorrect (displayed inverted).

Fix both these issues so that the Kconfig and address print uses
big-endian (standard way to display an address), while the libraries
and SoftDevice use addresses in little-endian.

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
The Kconfig options for address scan filter was there, but the
code to set it up was missing. Add the missing bits.

Change print format for logging the address of a connected peer
device. Invert the bytes to correctly print the address and add
colons.

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
Updated to use button 1 to disconnect from target peripheral to align
with other central samples.

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
@anhmolt anhmolt force-pushed the fixes-central-samples branch from d4a0641 to 822f13d Compare May 27, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-required PR must not be merged without tech writer approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants