Skip to content

extmod/modbluetooth: Allow config of scan interval/window. #5190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 11, 2019

Conversation

jimmo
Copy link
Member

@jimmo jimmo commented Oct 8, 2019

This adds two additional optional kwargs to gap_scan():

  • interval_ms: How long between scans.
  • window_ms: How long to scan for during a scan.

The default with NimBLE is a 11.25ms window with a 1.28s interval.

Changing these parameters is important for detecting low-frequency
advertisements (e.g. beacons).

@jimmo jimmo mentioned this pull request Oct 8, 2019
13 tasks
.window = BLE_GAP_SCAN_SLOW_WINDOW1,
uint16_t interval = BLE_GAP_SCAN_SLOW_INTERVAL1;
uint16_t window = BLE_GAP_SCAN_SLOW_WINDOW1;
if (interval_ms > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

No need to check this, just assume valid (default at least) values are passed in.

.filter_policy = BLE_HCI_CONN_FILT_NO_WL,
.limited = 0,
.passive = 0,
.passive = 1, // TODO: Handle BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP in gap_scan_cb above.
Copy link
Member

Choose a reason for hiding this comment

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

Why does this need to be changed?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was wrong before, because we're not handling the scan response event. Now that this change allows us to scan much faster, no point spamming the radio with active scans if we're going to ignore them.

I plan to add an active=True arg to scan() later when implementing active scans.

@dpgeorge dpgeorge added the extmod Relates to extmod/ directory in source label Oct 9, 2019
@jimmo jimmo force-pushed the ble-scan-interval-window branch from 84800f7 to d770e14 Compare October 9, 2019 11:12
@jimmo
Copy link
Member Author

jimmo commented Oct 9, 2019

Thanks, have made the suggested changes.

@dpgeorge
Copy link
Member

dpgeorge commented Oct 9, 2019

Looking at this again I see that the scanning intervals are in millisecond units. But this doesn't give enough resolution (in integers) to match what's possible with BLE. BLE scanning (and advertising) uses units of 625us, and so allows fractional millisecond values.

So I think it'd be good to change the units of these interval parameters to microseconds. (But keep the scan duration in milliseconds, which is not related to the BLE spec.)

@jimmo jimmo force-pushed the ble-scan-interval-window branch from d770e14 to 06e52e5 Compare October 11, 2019 02:17
jimmo added 2 commits October 11, 2019 13:51
This adds two additional optional kwargs to `gap_scan()`:
  - `interval_us`: How long between scans.
  - `window_us`: How long to scan for during a scan.

The default with NimBLE is a 11.25ms window with a 1.28s interval.

Changing these parameters is important for detecting low-frequency
advertisements (e.g. beacons).

Note: these params are in microseconds, not milliseconds in order
to allow the 625us granularity offered by the spec.
This is to more accurately match the BLE spec, where intervals are
configured in units of channel hop time (625us). When it was
specified in ms, not all "valid" intervals were able to be
specified.

Now that we're also allowing configuration of scan interval, this
commit updates advertising to match.
@jimmo jimmo force-pushed the ble-scan-interval-window branch from 06e52e5 to 76f4741 Compare October 11, 2019 02:51
@dpgeorge dpgeorge merged commit 76f4741 into micropython:master Oct 11, 2019
tannewt pushed a commit to tannewt/circuitpython that referenced this pull request Aug 24, 2021
samd: diagnose out of range I2C frequency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extmod Relates to extmod/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy