NimBLE-Arduino 1.4.2
|
Perform and manage BLE advertising. More...
#include <NimBLEAdvertising.h>
Public Member Functions | |
NimBLEAdvertising () | |
Construct a default advertising object. | |
void | addServiceUUID (const NimBLEUUID &serviceUUID) |
Add a service uuid to exposed list of services. More... | |
void | addServiceUUID (const char *serviceUUID) |
Add a service uuid to exposed list of services. More... | |
void | removeServiceUUID (const NimBLEUUID &serviceUUID) |
Remove a service UUID from the advertisment. More... | |
bool | start (uint32_t duration=0, advCompleteCB_t advCompleteCB=nullptr, NimBLEAddress *dirAddr=nullptr) |
Start advertising. More... | |
void | removeServices () |
Remove all service UUIDs from the advertisment. | |
bool | stop () |
Stop advertising. More... | |
void | setAppearance (uint16_t appearance) |
Set the device appearance in the advertising data. More... | |
void | setName (const std::string &name) |
Set the advertised name of the device. More... | |
void | setManufacturerData (const std::string &data) |
Set the advertised manufacturer data. More... | |
void | setManufacturerData (const std::vector< uint8_t > &data) |
Set the advertised manufacturer data. More... | |
void | setURI (const std::string &uri) |
Set the advertised URI. More... | |
void | setServiceData (const NimBLEUUID &uuid, const std::string &data) |
Set the service data advertised for the UUID. More... | |
void | setAdvertisementType (uint8_t adv_type) |
Set the type of advertisment to use. More... | |
void | setMaxInterval (uint16_t maxinterval) |
Set the maximum advertising interval. More... | |
void | setMinInterval (uint16_t mininterval) |
Set the minimum advertising interval. More... | |
void | setAdvertisementData (NimBLEAdvertisementData &advertisementData) |
Set the advertisement data that is to be published in a regular advertisement. More... | |
void | setScanFilter (bool scanRequestWhitelistOnly, bool connectWhitelistOnly) |
Set the filtering for the scan filter. More... | |
void | setScanResponseData (NimBLEAdvertisementData &advertisementData) |
Set the advertisement data that is to be published in a scan response. More... | |
void | setScanResponse (bool) |
Set if scan response is available. More... | |
void | setMinPreferred (uint16_t) |
Set the advertised min connection interval preferred by this device. More... | |
void | setMaxPreferred (uint16_t) |
Set the advertised max connection interval preferred by this device. More... | |
void | addTxPower () |
Add the transmission power level to the advertisement packet. | |
void | reset () |
Stops the current advertising and resets the advertising data to the default values. | |
void | advCompleteCB () |
Handles the callback when advertising stops. | |
bool | isAdvertising () |
Check if currently advertising. More... | |
Perform and manage BLE advertising.
A BLE server will want to perform advertising in order to make itself known to BLE clients.
void NimBLEAdvertising::addServiceUUID | ( | const char * | serviceUUID | ) |
Add a service uuid to exposed list of services.
[in] | serviceUUID | The string representation of the service to expose. |
void 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::isAdvertising | ( | ) |
Check if currently advertising.
void NimBLEAdvertising::removeServiceUUID | ( | const NimBLEUUID & | serviceUUID | ) |
Remove a service UUID from the advertisment.
[in] | serviceUUID | The UUID of the service to remove. |
void NimBLEAdvertising::setAdvertisementData | ( | NimBLEAdvertisementData & | advertisementData | ) |
Set the advertisement data that is to be published in a regular advertisement.
[in] | advertisementData | The data to be advertised. |
The use of this function will replace any data set with addServiceUUID
or setAppearance. If you wish for these to be advertised you must include them
in the advertisementData parameter sent.
void NimBLEAdvertising::setAdvertisementType | ( | uint8_t | adv_type | ) |
Set the type of advertisment to use.
[in] | adv_type |
|
void NimBLEAdvertising::setAppearance | ( | uint16_t | appearance | ) |
Set the device appearance in the advertising data.
[in] | appearance | The appearance of the device in the advertising data. |
void NimBLEAdvertising::setManufacturerData | ( | const std::string & | data | ) |
Set the advertised manufacturer data.
[in] | data | The data to advertise. |
void NimBLEAdvertising::setManufacturerData | ( | const std::vector< uint8_t > & | data | ) |
Set the advertised manufacturer data.
[in] | data | The data to advertise. |
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::setMaxPreferred | ( | uint16_t | maxinterval | ) |
Set the advertised max connection interval preferred by this device.
[in] | maxinterval | the max interval value. Range = 0x0006 to 0x0C80. |
Values not within the range will cancel advertising of this data.
Consumes 6 bytes of advertising space (combined with min interval).
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. |
void NimBLEAdvertising::setMinPreferred | ( | uint16_t | mininterval | ) |
Set the advertised min connection interval preferred by this device.
[in] | mininterval | the max interval value. Range = 0x0006 to 0x0C80. |
Values not within the range will cancel advertising of this data.
Consumes 6 bytes of advertising space (combined with max interval).
void NimBLEAdvertising::setName | ( | const std::string & | name | ) |
Set the advertised name of the device.
[in] | name | The name to advertise. |
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. |
void NimBLEAdvertising::setScanResponse | ( | bool | set | ) |
Set if scan response is available.
[in] | set | true = scan response available. |
void NimBLEAdvertising::setScanResponseData | ( | NimBLEAdvertisementData & | advertisementData | ) |
Set the advertisement data that is to be published in a scan response.
[in] | advertisementData | The data to be advertised. |
Calling this without also using setAdvertisementData will have no effect.
When using custom scan response data you must also use custom advertisement data.
void 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. |
void NimBLEAdvertising::setURI | ( | const std::string & | uri | ) |
Set the advertised URI.
[in] | uri | The URI to advertise. |
bool NimBLEAdvertising::start | ( | uint32_t | duration = 0 , |
advCompleteCB_t | advCompleteCB = nullptr , |
||
NimBLEAddress * | dirAddr = nullptr |
||
) |
Start advertising.
[in] | duration | The duration, in seconds, to advertise, 0 == advertise forever. |
[in] | advCompleteCB | A pointer to a callback to be invoked when advertising ends. |
[in] | dirAddr | The address of a peer to directly advertise to. |
bool NimBLEAdvertising::stop | ( | ) |
Stop advertising.