Merge pull request #102 from rbaron/ble-adv-int

Make advertisement intervals configurable
This commit is contained in:
rbaron 2023-01-28 11:52:00 +01:00 committed by GitHub
commit 997bfb7518
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View file

@ -10,6 +10,14 @@ config PRST_BLE_ADV_DURATION_SEC
int "Advertising duration in seconds"
default 1
config PRST_BLE_MIN_ADV_INTERVAL
int "Minimum advertising interval in milliseconds"
default 100
config PRST_BLE_MAX_ADV_INTERVAL
int "Maximum advertising interval in milliseconds"
default 150
choice PRST_BLE_ENCODING
prompt "b-parasite BLE encoding"
default PRST_BLE_ENCODING_BPARASITE_V2

View file

@ -55,12 +55,20 @@ int prst_ble_init() {
return 0;
}
#define PRST_MS_TO_INTERVAL(value_ms) ((uint16_t)(value_ms) / 0.625f)
int prst_ble_adv_start() {
// If BT_LE_ADV_NCONN_IDENTITY, this function will advertise with a static MAC
// address programmed in the chip. If BT_LE_ADV_NCONN, this function returns
// advertises with a random MAC each time.
return bt_le_adv_start(BT_LE_ADV_NCONN_IDENTITY, ad, ARRAY_SIZE(ad), sd,
ARRAY_SIZE(sd));
return bt_le_adv_start(
BT_LE_ADV_PARAM(
BT_LE_ADV_OPT_USE_IDENTITY,
PRST_MS_TO_INTERVAL(CONFIG_PRST_BLE_MIN_ADV_INTERVAL),
PRST_MS_TO_INTERVAL(CONFIG_PRST_BLE_MAX_ADV_INTERVAL),
NULL),
ad, ARRAY_SIZE(ad), sd,
ARRAY_SIZE(sd));
}
int prst_ble_adv_stop() {