diff --git a/libraries/Bluefruit52Lib/src/BLEAdvertising.cpp b/libraries/Bluefruit52Lib/src/BLEAdvertising.cpp index ce41a959..135af4ad 100644 --- a/libraries/Bluefruit52Lib/src/BLEAdvertising.cpp +++ b/libraries/Bluefruit52Lib/src/BLEAdvertising.cpp @@ -265,6 +265,7 @@ BLEAdvertising::BLEAdvertising(void) _stop_timeout = _left_timeout = 0; _stop_cb = NULL; _slow_cb = NULL; + _directed = false; // Broadcast advertising is the default } void BLEAdvertising::setFastTimeout(uint16_t sec) @@ -315,6 +316,17 @@ void BLEAdvertising::setStopCallback(stop_callback_t fp) _stop_cb = fp; } +void BLEAdvertising::setPeerAddress(const ble_gap_addr_t& peer_addr) +{ + _directed = true; + _peer_addr = peer_addr; // Copy address, used later in start function +} + +void BLEAdvertising::removePeerAddress() +{ + _directed = false; +} + bool BLEAdvertising::isRunning(void) { return _runnning; @@ -354,6 +366,11 @@ bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout) // , .set_id, .scan_req_notification }; + if (_directed) { + // Set target address when not using broadcasting + adv_para.p_peer_addr = &_peer_addr; + } + // gap_adv long-live is required by SD v6 static ble_gap_adv_data_t gap_adv = { @@ -464,5 +481,4 @@ void BLEAdvertising::_eventHandler(ble_evt_t* evt) default: break; } -} - +} \ No newline at end of file diff --git a/libraries/Bluefruit52Lib/src/BLEAdvertising.h b/libraries/Bluefruit52Lib/src/BLEAdvertising.h index b719a664..f69c66ea 100644 --- a/libraries/Bluefruit52Lib/src/BLEAdvertising.h +++ b/libraries/Bluefruit52Lib/src/BLEAdvertising.h @@ -134,6 +134,12 @@ public: bool setBeacon(BLEBeacon& beacon); bool setBeacon(EddyStoneUrl& eddy_url); + /// Advertise to a single peer instead of broadcasting + void setPeerAddress(const ble_gap_addr_t& peer_addr); + + /// Revert to broadcast advertising + void removePeerAddress(); + bool isRunning(void); void restartOnDisconnect(bool enable); @@ -152,6 +158,8 @@ private: uint8_t _type; bool _start_if_disconnect; bool _runnning; + ble_gap_addr_t _peer_addr; //! Target address for an ADV_DIRECT_IND advertisement + bool _directed; //! Whether the advertisements are directed or broadcast uint32_t _conn_mask;