@@ -253,7 +253,7 @@ BLEAdvertising::BLEAdvertising(void)
253
253
_hdl = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
254
254
_type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
255
255
_start_if_disconnect = true ;
256
- _runnning = false ;
256
+ _running = false ;
257
257
258
258
_conn_mask = 0 ;
259
259
@@ -321,7 +321,7 @@ void BLEAdvertising::setPeerAddress(const ble_gap_addr_t& peer_addr) {
321
321
322
322
bool BLEAdvertising::isRunning (void )
323
323
{
324
- return _runnning ;
324
+ return _running ;
325
325
}
326
326
327
327
bool BLEAdvertising::setBeacon (BLEBeacon& beacon)
@@ -339,8 +339,7 @@ void BLEAdvertising::restartOnDisconnect(bool enable)
339
339
_start_if_disconnect = enable;
340
340
}
341
341
342
- bool BLEAdvertising::_start (uint16_t interval, uint16_t timeout)
343
- {
342
+ bool BLEAdvertising::_start (uint16_t interval, uint16_t timeout) {
344
343
// ADV Params
345
344
ble_gap_adv_params_t adv_para = {
346
345
.properties = { .type = _type, .anonymous = 0 },
@@ -369,17 +368,24 @@ bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout)
369
368
default : break ;
370
369
}
371
370
371
+ // stop first if current running since we may change advertising data/params
372
+ if (_running) {
373
+ sd_ble_gap_adv_stop (_hdl);
374
+ }
375
+
372
376
// gap_adv long-live is required by SD v6
373
- static ble_gap_adv_data_t gap_adv = {
374
- .adv_data = { .p_data = _data, .len = _count },
375
- .scan_rsp_data = { .p_data = Bluefruit.ScanResponse .getData (), .len = Bluefruit.ScanResponse .count () }
376
- };
377
+ static ble_gap_adv_data_t gap_adv;
378
+ gap_adv.adv_data .p_data = _data;
379
+ gap_adv.adv_data .len = _count;
380
+ gap_adv.scan_rsp_data .p_data = Bluefruit.ScanResponse .getData ();
381
+ gap_adv.scan_rsp_data .len = Bluefruit.ScanResponse .count ();
382
+
377
383
VERIFY_STATUS ( sd_ble_gap_adv_set_configure (&_hdl, &gap_adv, &adv_para), false );
378
384
VERIFY_STATUS ( sd_ble_gap_tx_power_set (BLE_GAP_TX_POWER_ROLE_ADV, _hdl, Bluefruit.getTxPower () ), false );
379
385
VERIFY_STATUS ( sd_ble_gap_adv_start (_hdl, CONN_CFG_PERIPHERAL), false );
380
386
381
387
Bluefruit._startConnLed (); // start blinking
382
- _runnning = true ;
388
+ _running = true ;
383
389
_active_interval = interval;
384
390
385
391
_left_timeout -= min16 (_left_timeout, timeout);
@@ -403,7 +409,7 @@ bool BLEAdvertising::stop(void)
403
409
{
404
410
VERIFY_STATUS ( sd_ble_gap_adv_stop (_hdl), false );
405
411
406
- _runnning = false ;
412
+ _running = false ;
407
413
Bluefruit._stopConnLed (); // stop blinking
408
414
409
415
return true ;
@@ -425,7 +431,7 @@ void BLEAdvertising::_eventHandler(ble_evt_t* evt)
425
431
{
426
432
bitSet (_conn_mask, conn_hdl);
427
433
428
- _runnning = false ;
434
+ _running = false ;
429
435
}
430
436
}
431
437
break ;
@@ -436,14 +442,14 @@ void BLEAdvertising::_eventHandler(ble_evt_t* evt)
436
442
bitClear (_conn_mask, conn_hdl);
437
443
438
444
// Auto start if enabled and not connected to any central
439
- if ( !_runnning && _start_if_disconnect ) start (_stop_timeout);
445
+ if ( !_running && _start_if_disconnect ) start (_stop_timeout);
440
446
}
441
447
break ;
442
448
443
449
case BLE_GAP_EVT_ADV_SET_TERMINATED:
444
450
if (evt->evt .gap_evt .params .adv_set_terminated .reason == BLE_GAP_EVT_ADV_SET_TERMINATED_REASON_TIMEOUT)
445
451
{
446
- _runnning = false ;
452
+ _running = false ;
447
453
448
454
// If still advertising, it is only in slow mode --> blink normal
449
455
Bluefruit.setConnLedInterval (CFG_ADV_BLINKY_INTERVAL);
0 commit comments