-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
extmod/modbluetooth_nimble.c
Outdated
.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) { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
84800f7
to
d770e14
Compare
Thanks, have made the suggested changes. |
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.) |
d770e14
to
06e52e5
Compare
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.
06e52e5
to
76f4741
Compare
samd: diagnose out of range I2C frequency
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).