Skip to content

samples: bluetooth: peripheral_hids_mouse: Use low duty direct adv#27650

Merged
rlubos merged 1 commit into
nrfconnect:mainfrom
alstrzebonski:hid_samples_fix_dir_adv_disc
Mar 30, 2026
Merged

samples: bluetooth: peripheral_hids_mouse: Use low duty direct adv#27650
rlubos merged 1 commit into
nrfconnect:mainfrom
alstrzebonski:hid_samples_fix_dir_adv_disc

Conversation

@alstrzebonski
Copy link
Copy Markdown

Uses low duty directed advertising to prevent disconnecting connected peers which could happen when using high duty advertising. Introduces directed advertising timeout as low duty advertising has no automatic timeout.

Jira: NCSDK-37899

@alstrzebonski alstrzebonski requested a review from a team as a code owner March 23, 2026 17:04
@NordicBuilder
Copy link
Copy Markdown
Contributor

NordicBuilder commented Mar 23, 2026

CI Information

To view the history of this post, click the 'edited' button above
Build number: 14

Inputs:

Sources:

sdk-nrf: PR head: f967b833248ed495562d61b4e5fad45e45335f57

more details

sdk-nrf:

PR head: f967b833248ed495562d61b4e5fad45e45335f57
merge base: bac4d0218e7f1fc6ece5eb80e95d3006f116b1e6
target head (main): 7a2e1bf98a9e36e6efb9dba9adaaee54e0012b71
Diff

Github labels

Enabled Name Description
ci-disabled Disable the ci execution
ci-all-test Run all of ci, no test spec filtering will be done
ci-force-downstream Force execution of downstream even if twister fails
ci-run-twister Force run twister
ci-run-zephyr-twister Force run zephyr twister
List of changed files detected by CI (3)
doc
│  ├── nrf
│  │  ├── releases_and_maturity
│  │  │  ├── releases
│  │  │  │  │ release-notes-changelog.rst
samples
│  ├── bluetooth
│  │  ├── peripheral_hids_mouse
│  │  │  ├── README.rst
│  │  │  ├── src
│  │  │  │  │ main.c

Outputs:

Toolchain

Version: 911f4c5c26
Build docker image: docker-dtr.nordicsemi.no/sw-production/ncs-build:911f4c5c26_5ea73affbf

Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped; ⚠️ Quarantine

  • ◻️ Toolchain - Skipped: existing toolchain is used
  • ✅ Build twister
    • sdk-nrf test count: 17
  • ✅ Integration tests
Disabled integration tests
    • test-fw-nrfconnect-nrf_lrcs_mosh
    • test-fw-nrfconnect-nrf_lrcs_positioning
    • desktop52_verification
    • test_ble_nrf_config
    • test-fw-nrfconnect-apps
    • test-fw-nrfconnect-ble_mesh
    • test-fw-nrfconnect-ble_samples
    • test-fw-nrfconnect-chip
    • test-fw-nrfconnect-fem
    • test-fw-nrfconnect-nfc
    • test-fw-nrfconnect-nrf-iot_libmodem-nrf
    • test-fw-nrfconnect-nrf-iot_lwm2m
    • test-fw-nrfconnect-nrf-iot_samples
    • test-fw-nrfconnect-nrf-iot_thingy91
    • test-fw-nrfconnect-nrf-iot_zephyr_lwm2m
    • test-fw-nrfconnect-nrf_crypto
    • test-fw-nrfconnect-ps-main
    • test-fw-nrfconnect-rpc
    • test-fw-nrfconnect-rs
    • test-fw-nrfconnect-tfm
    • test-fw-nrfconnect-thread-main
    • test-low-level
    • test-sdk-audio
    • test-sdk-dfu
    • test-sdk-find-my
    • test-sdk-mcuboot
    • test-sdk-wifi
    • test-secdom-samples-public

Note: This message is automatically posted and updated by the CI

@alstrzebonski alstrzebonski force-pushed the hid_samples_fix_dir_adv_disc branch 2 times, most recently from a6aca48 to 0efee95 Compare March 23, 2026 17:41
@alstrzebonski
Copy link
Copy Markdown
Author

Documentation will be added later in this PR.

@alstrzebonski alstrzebonski force-pushed the hid_samples_fix_dir_adv_disc branch from 0efee95 to ced1c86 Compare March 24, 2026 10:32
@alstrzebonski alstrzebonski requested review from a team as code owners March 24, 2026 10:32
@alstrzebonski
Copy link
Copy Markdown
Author

Added documentation.

@NordicBuilder NordicBuilder added doc-required PR must not be merged without tech writer approval. changelog labels Mar 24, 2026
This feature changes the way advertising works in comparison to the other Bluetooth Low Energy samples.
When the device wants to advertise, it starts with high duty cycle directed advertising provided that it has bonding information.
When the device wants to advertise, it starts with low duty cycle directed advertising provided that it has bonding information.
Each directed advertising attempt has a 2-second timeout.
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.

Suggested change
Each directed advertising attempt has a 2-second timeout.
Each directed advertising attempt has a timeout of two seconds.

* Privacy (:kconfig:option:`CONFIG_BT_PRIVACY`) - The `Bluetooth Low Energy app`_ does not fully support the Bluetooth Privacy feature by disallowing distribution of the Identity Resolving Key (IRK) during the pairing procedure.
* High-duty directed advertising (:kconfig:option:`CONFIG_BT_DIRECTED_ADVERTISING`) - High-duty directed advertising with 3.75 ms advertising interval and 1.28 s duration prevents the subsequent undirected advertising from being reported in the scanning list of `Bluetooth Low Energy app`_ .
As a result, it is only possible to connect to the target DK during the very short interval of high-duty directed advertising.
* Low-duty directed advertising (:kconfig:option:`CONFIG_BT_DIRECTED_ADVERTISING`) - Low-duty directed advertising with 2 s duration prevents the subsequent undirected advertising from being reported in the scanning list of `Bluetooth Low Energy app`_ .
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.

Suggested change
* Low-duty directed advertising (:kconfig:option:`CONFIG_BT_DIRECTED_ADVERTISING`) - Low-duty directed advertising with 2 s duration prevents the subsequent undirected advertising from being reported in the scanning list of `Bluetooth Low Energy app`_ .
* Low-duty directed advertising (:option:`CONFIG_BT_DIRECTED_ADVERTISING`) - Low-duty directed advertising with duration of two seconds prevents the subsequent undirected advertising from being reported in the scanning list of `Bluetooth Low Energy app`_ .

The feature depends on Bluetooth LE security support (:option:`CONFIG_BT_HIDS_SECURITY_ENABLED`).
This feature changes the way advertising works in comparison to the other Bluetooth Low Energy samples.
When the device wants to advertise, it starts with high duty cycle directed advertising provided that it has bonding information.
When the device wants to advertise, it starts with low duty cycle directed advertising provided that it has bonding information.
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.

Suggested change
When the device wants to advertise, it starts with low duty cycle directed advertising provided that it has bonding information.
When the device wants to advertise, it starts with low-duty cycle directed advertising provided that it has bonding information.

Comment on lines +428 to +429
* The directed advertising from high duty cycle to low duty cycle to prevent disconnecting already connected peers.
A 2-second timeout is used for each low duty cycle directed advertising attempt.
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.

Suggested change
* The directed advertising from high duty cycle to low duty cycle to prevent disconnecting already connected peers.
A 2-second timeout is used for each low duty cycle directed advertising attempt.
* The directed advertising from high-duty to low-duty cycle to prevent disconnecting peers that are already connected.
A timeout of two seconds is used for each low-duty cycle directed advertising attempt.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 24, 2026

@alstrzebonski alstrzebonski force-pushed the hid_samples_fix_dir_adv_disc branch from ced1c86 to 1fe2e2b Compare March 24, 2026 11:12
@alstrzebonski alstrzebonski requested a review from peknis March 24, 2026 11:13
Comment thread samples/bluetooth/peripheral_hids_mouse/src/main.c Outdated
Comment thread samples/bluetooth/peripheral_hids_mouse/src/main.c Outdated
Comment thread samples/bluetooth/peripheral_hids_mouse/README.rst Outdated
Comment thread doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst
Comment thread samples/bluetooth/peripheral_hids_mouse/README.rst Outdated
@alstrzebonski alstrzebonski force-pushed the hid_samples_fix_dir_adv_disc branch 2 times, most recently from 9573b49 to 5a1b908 Compare March 24, 2026 15:45
Comment thread samples/bluetooth/peripheral_hids_mouse/src/main.c
Comment thread doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst Outdated
Comment thread doc/nrf/releases_and_maturity/known_issues.rst Outdated
When the device wants to advertise, it starts with directed advertising provided that it has bonding information.
When there is at least one connected peer, low-duty cycle directed advertising is used.
Otherwise, high-duty cycle directed advertising is used.
The low-duty cycle directed advertising is used because scheduling high-duty directed advertising may cause problems with reacting to Bluetooth LE connection events from connected peers which can lead to disconnections.
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.

Suggested change
The low-duty cycle directed advertising is used because scheduling high-duty directed advertising may cause problems with reacting to Bluetooth LE connection events from connected peers which can lead to disconnections.
The low-duty cycle directed advertising is used because scheduling high-duty directed advertising might cause problems with reacting to Bluetooth LE connection events from connected peers, which can result in disconnections.

Comment thread doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst Outdated

.. rst-class:: v3-2-4 v3-2-3 v3-2-2 v3-2-1 v3-2-0

NCSDK-37899: High-duty cycle directed advertising in the :ref:`peripheral_hids_mouse` sample may lead to disconnecting connected peers
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.

Consider also mentioning what would happen for older NCS releases (before SoftDevice scheduler update). The behavior is different there (but device still would not work properly)

Comment thread doc/nrf/releases_and_maturity/known_issues.rst Outdated
Comment thread doc/nrf/releases_and_maturity/known_issues.rst Outdated
Comment thread samples/bluetooth/peripheral_hids_mouse/src/main.c Outdated
Comment thread samples/bluetooth/peripheral_hids_mouse/src/main.c
Comment thread samples/bluetooth/peripheral_hids_mouse/src/main.c
Comment thread samples/bluetooth/peripheral_hids_mouse/src/main.c
@alstrzebonski alstrzebonski force-pushed the hid_samples_fix_dir_adv_disc branch from 5a1b908 to 3ba11a3 Compare March 25, 2026 12:58
printk("Direct advertising to %s started\n", addr_buf);

/* High-duty directed advertising expires automatically after timeout defined in
* the Bluetooth specification. The Blutooth stack will call connected() callback
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.

Suggested change
* the Bluetooth specification. The Blutooth stack will call connected() callback
* the Bluetooth specification. The Bluetooth stack will call connected() callback

Comment thread samples/bluetooth/peripheral_hids_mouse/src/main.c
Uses low duty directed advertising to prevent disconnecting
connected peers which could happen when using high duty
advertising. Introduces directed advertising timeout as
low duty advertising has no automatic timeout.

Jira: NCSDK-37899

Signed-off-by: Aleksander Strzebonski <aleksander.strzebonski@nordicsemi.no>
@alstrzebonski alstrzebonski force-pushed the hid_samples_fix_dir_adv_disc branch from dbb8636 to f967b83 Compare March 30, 2026 13:16
@alstrzebonski
Copy link
Copy Markdown
Author

Rebased on main.

@rlubos
Copy link
Copy Markdown
Contributor

rlubos commented Mar 30, 2026

@MarekPieta Please revisit

@MarekPieta MarekPieta added the bugfix Fixes a known bug label Mar 30, 2026
@rlubos rlubos merged commit 1de0579 into nrfconnect:main Mar 30, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes a known bug changelog doc-required PR must not be merged without tech writer approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants