NimBLE-Arduino  1.4.1
NimBLEExtAdvertisement Class Reference

Extended advertisement data. More...

Public Member Functions

 NimBLEExtAdvertisement (uint8_t priPhy=BLE_HCI_LE_PHY_1M, uint8_t secPhy=BLE_HCI_LE_PHY_1M)
 Construct a BLE extended advertisement. More...
 
void setAppearance (uint16_t appearance)
 Set the appearance. More...
 
void setCompleteServices (const NimBLEUUID &uuid)
 Set a single service to advertise as a complete list of services. More...
 
void setCompleteServices16 (const std::vector< NimBLEUUID > &v_uuid)
 Set the complete list of 16 bit services to advertise. More...
 
void setCompleteServices32 (const std::vector< NimBLEUUID > &v_uuid)
 Set the complete list of 32 bit services to advertise. More...
 
void setFlags (uint8_t flag)
 Set the advertisement flags. More...
 
void setManufacturerData (const std::string &data)
 Set manufacturer specific data. More...
 
void setURI (const std::string &uri)
 Set the URI to advertise. More...
 
void setName (const std::string &name)
 Set the complete name of this device. More...
 
void setPartialServices (const NimBLEUUID &uuid)
 Set a single service to advertise as a partial list of services. More...
 
void setPartialServices16 (const std::vector< NimBLEUUID > &v_uuid)
 Set the partial list of services to advertise. More...
 
void setPartialServices32 (const std::vector< NimBLEUUID > &v_uuid)
 Set the partial list of services to advertise. More...
 
void setServiceData (const NimBLEUUID &uuid, const std::string &data)
 Set the service data (UUID + data) More...
 
void setShortName (const std::string &name)
 Set the short name. More...
 
void setData (const uint8_t *data, size_t length)
 Set the advertisement data. More...
 
void addData (const std::string &data)
 Add data to the payload to be advertised. More...
 
void addData (const uint8_t *data, size_t length)
 Add data to the payload to be advertised. More...
 
void addTxPower ()
 Adds Tx power level to the advertisement data.
 
void setPreferredParams (uint16_t min, uint16_t max)
 Set the preferred connection interval parameters. More...
 
void setLegacyAdvertising (bool val)
 Sets wether the advertisement should use legacy (BLE 4.0, 31 bytes max) advertising. More...
 
void setConnectable (bool val)
 Sets wether this advertisement should advertise as a connectable device. More...
 
void setScannable (bool val)
 Sets wether the advertisement has scan response data available. More...
 
void setMinInterval (uint32_t mininterval)
 Set the minimum advertising interval. More...
 
void setMaxInterval (uint32_t maxinterval)
 Set the maximum advertising interval. More...
 
void setPrimaryPhy (uint8_t phy)
 Set the primary advertising PHY to use. More...
 
void setSecondaryPhy (uint8_t phy)
 Set the secondary advertising PHY to use. More...
 
void setScanFilter (bool scanRequestWhitelistOnly, bool connectWhitelistOnly)
 Set the filtering for the scan filter. More...
 
void setDirectedPeer (const NimBLEAddress &addr)
 Sets the peer to directly advertise to. More...
 
void setDirected (bool val, bool high_duty=true)
 Enable or disable direct advertisements to the peer set with NimBLEExtAdvertisement::setDirectedPeer More...
 
void setAnonymous (bool val)
 Sets whether the advertisement should be anonymous. More...
 
void setPrimaryChannels (bool ch37, bool ch38, bool ch39)
 Sets The primary channels to advertise on. More...
 
void setTxPower (int8_t dbm)
 Sets the transmission power level for this advertisement. More...
 
void setAddress (const NimBLEAddress &addr)
 Set the address to use for this advertisement. More...
 
void enableScanRequestCallback (bool enable)
 Sets whether the scan response request callback should be called. More...
 
void clearData ()
 Clears the data stored in this instance, does not change settings. More...
 
size_t getDataSize ()
 Get the size of the current data.
 

Detailed Description

Extended advertisement data.

Constructor & Destructor Documentation

◆ NimBLEExtAdvertisement()

NimBLEExtAdvertisement::NimBLEExtAdvertisement ( uint8_t  priPhy = BLE_HCI_LE_PHY_1M,
uint8_t  secPhy = BLE_HCI_LE_PHY_1M 
)

Construct a BLE extended advertisement.

Parameters
[in]priPhyThe primary Phy to advertise on, can be one of:
  • BLE_HCI_LE_PHY_1M
  • BLE_HCI_LE_PHY_CODED
[in]secPhyThe secondary Phy to advertise on, can be one of:
  • BLE_HCI_LE_PHY_1M
  • BLE_HCI_LE_PHY_2M
  • BLE_HCI_LE_PHY_CODED

Member Function Documentation

◆ addData() [1/2]

void NimBLEExtAdvertisement::addData ( const std::string &  data)

Add data to the payload to be advertised.

Parameters
[in]dataThe data to be added to the payload.

◆ addData() [2/2]

void NimBLEExtAdvertisement::addData ( const uint8_t *  data,
size_t  length 
)

Add data to the payload to be advertised.

Parameters
[in]dataThe data to be added to the payload.
[in]lengthThe size of data to be added to the payload.

◆ clearData()

void NimBLEExtAdvertisement::clearData ( )

Clears the data stored in this instance, does not change settings.

This will clear all data but preserves advertising parameter settings.

◆ enableScanRequestCallback()

void NimBLEExtAdvertisement::enableScanRequestCallback ( bool  enable)

Sets whether the scan response request callback should be called.

Parameters
[in]enableIf true the scan response request callback will be called for this advertisement.

◆ setAddress()

void NimBLEExtAdvertisement::setAddress ( const NimBLEAddress addr)

Set the address to use for this advertisement.

Parameters
[in]addrThe address to use.

◆ setAnonymous()

void NimBLEExtAdvertisement::setAnonymous ( bool  val)

Sets whether the advertisement should be anonymous.

Parameters
[in]valSet to true to enable anonymous advertising.

Anonymous advertising omits the device's address from the advertisement.

◆ setAppearance()

void NimBLEExtAdvertisement::setAppearance ( uint16_t  appearance)

Set the appearance.

Parameters
[in]appearanceThe appearance code value.

See also: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.gap.appearance.xml

◆ setCompleteServices()

void NimBLEExtAdvertisement::setCompleteServices ( const NimBLEUUID uuid)

Set a single service to advertise as a complete list of services.

Parameters
[in]uuidThe service to advertise.

◆ setCompleteServices16()

void NimBLEExtAdvertisement::setCompleteServices16 ( const std::vector< NimBLEUUID > &  v_uuid)

Set the complete list of 16 bit services to advertise.

Parameters
[in]v_uuidA vector of 16 bit UUID's to advertise.

◆ setCompleteServices32()

void NimBLEExtAdvertisement::setCompleteServices32 ( const std::vector< NimBLEUUID > &  v_uuid)

Set the complete list of 32 bit services to advertise.

Parameters
[in]v_uuidA vector of 32 bit UUID's to advertise.

◆ setConnectable()

void NimBLEExtAdvertisement::setConnectable ( bool  val)

Sets wether this advertisement should advertise as a connectable device.

Parameters
[in]valTrue = connectable.

◆ setData()

void NimBLEExtAdvertisement::setData ( const uint8_t *  data,
size_t  length 
)

Set the advertisement data.

Parameters
[in]dataThe data to be set as the payload.
[in]lengthThe size of data.

This will completely replace any data that was previously set.

◆ setDirected()

void NimBLEExtAdvertisement::setDirected ( bool  val,
bool  high_duty = true 
)

Enable or disable direct advertisements to the peer set with NimBLEExtAdvertisement::setDirectedPeer

Parameters
[in]valtrue = send directed advertisements to peer.
[in]high_dutytrue = use fast advertising rate, default - true.

◆ setDirectedPeer()

void NimBLEExtAdvertisement::setDirectedPeer ( const NimBLEAddress addr)

Sets the peer to directly advertise to.

Parameters
[in]addrThe address of the peer to direct the advertisements.

◆ setFlags()

void NimBLEExtAdvertisement::setFlags ( uint8_t  flag)

Set the advertisement flags.

Parameters
[in]flagThe flags to be set in the advertisement.
  • BLE_HS_ADV_F_DISC_LTD
  • BLE_HS_ADV_F_DISC_GEN
  • BLE_HS_ADV_F_BREDR_UNSUP - must always use with NimBLE

◆ setLegacyAdvertising()

void NimBLEExtAdvertisement::setLegacyAdvertising ( bool  val)

Sets wether the advertisement should use legacy (BLE 4.0, 31 bytes max) advertising.

Parameters
[in]valtrue = using legacy advertising.

◆ setManufacturerData()

void NimBLEExtAdvertisement::setManufacturerData ( const std::string &  data)

