18#ifndef NIMBLE_CPP_EXTADVERTISING_H_
19#define NIMBLE_CPP_EXTADVERTISING_H_
22#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER) && CONFIG_BT_NIMBLE_EXT_ADV
24# if defined(CONFIG_NIMBLE_CPP_IDF)
25# include "host/ble_gap.h"
27# include "nimble/nimble/host/include/host/ble_gap.h"
35# include "NimBLEAddress.h"
62 bool setURI(
const std::string& uri);
63 bool setName(
const std::string& name,
bool isComplete =
true);
71 bool setData(
const uint8_t* data,
size_t length);
72 bool addData(
const uint8_t* data,
size_t length);
73 bool addData(
const std::string& data);
84 void setScanFilter(
bool scanRequestWhitelistOnly,
bool connectWhitelistOnly);
86 void setDirected(
bool enable,
bool high_duty =
true);
101 bool setServices(
bool complete, uint8_t size,
const std::vector<NimBLEUUID>& uuids);
103 std::vector<uint8_t> m_payload{};
104 ble_gap_ext_adv_params m_params{};
115 bool start(uint8_t instId,
int duration = 0,
int maxEvents = 0);
120 bool stop(uint8_t instId);
131 static int handleGapEvent(
struct ble_gap_event* event,
void* arg);
133 bool m_deleteCallbacks;
135 std::vector<bool> m_advStatus;
A BLE device address.
Definition NimBLEAddress.h:41
A model of a BLE Device from which all the BLE roles are created.
Definition NimBLEDevice.h:109
Extended advertisement data.
Definition NimBLEExtAdvertising.h:46
void setAddress(const NimBLEAddress &addr)
Set the address to use for this advertisement.
Definition NimBLEExtAdvertising.cpp:404
bool setAppearance(uint16_t appearance)
Set the appearance.
Definition NimBLEExtAdvertising.cpp:578
bool setFlags(uint8_t flag)
Set the advertisement flags.
Definition NimBLEExtAdvertising.cpp:600
bool addServiceUUID(const NimBLEUUID &serviceUUID)
Add a service uuid to exposed list of services.
Definition NimBLEExtAdvertising.cpp:690
void clearData()
Clears the data stored in this instance, does not change settings.
Definition NimBLEExtAdvertising.cpp:523
void setAnonymous(bool enable)
Sets whether the advertisement should be anonymous.
Definition NimBLEExtAdvertising.cpp:507
bool setPartialServices32(const std::vector< NimBLEUUID > &uuids)
Set the partial list of services to advertise.
Definition NimBLEExtAdvertising.cpp:854
bool addData(const uint8_t *data, size_t length)
Add data to the payload to be advertised.
Definition NimBLEExtAdvertising.cpp:549
bool setCompleteServices16(const std::vector< NimBLEUUID > &uuids)
Set the complete list of 16 bit services to advertise.
Definition NimBLEExtAdvertising.cpp:818
void setScanFilter(bool scanRequestWhitelistOnly, bool connectWhitelistOnly)
Set the filtering for the scan filter.
Definition NimBLEExtAdvertising.cpp:427
bool removeData(uint8_t type)
Remove data from the advertisement data.
Definition NimBLEExtAdvertising.cpp:1037
bool setServiceData(const NimBLEUUID &uuid, const uint8_t *data, size_t length)
Set the service data advertised for the UUID.
Definition NimBLEExtAdvertising.cpp:915
bool setPreferredParams(uint16_t min, uint16_t max)
Set the preferred min and max connection intervals to advertise.
Definition NimBLEExtAdvertising.cpp:992
void setLegacyAdvertising(bool enable)
Sets wether the advertisement should use legacy (BLE 4.0, 31 bytes max) advertising.
Definition NimBLEExtAdvertising.cpp:369
bool setPartialServices(const NimBLEUUID &uuid)
Set a single service to advertise as a partial list of services.
Definition NimBLEExtAdvertising.cpp:836
void setMaxInterval(uint32_t maxinterval)
Set the maximum advertising interval.
Definition NimBLEExtAdvertising.cpp:476
bool setManufacturerData(const uint8_t *data, size_t length)
Set manufacturer specific data.
Definition NimBLEExtAdvertising.cpp:619
bool setShortName(const std::string &name)
Set the short name.
Definition NimBLEExtAdvertising.cpp:981
void setDirectedPeer(const NimBLEAddress &addr)
Sets the peer to directly advertise to.
Definition NimBLEExtAdvertising.cpp:450
std::string toString() const
Get the string representation of the advertisement data.
Definition NimBLEExtAdvertising.cpp:1061
bool removeServiceUUID(const NimBLEUUID &serviceUUID)
Remove a service UUID from the advertisement.
Definition NimBLEExtAdvertising.cpp:745
void setTxPower(int8_t dbm)
Sets the transmission power level for this advertisement.
Definition NimBLEExtAdvertising.cpp:386
bool setURI(const std::string &uri)
Set the URI to advertise.
Definition NimBLEExtAdvertising.cpp:655
int getDataLocation(uint8_t type) const
Get the location of the data in the payload.
Definition NimBLEExtAdvertising.cpp:1021
bool setName(const std::string &name, bool isComplete=true)
Set the complete name of this device.
Definition NimBLEExtAdvertising.cpp:673
void setSecondaryPhy(uint8_t phy)
Set the secondary advertising PHY to use.
Definition NimBLEExtAdvertising.cpp:497
bool setCompleteServices32(const std::vector< NimBLEUUID > &uuids)
Set the complete list of 32 bit services to advertise.
Definition NimBLEExtAdvertising.cpp:827
void enableScanRequestCallback(bool enable)
Sets whether the scan response request callback should be called.
Definition NimBLEExtAdvertising.cpp:515
void setPrimaryChannels(bool ch37, bool ch38, bool ch39)
Sets The primary channels to advertise on.
Definition NimBLEExtAdvertising.cpp:418
bool removeServices()
Remove all service UUIDs from the advertisement.
Definition NimBLEExtAdvertising.cpp:800
void setConnectable(bool enable)
Sets wether this advertisement should advertise as a connectable device.
Definition NimBLEExtAdvertising.cpp:394
void addTxPower()
Adds Tx power level to the advertisement data.
Definition NimBLEExtAdvertising.cpp:1012
void setPrimaryPhy(uint8_t phy)
Set the primary advertising PHY to use.
Definition NimBLEExtAdvertising.cpp:486
bool setPartialServices16(const std::vector< NimBLEUUID > &uuids)
Set the partial list of services to advertise.
Definition NimBLEExtAdvertising.cpp:845
void setScannable(bool enable)
Sets wether the advertisement has scan response data available.
Definition NimBLEExtAdvertising.cpp:377
size_t getDataSize() const
Get the size of the current data.
Definition NimBLEExtAdvertising.cpp:1053
void setMinInterval(uint32_t mininterval)
Set the minimum advertising interval.
Definition NimBLEExtAdvertising.cpp:468
bool setCompleteServices(const NimBLEUUID &uuid)
Set a single service to advertise as a complete list of services.
Definition NimBLEExtAdvertising.cpp:809
void setDirected(bool enable, bool high_duty=true)
Enable or disable direct advertisements to the peer set with NimBLEExtAdvertisement::setDirectedPeer
Definition NimBLEExtAdvertising.cpp:459
bool setData(const uint8_t *data, size_t length)
Set the advertisement data.
Definition NimBLEExtAdvertising.cpp:534
Callbacks associated with NimBLEExtAdvertising class.
Definition NimBLEExtAdvertising.h:141
virtual void onStopped(NimBLEExtAdvertising *pAdv, int reason, uint8_t instId)
Handle an advertising stop event.
Definition NimBLEExtAdvertising.cpp:336
virtual void onScanRequest(NimBLEExtAdvertising *pAdv, uint8_t instId, NimBLEAddress addr)
Handle a scan response request. This is called when a scanning device requests a scan response.
Definition NimBLEExtAdvertising.cpp:340
Extended advertising class.
Definition NimBLEExtAdvertising.h:111
bool stop()
Stop all advertisements.
Definition NimBLEExtAdvertising.cpp:230
~NimBLEExtAdvertising()
Destructor: deletes callback instances if requested.
Definition NimBLEExtAdvertising.cpp:47
bool start(uint8_t instId, int duration=0, int maxEvents=0)
Start extended advertising.
Definition NimBLEExtAdvertising.cpp:158
bool isActive(uint8_t instId)
Check if currently advertising.
Definition NimBLEExtAdvertising.cpp:263
bool removeAll()
Stop and remove all advertising instance data.
Definition NimBLEExtAdvertising.cpp:197
bool isAdvertising()
Check if any instances are currently advertising.
Definition NimBLEExtAdvertising.cpp:271
bool setScanResponseData(uint8_t instId, NimBLEExtAdvertisement &data)
Set the scan response data for a legacy advertisement.
Definition NimBLEExtAdvertising.cpp:134
bool removeInstance(uint8_t instId)
Stop and remove this instance data from the advertisement set.
Definition NimBLEExtAdvertising.cpp:180
void setCallbacks(NimBLEExtAdvertisingCallbacks *callbacks, bool deleteCallbacks=true)
Set a callback to call when the advertisement stops.
Definition NimBLEExtAdvertising.cpp:248
bool setInstanceData(uint8_t instId, NimBLEExtAdvertisement &adv)
Register the extended advertisement data.
Definition NimBLEExtAdvertising.cpp:59
NimBLEExtAdvertising()
Constructor.
Definition NimBLEExtAdvertising.cpp:39
The model of a BLE server.
Definition NimBLEServer.h:60
A model of a BLE UUID.
Definition NimBLEUUID.h:41