NimBLE-Arduino 2.1.2
|
Perform and manage BLE advertising. More...
#include <NimBLEAdvertising.h>
Public Member Functions | |
NimBLEAdvertising () | |
Construct a default advertising object. | |
bool | start (uint32_t duration=0, const NimBLEAddress *dirAddr=nullptr) |
Start advertising. | |
void | setAdvertisingCompleteCallback (advCompleteCB_t callback) |
Set the callback to be invoked when advertising stops. | |
bool | stop () |
Stop advertising. | |
bool | setConnectableMode (uint8_t mode) |
Set the type of connectable mode to advertise. | |
bool | setDiscoverableMode (uint8_t mode) |
Set the discoverable mode to use. | |
bool | reset () |
Stops the current advertising and resets the advertising data to the default values. | |
bool | isAdvertising () |
Check if currently advertising. | |
void | setScanFilter (bool scanRequestWhitelistOnly, bool connectWhitelistOnly) |
Set the filtering for the scan filter. | |
void | enableScanResponse (bool enable) |
Enable scan response data. | |
void | setAdvertisingInterval (uint16_t interval) |
Set the advertising interval. | |
void | setMaxInterval (uint16_t maxInterval) |
Set the maximum advertising interval. | |
void | setMinInterval (uint16_t minInterval) |
Set the minimum advertising interval. | |
bool | setAdvertisementData (const NimBLEAdvertisementData &advertisementData) |
Set the advertisement data that is to be broadcast in a regular advertisement. | |
bool | setScanResponseData (const NimBLEAdvertisementData &advertisementData) |
Set the data that is to be provided in a scan response. | |
const NimBLEAdvertisementData & | getAdvertisementData () |
Get the current advertisement data. | |
const NimBLEAdvertisementData & | getScanData () |
Get the current scan response data. | |
void | clearData () |
Clear the advertisement and scan response data and set the flags to BLE_HS_ADV_F_DISC_GEN. | |
bool | refreshAdvertisingData () |
Refresh advertsing data dynamically without stop/start cycle. For instance allows refreshing manufacturer data dynamically. | |
bool | addServiceUUID (const NimBLEUUID &serviceUUID) |
Add a service uuid to exposed list of services. | |
bool | addServiceUUID (const char *serviceUUID) |
Add a service uuid to exposed list of services. | |
bool | removeServiceUUID (const NimBLEUUID &serviceUUID) |
Remove a service UUID from the advertisement. | |
bool | removeServiceUUID (const char *serviceUUID) |
Remove a service UUID from the advertisement. | |
bool | removeServices () |
Remove all service UUIDs from the advertisement. | |
bool | setAppearance (uint16_t appearance) |
Set the device appearance in the advertising data. | |
bool | setPreferredParams (uint16_t minInterval, uint16_t maxInterval) |
Set the preferred min and max connection intervals to advertise. | |
bool | addTxPower () |
Add the transmission power level to the advertisement packet. | |
bool | setName (const std::string &name) |
Set the advertised name of the device. | |
bool | setManufacturerData (const uint8_t *data, size_t length) |
Set the advertised manufacturer data. | |
bool | setManufacturerData (const std::string &data) |
Set the advertised manufacturer data. | |
bool | setManufacturerData (const std::vector< uint8_t > &data) |
Set the advertised manufacturer data. | |
bool | setURI (const std::string &uri) |
Set the advertised URI. | |
bool | setServiceData (const NimBLEUUID &uuid, const uint8_t *data, size_t length) |
Set the service data advertised for the UUID. | |
bool | setServiceData (const NimBLEUUID &uuid, const std::string &data) |
Set the service data advertised for the UUID. | |
bool | setServiceData (const NimBLEUUID &uuid, const std::vector< uint8_t > &data) |
Set the service data advertised for the UUID. | |
Perform and manage BLE advertising.
A BLE server will want to perform advertising in order to make itself known to BLE clients.
bool NimBLEAdvertising::addServiceUUID | ( | const char * | serviceUUID | ) |
Add a service uuid to exposed list of services.
[in] | serviceUUID | The string representation of the service to expose. |
bool NimBLEAdvertising::addServiceUUID | ( | const NimBLEUUID & | serviceUUID | ) |
Add a service uuid to exposed list of services.
[in] | serviceUUID | The UUID of the service to expose. |
bool NimBLEAdvertising::addTxPower | ( | ) |
Add the transmission power level to the advertisement packet.
void NimBLEAdvertising::enableScanResponse | ( | bool | enable | ) |
Enable scan response data.
[in] | enable | If true, scan response data will be available, false disabled, default = disabled. |
The scan response data is sent in response to a scan request from a peer device.
const NimBLEAdvertisementData & NimBLEAdvertising::getAdvertisementData | ( | ) |
Get the current advertisement data.
const NimBLEAdvertisementData & NimBLEAdvertising::getScanData | ( | ) |
Get the current scan response data.
bool NimBLEAdvertising::isAdvertising | ( | ) |
Check if currently advertising.
bool NimBLEAdvertising::refreshAdvertisingData | ( | ) |
Refresh advertsing data dynamically without stop/start cycle. For instance allows refreshing manufacturer data dynamically.
If scan response is enabled it will be refreshed as well.
bool NimBLEAdvertising::removeServices | ( | ) |
Remove all service UUIDs from the advertisement.
bool NimBLEAdvertising::removeServiceUUID | ( | const char * | serviceUUID | ) |
Remove a service UUID from the advertisement.
[in] | serviceUUID | The UUID of the service to remove. |
bool NimBLEAdvertising::removeServiceUUID | ( | const NimBLEUUID & | serviceUUID | ) |
Remove a service UUID from the advertisement.
[in] | serviceUUID | The UUID of the service to remove. |
bool NimBLEAdvertising::reset | ( | ) |
Stops the current advertising and resets the advertising data to the default values.
bool NimBLEAdvertising::setAdvertisementData | ( | const NimBLEAdvertisementData & | data | ) |
Set the advertisement data that is to be broadcast in a regular advertisement.
[in] | data | The data to be broadcast. |
void NimBLEAdvertising::setAdvertisingCompleteCallback | ( | advCompleteCB_t | callback | ) |
Set the callback to be invoked when advertising stops.
[in] | callback | The callback to be invoked when advertising stops. |
void NimBLEAdvertising::setAdvertisingInterval | ( | uint16_t | interval | ) |
Set the advertising interval.
[in] | interval | The advertising interval in 0.625ms units, 0 = use default. |
bool NimBLEAdvertising::setAppearance | ( | uint16_t | appearance | ) |
Set the device appearance in the advertising data.
[in] | appearance | The appearance of the device in the advertising data. If the appearance value is 0 then the appearance will not be in the advertisement. |
bool NimBLEAdvertising::setConnectableMode | ( | uint8_t | mode | ) |
Set the type of connectable mode to advertise.
[in] | mode | The connectable mode:
|
bool NimBLEAdvertising::setDiscoverableMode | ( | uint8_t | mode | ) |
Set the discoverable mode to use.
[in] | mode | The discoverable mode:
|
bool NimBLEAdvertising::setManufacturerData | ( | const std::string & | data | ) |
Set the advertised manufacturer data.
[in] | data | The data to advertise. |
bool NimBLEAdvertising::setManufacturerData | ( | const std::vector< uint8_t > & | data | ) |
Set the advertised manufacturer data.
[in] | data | The data to advertise. |
bool NimBLEAdvertising::setManufacturerData | ( | const uint8_t * | data, |
size_t | length | ||
) |
Set the advertised manufacturer data.
[in] | data | The data to advertise. |
[in] | length | The length of the data. |
void NimBLEAdvertising::setMaxInterval | ( | uint16_t | maxInterval | ) |
Set the maximum advertising interval.
[in] | maxInterval | Maximum value for advertising interval in 0.625ms units, 0 = use default. |
void NimBLEAdvertising::setMinInterval | ( | uint16_t | minInterval | ) |
Set the minimum advertising interval.
[in] | minInterval | Minimum value for advertising interval in 0.625ms units, 0 = use default. |
bool NimBLEAdvertising::setName | ( | const std::string & | name | ) |
Set the advertised name of the device.
[in] | name | The name to advertise. |
If scan response is enabled the name will be set in the scan response data.
bool NimBLEAdvertising::setPreferredParams | ( | uint16_t | minInterval, |
uint16_t | maxInterval | ||
) |
Set the preferred min and max connection intervals to advertise.
[in] | minInterval | The minimum preferred connection interval. |
[in] | maxInterval | The Maximum preferred connection interval. |
Range = 0x0006(7.5ms) to 0x0C80(4000ms), values not within the range will be limited to this range.
void NimBLEAdvertising::setScanFilter | ( | bool | scanRequestWhitelistOnly, |
bool | connectWhitelistOnly | ||
) |
Set the filtering for the scan filter.
[in] | scanRequestWhitelistOnly | If true, only allow scan requests from those on the white list. |
[in] | connectWhitelistOnly | If true, only allow connections from those on the white list. |
bool NimBLEAdvertising::setScanResponseData | ( | const NimBLEAdvertisementData & | data | ) |
Set the data that is to be provided in a scan response.
[in] | data | The data to be provided in the scan response |
The scan response data is sent in response to a scan request from a peer device. If this is set without setting the advertisement data when advertising starts this may be overwritten.
bool NimBLEAdvertising::setServiceData | ( | const NimBLEUUID & | uuid, |
const std::string & | data | ||
) |
Set the service data advertised for the UUID.
[in] | uuid | The UUID the service data belongs to. |
[in] | data | The data to advertise. |
bool NimBLEAdvertising::setServiceData | ( | const NimBLEUUID & | uuid, |
const std::vector< uint8_t > & | data | ||
) |
Set the service data advertised for the UUID.
[in] | uuid | The UUID the service data belongs to. |
[in] | data | The data to advertise. |
bool NimBLEAdvertising::setServiceData | ( | const NimBLEUUID & | uuid, |
const uint8_t * | data, | ||
size_t | length | ||
) |
Set the service data advertised for the UUID.
[in] | uuid | The UUID the service data belongs to. |
[in] | data | The data to advertise. |
[in] | length | The length of the data. |
bool NimBLEAdvertising::setURI | ( | const std::string & | uri | ) |
Set the advertised URI.
[in] | uri | The URI to advertise. |
bool NimBLEAdvertising::start | ( | uint32_t | duration = 0 , |
const NimBLEAddress * | dirAddr = nullptr |
||
) |
Start advertising.
[in] | duration | The duration, in milliseconds, to advertise, 0 == advertise forever. |
[in] | dirAddr | The address of a peer to directly advertise to. |
bool NimBLEAdvertising::stop | ( | ) |
Stop advertising.