Set manufacturer specific data.

Parameters
[in]dataThe manufacturer data to advertise.

◆ setMaxInterval()

void NimBLEExtAdvertisement::setMaxInterval ( uint32_t  maxinterval)

Set the maximum advertising interval.

Parameters
[in]maxintervalMaximum value for advertising interval in 0.625ms units, 0 = use default.

◆ setMinInterval()

void NimBLEExtAdvertisement::setMinInterval ( uint32_t  mininterval)

Set the minimum advertising interval.

Parameters
[in]minintervalMinimum value for advertising interval in 0.625ms units, 0 = use default.

◆ setName()

void NimBLEExtAdvertisement::setName ( const std::string &  name)

Set the complete name of this device.

Parameters
[in]nameThe name to advertise.

◆ setPartialServices()

void NimBLEExtAdvertisement::setPartialServices ( const NimBLEUUID uuid)

Set a single service to advertise as a partial list of services.

Parameters
[in]uuidThe service to advertise.

◆ setPartialServices16()

void NimBLEExtAdvertisement::setPartialServices16 ( const std::vector< NimBLEUUID > &  v_uuid)

Set the partial list of services to advertise.

Parameters
[in]v_uuidA vector of 16 bit UUID's to advertise.

◆ setPartialServices32()

void NimBLEExtAdvertisement::setPartialServices32 ( const std::vector< NimBLEUUID > &  v_uuid)

Set the partial list of services to advertise.

Parameters
[in]v_uuidA vector of 32 bit UUID's to advertise.

◆ setPreferredParams()

void NimBLEExtAdvertisement::setPreferredParams ( uint16_t  min,
uint16_t  max 
)

Set the preferred connection interval parameters.

Parameters
[in]minThe minimum interval desired.
[in]maxThe maximum interval desired.

◆ setPrimaryChannels()

void NimBLEExtAdvertisement::setPrimaryChannels ( bool  ch37,
bool  ch38,
bool  ch39 
)

Sets The primary channels to advertise on.

Parameters
[in]ch37Advertise on channel 37.
[in]ch38Advertise on channel 38.
[in]ch39Advertise on channel 39.

This will set a bitmask using the input parameters to allow different
combinations. If all inputs are false then all 3 channels will be used.

◆ setPrimaryPhy()

void NimBLEExtAdvertisement::setPrimaryPhy ( uint8_t  phy)

Set the primary advertising PHY to use.

Parameters
[in]phyCan be one of following constants:
  • BLE_HCI_LE_PHY_1M
  • BLE_HCI_LE_PHY_CODED

◆ setScanFilter()

void NimBLEExtAdvertisement::setScanFilter ( bool  scanRequestWhitelistOnly,
bool  connectWhitelistOnly 
)

Set the filtering for the scan filter.

Parameters
[in]scanRequestWhitelistOnlyIf true, only allow scan requests from those on the white list.
[in]connectWhitelistOnlyIf true, only allow connections from those on the white list.

◆ setScannable()

void NimBLEExtAdvertisement::setScannable ( bool  val)

Sets wether the advertisement has scan response data available.

Parameters
[in]valtrue = scan response is available.

◆ setSecondaryPhy()

void NimBLEExtAdvertisement::setSecondaryPhy ( uint8_t  phy)

Set the secondary advertising PHY to use.

Parameters
[in]phyCan be one of following constants:
  • BLE_HCI_LE_PHY_1M
  • BLE_HCI_LE_PHY_2M
  • BLE_HCI_LE_PHY_CODED

◆ setServiceData()

void NimBLEExtAdvertisement::setServiceData ( const NimBLEUUID uuid,
const std::string &  data 
)

Set the service data (UUID + data)

Parameters
[in]uuidThe UUID to set with the service data.
[in]dataThe data to be associated with the service data advertised.

◆ setShortName()

void NimBLEExtAdvertisement::setShortName ( const std::string &  name)

Set the short name.

Parameters
[in]nameThe short name of the device.

◆ setTxPower()

void NimBLEExtAdvertisement::setTxPower ( int8_t  dbm)

Sets the transmission power level for this advertisement.

Parameters
[in]dbmthe transmission power to use in dbm.

The allowable value range depends on device hardware.
The ESP32C3 and ESP32S3 have a range of -27 to +18.

◆ setURI()

void NimBLEExtAdvertisement::setURI ( const std::string &  uri)

Set the URI to advertise.

Parameters
[in]uriThe uri to advertise.