Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
BLE Class Reference
[Ble]
Abstract away BLE-capable radio transceivers or SOCs. More...
#include <BLE.h>
Data Structures | |
| struct | InitializationCompleteCallbackContext |
| Initialization complete event. More... | |
| struct | OnEventsToProcessCallbackContext |
| Events to process event. More... | |
Public Types | |
| typedef unsigned | InstanceID_t |
| Opaque type used to store the ID of a BLE instance. | |
| typedef FunctionPointerWithContext < OnEventsToProcessCallbackContext * > | OnEventsToProcessCallback_t |
| Events to process event handler. | |
| typedef void(* | InitializationCompleteCallback_t )(InitializationCompleteCallbackContext *context) |
| Initialization complete event handler. | |
Public Member Functions | |
| InstanceID_t | getInstanceID (void) const |
| Fetch the ID of a BLE instance. | |
| void | onEventsToProcess (const OnEventsToProcessCallback_t &on_event_cb) |
| Register a callback called when the BLE stack has pending work. | |
| void | processEvents () |
| Process ALL pending events living in the BLE stack and return once all events have been consumed. | |
| ble_error_t | init (InitializationCompleteCallback_t completion_cb=NULL) |
| Initialize the BLE controller/stack. | |
| template<typename T > | |
| ble_error_t | init (T *object, void(T::*completion_cb)(InitializationCompleteCallbackContext *context)) |
| Initialize the BLE controller/stack. | |
| bool | hasInitialized (void) const |
| Indicate if the BLE instance has been initialized. | |
| ble_error_t | shutdown (void) |
| Shut down the underlying stack, and reset state of this BLE instance. | |
| const char * | getVersion (void) |
| This call allows the application to get the BLE stack version information. | |
| Gap & | gap () |
| Accessor to Gap. | |
| const Gap & | gap () const |
| A const alternative to gap(). | |
| GattServer & | gattServer () |
| Accessor to GattServer. | |
| const GattServer & | gattServer () const |
| A const alternative to gattServer(). | |
| GattClient & | gattClient () |
| Accessors to GattClient. | |
| const GattClient & | gattClient () const |
| A const alternative to gattClient(). | |
| SecurityManager & | securityManager () |
| Accessors to SecurityManager. | |
| const SecurityManager & | securityManager () const |
| A const alternative to securityManager(). | |
| MBED_DEPRECATED ("Use BLE::Instance() instead of BLE constructor.") BLE(InstanceID_t instanceID | |
| Constructor for a handle to a BLE instance (the BLE stack). | |
| MBED_DEPRECATED ("Use BLE::processEvents() and BLE::onEventsToProcess().") void waitForEvent(void) | |
| Yield control to the BLE stack or to other tasks waiting for events. | |
| MBED_DEPRECATED("Use ble.gap().setAdvertisingType(...)") void setAdvertisingType(GapAdvertisingParams | MBED_DEPRECATED ("Use ble.gap().setAdvertisingInterval(...)") void setAdvertisingInterval(uint16_t interval) |
| Set the GAP advertising mode to use for this device. | |
| MBED_DEPRECATED ("Use ble.gap().getMinAdvertisingInterval(...)") uint16_t getMinAdvertisingInterval(void) const | |
| Get the minimum advertising interval in milliseconds, which can be used for connectable advertising types. | |
| MBED_DEPRECATED ("Use ble.gap().getMinNonConnectableAdvertisingInterval(...)") uint16_t getMinNonConnectableAdvertisingInterval(void) const | |
| Get the minimum advertising interval in milliseconds, which can be used for nonconnectable advertising type. | |
| MBED_DEPRECATED ("Use ble.gap().getMaxAdvertisingInterval(...)") uint16_t getMaxAdvertisingInterval(void) const | |
| Get the maximum advertising interval in milliseconds. | |
| MBED_DEPRECATED ("Use ble.gap().setAdvertisingTimeout(...)") void setAdvertisingTimeout(uint16_t timeout) | |
| Set the advertising duration. | |
| MBED_DEPRECATED ("Use ble.gap().setAdvertisingParams(...)") void setAdvertisingParams(const GapAdvertisingParams &advParams) | |
| Set up a particular, user-constructed set of advertisement parameters for the underlying stack. | |
| MBED_DEPRECATED ("Use ble.gap().getAdvertisingParams(...)") const GapAdvertisingParams &getAdvertisingParams(void) const | |
| Get the current advertising parameters. | |
| MBED_DEPRECATED ("Use ble.gap().accumulateAdvertisingPayload(flags)") ble_error_t accumulateAdvertisingPayload(uint8_t flags) | |
| Accumulate an AD structure in the advertising payload. | |
| MBED_DEPRECATED("Use ble.gap().accumulateAdvertisingPayload(appearance)") ble_error_t accumulateAdvertisingPayload(GapAdvertisingData | MBED_DEPRECATED ("Use ble.gap().accumulateAdvertisingPayloadTxPower(...)") ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power) |
| Accumulate an AD structure in the advertising payload. | |
| MBED_DEPRECATED("Use ble.gap().accumulateAdvertisingPayload(...)") ble_error_t accumulateAdvertisingPayload(GapAdvertisingData | MBED_DEPRECATED ("Use ble.gap().setAdvertisingData(...)") ble_error_t setAdvertisingData(const GapAdvertisingData &advData) |
| Accumulate a variable length byte-stream as an AD structure in the advertising payload. | |
| MBED_DEPRECATED ("Use ble.gap().getAdvertisingData(...)") const GapAdvertisingData &getAdvertisingData(void) const | |
| Get a reference to the current advertising payload. | |
| MBED_DEPRECATED ("Use ble.gap().clearAdvertisingPayload(...)") void clearAdvertisingPayload(void) | |
| Reset any advertising payload prepared from prior calls to accumulateAdvertisingPayload(). | |
| MBED_DEPRECATED ("Use ble.gap().setAdvertisingPayload(...)") ble_error_t setAdvertisingPayload(void) | |
| Dynamically reset the accumulated advertising payload and scanResponse. | |
| MBED_DEPRECATED("Use ble.gap().accumulateScanResponse(...)") ble_error_t accumulateScanResponse(GapAdvertisingData | MBED_DEPRECATED ("Use ble.gap().clearScanResponse(...)") void clearScanResponse(void) |
| Accumulate a variable length byte-stream as an AD structure in the scanResponse payload. | |
| MBED_DEPRECATED ("Use ble.gap().startAdvertising(...)") ble_error_t startAdvertising(void) | |
| Start advertising. | |
| MBED_DEPRECATED ("Use ble.gap().stopAdvertising(...)") ble_error_t stopAdvertising(void) | |
| Stop advertising. | |
| MBED_DEPRECATED ("Use ble.gap().setScanParams(...)") ble_error_t setScanParams(uint16_t interval | |
| Set up parameters for GAP scanning (observer mode). | |
| MBED_DEPRECATED ("Use ble.gap().setScanInterval(...)") ble_error_t setScanInterval(uint16_t interval) | |
| Set up the scanInterval parameter for GAP scanning (observer mode). | |
| MBED_DEPRECATED ("Use ble.gap().setScanWindow(...)") ble_error_t setScanWindow(uint16_t window) | |
| Set up the scanWindow parameter for GAP scanning (observer mode). | |
| MBED_DEPRECATED ("Use ble.gap().setScanTimeout(...)") ble_error_t setScanTimeout(uint16_t timeout) | |
| Set up parameters for GAP scanning (observer mode). | |
| MBED_DEPRECATED ("Use ble.gap().setActiveScan(...)") void setActiveScan(bool activeScanning) | |
| Set up parameters for GAP scanning (observer mode). | |
| MBED_DEPRECATED ("Use ble.gap().stopScan()") ble_error_t stopScan(void) | |
| Stop scanning. | |
| MBED_DEPRECATED ("Use ble.gap().setPreferredConnectionParams(...)") ble_error_t setPreferredConnectionParams(const Gap | |
| Set the GAP peripheral's preferred connection parameters. | |
| MBED_DEPRECATED("Use ble.gap().updateConnectionParams(...)") ble_error_t updateConnectionParams(Gap | MBED_DEPRECATED ("Use ble.gap().setDeviceName(...)") ble_error_t setDeviceName(const uint8_t *deviceName) |
| Update connection parameters while in the peripheral role. | |
| MBED_DEPRECATED ("Use ble.gap().getDeviceName(...)") ble_error_t getDeviceName(uint8_t *deviceName | |
| Get the value of the device name characteristic in the Gap service. | |
| MBED_DEPRECATED ("Use ble.gap().setAppearance(...)") ble_error_t setAppearance(GapAdvertisingData | |
| Set the appearance characteristic in the Gap service. | |
| MBED_DEPRECATED ("Use ble.gap().getAppearance(...)") ble_error_t getAppearance(GapAdvertisingData | |
| Get the appearance characteristic in the Gap service. | |
| MBED_DEPRECATED ("Use ble.gap().setTxPower(...)") ble_error_t setTxPower(int8_t txPower) | |
| Set the radio's transmit power. | |
| MBED_DEPRECATED ("Use ble.gap().getPermittedTxPowerValues(...)") void getPermittedTxPowerValues(const int8_t **valueArrayPP | |
| Query the underlying stack for permitted arguments for setTxPower(). | |
| MBED_DEPRECATED ("Use ble.gattServer().addService(...)") ble_error_t addService(GattService &service) | |
| Add a service declaration to the local server ATT table. | |
| MBED_DEPRECATED ("Use ble.gattServer().read(...)") ble_error_t readCharacteristicValue(GattAttribute | |
| Read the value of a characteristic from the local GattServer. | |
| MBED_DEPRECATED ("Use ble.gattServer().read(...)") ble_error_t readCharacteristicValue(Gap | |
| Read the value of a characteristic from the local GattServer. | |
| MBED_DEPRECATED ("Use ble.gattServer().write(...)") ble_error_t updateCharacteristicValue(GattAttribute | |
| Update the value of a characteristic on the local GattServer. | |
| MBED_DEPRECATED ("Use ble.gattServer().write(...)") ble_error_t updateCharacteristicValue(Gap | |
| Update the value of a characteristic on the local GattServer. | |
| MBED_DEPRECATED ("Use ble.securityManager().init(...)") ble_error_t initializeSecurity(bool enableBonding | |
| Enable the BLE stack's Security Manager. | |
| MBED_DEPRECATED ("ble.gap().onRadioNotification(...)") void onRadioNotification(void(*callback)(bool)) | |
| Radio Notification is a feature that enables ACTIVE and INACTIVE (nACTIVE) signals from the stack. | |
| MBED_DEPRECATED ("ble.gattServer().onDataSent(...)") void onDataSent(void(*callback)(unsigned count)) | |
| Add a callback for the GATT event DATA_SENT (which is triggered when updates are sent out by GATT in the form of notifications). | |
| template<typename T > | |
| MBED_DEPRECATED ("ble.gattServer().onDataSent(...)") void onDataSent(T *objPtr | |
| The same as onDataSent() but allows an object reference and member function to be added to the chain of callbacks. | |
| MBED_DEPRECATED ("ble.gattServer().onDataWritten(...)") void onDataWritten(void(*callback)(const GattWriteCallbackParams *eventDataP)) | |
| Set up a callback for when an attribute has its value updated by or at the connected peer. | |
| template<typename T > | |
| MBED_DEPRECATED ("ble.gattServer().onDataWritten(...)") void onDataWritten(T *objPtr | |
| The same as onDataWritten() but allows an object reference and member function to be added to the chain of callbacks. | |
| MBED_DEPRECATED ("ble.gattServer().onDataRead(...)") ble_error_t onDataRead(void(*callback)(const GattReadCallbackParams *eventDataP)) | |
| Set up a callback to be invoked on the peripheral when an attribute is being read by a remote client. | |
| template<typename T > | |
| MBED_DEPRECATED ("ble.gattServer().onDataRead(...)") ble_error_t onDataRead(T *objPtr | |
| The same as onDataRead() but allows an object reference and member function to be added to the chain of callbacks. | |
| MBED_DEPRECATED ("ble.gattServer().onUpdatesEnabled(...)") void onUpdatesEnabled(GattServer | |
| Set up a callback for when notifications or indications are enabled for a characteristic on the local GattServer. | |
| MBED_DEPRECATED ("ble.gattServer().onUpdatesDisabled(...)") void onUpdatesDisabled(GattServer | |
| Set up a callback for when notifications or indications are disabled for a characteristic on the local GattServer. | |
| MBED_DEPRECATED ("ble.gattServer().onConfirmationReceived(...)") void onConfirmationReceived(GattServer | |
| Set up a callback for when the GATT server receives a response for an indication event sent previously. | |
| MBED_DEPRECATED ("ble.securityManager().onSecuritySetupInitiated(callback)") void onSecuritySetupInitiated(SecurityManager | |
| Set up a callback for when the security setup procedure (key generation and exchange) for a link has started. | |
| MBED_DEPRECATED ("ble.securityManager().onSecuritySetupCompleted(callback)") void onSecuritySetupCompleted(SecurityManager | |
| Set up a callback for when the security setup procedure (key generation and exchange) for a link has completed. | |
| MBED_DEPRECATED ("ble.securityManager().onLinkSecured(callback)") void onLinkSecured(SecurityManager | |
| Set up a callback for when a link with the peer is secured. | |
| MBED_DEPRECATED ("ble.securityManager().onSecurityContextStored(callback)") void onSecurityContextStored(SecurityManager | |
| Set up a callback for successful bonding, meaning that link-specific security context is stored persistently for a peer device. | |
| MBED_DEPRECATED ("ble.securityManager().onPasskeyDisplay(callback)") void onPasskeyDisplay(SecurityManager | |
| Set up a callback for when the passkey needs to be displayed on a peripheral with DISPLAY capability. | |
Static Public Member Functions | |
| static BLE & | Instance (InstanceID_t id=DEFAULT_INSTANCE) |
| Get a reference to the BLE singleton corresponding to a given interface. | |
| static const char * | errorToString (ble_error_t error) |
| Translate error code into a printable string. | |
Data Fields | |
| MBED_DEPRECATED("Use ble.gap().startScan(callback)") ble_error_t startScan(void(*callback)(const Gap | MBED_DEPRECATED ("Use ble.gap().startScan(object, callback)") ble_error_t startScan(T *object |
| Start scanning (Observer Procedure) based on the parameters currently in effect. | |
Static Public Attributes | |
| static const InstanceID_t | DEFAULT_INSTANCE = 0 |
| The value of the BLE::InstanceID_t for the default BLE instance. | |
| static const InstanceID_t | NUM_INSTANCES = 1 |
| The number of permitted BLE instances for the application. | |
Friends | |
| class | BLEInstanceBase |
Detailed Description
Abstract away BLE-capable radio transceivers or SOCs.
Instances of this class have three responsibilities:
- Initialize the inner BLE subsystem.
- Signal user code that BLE events are available and an API to process them.
- Manage access to the instances abstracting each BLE layer: + GAP: Handle advertising and scan, as well as connection and disconnection. + GATTServer: API to construct and manage a GATT server, which connected peers can access. + GATTClient: API to interact with a peer GATT server. + SecurityManager: API to manage security.
The user should not create BLE instances directly but rather access to the singleton(s) holding the BLE interfaces present in the system by using the static function Instance().
#include "ble/BLE.h" BLE& ble_interface = BLE::Instance();
Next, the signal handling/process mechanism should be set up. By design, Mbed BLE does not impose to the user an event handling/processing mechanism; however, it exposes APIs, which allows an application to compose its own:
- onEventsToProcess(), which registers a callback that the BLE subsystem will call when there is an event ready to be processed.
- processEvents(), which processes all the events present in the BLE subsystem.
It is common to bind BLE event mechanism with Mbed EventQueue:
#include <events/mbed_events.h> #include "ble/BLE.h" // declare the event queue, which the whole application will share. static EventQueue event_queue(4 * EVENTS_EVENT_SIZE); // Function invoked when there is a BLE event available. // Event processing is put into the event queue. void schedule_ble_processing(BLE::OnEventsToProcessCallbackContext* context) { event_queue.call(callback(&(context->ble), &BLE::processEvents)); } int main() { BLE &ble_interface = BLE::Instance(); // Bind event signaling to schedule_ble_processing ble_interface.onEventsToProcess(schedule_ble_processing); // Launch BLE initialisation // Dispatch events in the event queue event_queue.dispatch_forever(); return 0; }
Once the event processing mechanism is in place, the Bluetooth subsystem can be initialized with the init() function. That function accepts in input a callback, which will be invoked once the initialization process has finished.
void on_ble_init_complete(BLE::InitializationCompleteCallbackContext *context) { BLE& ble_interface = context->ble; ble_error_t initialization_error = context->error; if (initialization_error) { // handle error return; } // The BLE interface can be accessed now. } int main() { BLE &ble_interface = BLE::Instance(); ble_interface.onEventsToProcess(schedule_ble_processing); // Initialize the BLE interface ble_interface.init(on_ble_init_complete); event_queue.dispatch_forever(); return 0; }
Definition at line 139 of file BLE.h.
Member Typedef Documentation
| typedef void(* InitializationCompleteCallback_t)(InitializationCompleteCallbackContext *context) |
| typedef unsigned InstanceID_t |
Member Function Documentation
| const char * errorToString | ( | ble_error_t | error ) | [static] |
| Gap & gap | ( | ) |
| const Gap & gap | ( | ) | const |
| GattClient & gattClient | ( | ) |
| const GattClient & gattClient | ( | ) | const |
A const alternative to gattClient().
- Returns:
- A const reference to a GattClient object associated to this BLE instance.
| const GattServer & gattServer | ( | ) | const |
A const alternative to gattServer().
- Returns:
- A const reference to a GattServer object associated to this BLE instance.
| GattServer & gattServer | ( | ) |
| InstanceID_t getInstanceID | ( | void | ) | const |
| const char * getVersion | ( | void | ) |
| bool hasInitialized | ( | void | ) | const |
| ble_error_t init | ( | InitializationCompleteCallback_t | completion_cb = NULL ) |
Initialize the BLE controller/stack.
init() hands control to the underlying BLE module to accomplish initialization. This initialization may tacitly depend on other hardware setup (such as clocks or power-modes) that happens early on during system startup. It may not be safe to call init() from a global static context where ordering is compiler-specific and can't be guaranteed - it is safe to call BLE::init() from within main().
- Parameters:
-
[in] completion_cb A callback for when initialization completes for a BLE instance. This is an optional parameter; if no callback is set up, the application can still determine the status of initialization using BLE::hasInitialized() (see below).
- Returns:
- BLE_ERROR_NONE if the initialization procedure started successfully.
- Note:
- If init() returns BLE_ERROR_NONE, the underlying stack must invoke the initialization completion callback at some point.
- Nearly all BLE APIs would return BLE_ERROR_INITIALIZATION_INCOMPLETE if used on an instance before the corresponding transport is initialized.
- There are two versions of init(). In addition to the function-pointer, init() can also take an <Object, member> pair as its callback target.
- Attention:
- This should be called before using anything else in the BLE API.
| ble_error_t init | ( | T * | object, |
| void(T::*)(InitializationCompleteCallbackContext *context) | completion_cb | ||
| ) |
Initialize the BLE controller/stack.
This is an alternate declaration for init(). This one takes an <Object, member> pair as its callback target.
- Parameters:
-
[in] object Object, which will be used to invoke the completion callback. [in] completion_cb Member function pointer, which will be invoked when initialization is complete.
| BLE & Instance | ( | InstanceID_t | id = DEFAULT_INSTANCE ) |
[static] |
Get a reference to the BLE singleton corresponding to a given interface.
There is a static array of BLE singletons.
- Note:
- Calling Instance() is preferred over constructing a BLE object directly because it returns references to singletons.
- Parameters:
-
[in] id BLE Instance ID to get.
- Returns:
- A reference to a single object.
- Precondition:
- id shall be less than NUM_INSTANCES.
| MBED_DEPRECATED | ( | "ble.gattServer().onDataSent(...)" | ) |
Add a callback for the GATT event DATA_SENT (which is triggered when updates are sent out by GATT in the form of notifications).
- Parameters:
-
[in] callback Event handler being registered.
- Note:
- It is possible to chain together multiple onDataSent callbacks (potentially from different modules of an application) to receive updates to characteristics.
- It is also possible to set up a callback into a member function of some object.
| MBED_DEPRECATED | ( | "ble.gap().onRadioNotification(...)" | ) |
Radio Notification is a feature that enables ACTIVE and INACTIVE (nACTIVE) signals from the stack.
These notify the application when the radio is in use. The signal is sent using software interrupt.
The ACTIVE signal is sent before the radio event starts. The nACTIVE signal is sent at the end of the radio event. These signals can be used by the application programmer to synchronize application logic with radio activity. For example, the ACTIVE signal can be used to shut off external devices to manage peak current drawn during periods when the radio is on, or to trigger sensor data collection for transmission in the radio event.
- Parameters:
-
callback The application handler to be invoked in response to a radio ACTIVE/INACTIVE event.
| MBED_DEPRECATED | ( | "ble.gattServer().onDataSent(...)" | ) |
The same as onDataSent() but allows an object reference and member function to be added to the chain of callbacks.
- Parameters:
-
[in] objPtr Pointer to the instance that is used to invoke the event handler. [in] memberPtr Event handler being registered. It is a member function.
| MBED_DEPRECATED | ( | "Use ble.gattServer().write(...)" | ) |
Update the value of a characteristic on the local GattServer.
A version of the above, with a connection handle parameter to allow updates for connection-specific multivalued attributes (such as the CCCDs).
- Parameters:
-
[in] connectionHandle Connection Handle. [in] attributeHandle Handle for the value attribute of the Characteristic. [in] value A pointer to a buffer holding the new value. [in] size Size of the new value (in bytes). [in] localOnly Should this update be kept on the local GattServer regardless of the state of the notify/indicate flag in the CCCD for this Characteristic? If set to true, no notification or indication is generated.
- Returns:
- BLE_ERROR_NONE if we have successfully set the value of the attribute.
| MBED_DEPRECATED | ( | "Use ble.gattServer().write(...)" | ) |
Update the value of a characteristic on the local GattServer.
- Parameters:
-
[in] attributeHandle Handle for the value attribute of the characteristic. [in] value A pointer to a buffer holding the new value. [in] size Size of the new value (in bytes). [in] localOnly Should this update be kept on the local GattServer regardless of the state of the notify/indicate flag in the CCCD for this characteristic? If set to true, no notification or indication is generated.
- Returns:
- BLE_ERROR_NONE if we have successfully set the value of the attribute.
| MBED_DEPRECATED | ( | "Use ble.gattServer().read(...)" | ) |
Read the value of a characteristic from the local GattServer.
- Parameters:
-
[in] connectionHandle Connection Handle. [in] attributeHandle Attribute handle for the value attribute of the characteristic. [out] buffer A buffer to hold the value being read. [in,out] lengthP Length of the buffer being supplied. If the attribute value is longer than the size of the supplied buffer, this variable will return the total attribute value length (excluding offset). The application may use this information to allocate a suitable buffer size.
- Returns:
- BLE_ERROR_NONE if a value was read successfully into the buffer.
- Note:
- This API is a version of the above, with an additional connection handle parameter to allow fetches for connection-specific multivalued attributes (such as the CCCDs).
| MBED_DEPRECATED | ( | "Use ble.gattServer().read(...)" | ) |
Read the value of a characteristic from the local GattServer.
- Parameters:
-
[in] attributeHandle Attribute handle for the value attribute of the characteristic. [out] buffer A buffer to hold the value being read. [in,out] lengthP Length of the buffer being supplied. If the attribute value is longer than the size of the supplied buffer, this variable will return the total attribute value length (excluding offset). The application may use this information to allocate a suitable buffer size.
- Returns:
- BLE_ERROR_NONE if a value was read successfully into the buffer.
| MBED_DEPRECATED | ( | "Use ble.gattServer().addService(...)" | ) |
Add a service declaration to the local server ATT table.
Also add the characteristics contained within.
- Parameters:
-
[in] service The service to be added; attribute handle of services, characteristic and characteristic descriptors are updated by the process.
- Returns:
- BLE_ERROR_NONE if the service was successfully added.
| MBED_DEPRECATED | ( | "Use ble.gap().getPermittedTxPowerValues(...)" | ) | const |
Query the underlying stack for permitted arguments for setTxPower().
- Parameters:
-
[out] valueArrayPP Out parameter to receive the immutable array of Tx values. [out] countP Out parameter to receive the array's size.
| MBED_DEPRECATED | ( | "ble.gattServer().onDataRead(...)" | ) |
The same as onDataRead() but allows an object reference and member function to be added to the chain of callbacks.
- Parameters:
-
[in] objPtr Pointer to the instance that is used to invoke the event handler ( memberPtr).[in] memberPtr Event handler being registered. It is a member function.
- Returns:
- BLE_ERROR_NOT_IMPLEMENTED if this functionality isn't available; else BLE_ERROR_NONE.
| MBED_DEPRECATED | ( | "Use ble.gap().clearAdvertisingPayload(...)" | ) |
Reset any advertising payload prepared from prior calls to accumulateAdvertisingPayload().
This automatically propagates the re- initialized advertising payload to the underlying stack.
| MBED_DEPRECATED | ( | "Use ble.gap().setAppearance(...)" | ) |
| MBED_DEPRECATED | ( | "Use ble.gap().getMinNonConnectableAdvertisingInterval(...)" | ) | const |
| MBED_DEPRECATED | ( | "Use ble.gap().getDeviceName(...)" | ) |
Get the value of the device name characteristic in the Gap service.
- Parameters:
-
[out] deviceName Pointer to an empty buffer where the UTF-8 *non NULL- terminated* string will be placed. Set this value to NULL to obtain the deviceName-length from the 'length' parameter. [in,out] lengthP (on input) Length of the buffer pointed to by deviceName; (on output) the complete device name length (without the null terminator).
- Returns:
- BLE_ERROR_NONE if the device name was fetched correctly from the underlying BLE stack.
- Note:
- If the device name is longer than the size of the supplied buffer, the length will return the complete device name length and not the number of bytes actually returned in deviceName. The application may use this information to retry with a suitable buffer size.
| MBED_DEPRECATED ("Use ble.gap().updateConnectionParams(...)") ble_error_t updateConnectionParams(Gap MBED_DEPRECATED | ( | "Use ble.gap().setDeviceName(...)" | ) | const |
Update connection parameters while in the peripheral role.
In the peripheral role, this will send the corresponding L2CAP request to the connected peer and wait for the central to perform the procedure.
- Parameters:
-
[in] handle Connection Handle [in] params Pointer to desired connection parameters. If NULL is provided on a peripheral role, the parameters in the PPCP characteristic of the GAP service will be used instead.
- Returns:
- BLE_ERROR_NONE if the connection parameters were updated correctly.
Set the device name characteristic in the Gap service.
- Parameters:
-
[in] deviceName The new value for the device-name. This is a UTF-8 encoded, NULL-terminated string.
- Returns:
- BLE_ERROR_NONE if the device name was set correctly.
| MBED_DEPRECATED | ( | "Use ble.gap().setPreferredConnectionParams(...)" | ) | const |
Set the GAP peripheral's preferred connection parameters.
These are the defaults that the peripheral would like to have in a connection. The choice of the connection parameters is eventually up to the central.
- Parameters:
-
[in] params The structure containing the desired parameters.
- Returns:
- BLE_ERROR_NONE if the preferred connection parameters were set correctly.
| MBED_DEPRECATED | ( | "Use ble.gap().stopScan()" | ) |
| MBED_DEPRECATED | ( | "Use ble.gap().setActiveScan(...)" | ) |
Set up parameters for GAP scanning (observer mode).
- Parameters:
-
[in] activeScanning Set to True if active-scanning is required. This is used to fetch the scan response from a peer if possible.
Once the scanning parameters have been configured, scanning can be enabled by using startScan().
| MBED_DEPRECATED | ( | "Use ble.gap().setAdvertisingPayload(...)" | ) |
Dynamically reset the accumulated advertising payload and scanResponse.
The application must clear and re- accumulate a new advertising payload (and scanResponse) before using this API.
- Returns:
- BLE_ERROR_NONE when the advertising payload is set successfully.
- Note:
- The new APIs in Gap update the underlying advertisement payload implicitly.
| MBED_DEPRECATED | ( | "Use ble.gap().setScanWindow(...)" | ) |
Set up the scanWindow parameter for GAP scanning (observer mode).
- Parameters:
-
[in] window Scan Window (in milliseconds) [valid values lie between 2.5ms and 10.24s].
- Returns:
- BLE_ERROR_NONE if the scan window was correctly set.
The scanning window divided by the interval determines the duty cycle for scanning. For example, if the interval is 100ms and the window is 10ms, then the controller will scan for 10 percent of the time. It is possible to have the interval and window set to the same value. In this case, scanning is continuous, with a change of scanning frequency once every interval.
Once the scanning parameters have been configured, scanning can be enabled by using startScan().
| MBED_DEPRECATED | ( | "Use ble.gap().setScanInterval(...)" | ) |
Set up the scanInterval parameter for GAP scanning (observer mode).
- Parameters:
-
[in] interval Scan interval (in milliseconds) [valid values lie between 2.5ms and 10.24s].
- Returns:
- BLE_ERROR_NONE if the scan interval was correctly set.
The scanning window divided by the interval determines the duty cycle for scanning. For example, if the interval is 100ms and the window is 10ms, then the controller will scan for 10 percent of the time. It is possible to have the interval and window set to the same value. In this case, scanning is continuous, with a change of scanning frequency once every interval.
Once the scanning parameters have been configured, scanning can be enabled by using startScan().
| MBED_DEPRECATED | ( | "Use ble.gap().setScanParams(...)" | ) |
Set up parameters for GAP scanning (observer mode).
- Parameters:
-
[in] interval Scan interval (in milliseconds) [valid values lie between 2.5ms and 10.24s]. [in] window Scan Window (in milliseconds) [valid values lie between 2.5ms and 10.24s]. [in] timeout Scan timeout (in seconds) between 0x0001 and 0xFFFF; 0x0000 disables timeout. [in] activeScanning Set to True if active-scanning is required. This is used to fetch the scan response from a peer if possible.
- Returns:
- BLE_ERROR_NONE if the scan parameters were correctly set.
The scanning window divided by the interval determines the duty cycle for scanning. For example, if the interval is 100ms and the window is 10ms, then the controller will scan for 10 percent of the time. It is possible to have the interval and window set to the same value. In this case, scanning is continuous, with a change of scanning frequency once every interval.
Once the scanning parameters have been configured, scanning can be enabled by using startScan().
- Note:
- The scan interval and window are recommendations to the BLE stack.
| MBED_DEPRECATED | ( | "ble.gattServer().onUpdatesEnabled(...)" | ) |
| MBED_DEPRECATED | ( | "ble.gattServer().onConfirmationReceived(...)" | ) |
| MBED_DEPRECATED ("Use ble.gap().accumulateScanResponse(...)") ble_error_t accumulateScanResponse(GapAdvertisingData MBED_DEPRECATED | ( | "Use ble.gap().clearScanResponse(...)" | ) |
Accumulate a variable length byte-stream as an AD structure in the scanResponse payload.
- Parameters:
-
[in] type The type that describes the variable length data. [in] data Data bytes. [in] len Data length.
- Returns:
- BLE_ERROR_NONE if the data was successfully added to the scan response payload.
Reset any scan response prepared from prior calls to accumulateScanResponse().
| MBED_DEPRECATED | ( | "ble.securityManager().onSecuritySetupCompleted(callback)" | ) |
Set up a callback for when the security setup procedure (key generation and exchange) for a link has completed.
This will be skipped for bonded devices. The callback is passed in the success/failure status of the security setup procedure.
- Parameters:
-
[in] callback Event handler being registered.
| MBED_DEPRECATED | ( | "Use ble.gap().startAdvertising(...)" | ) |
Start advertising.
- Returns:
- BLE_ERROR_NONE if the advertising procedure successfully started.
| MBED_DEPRECATED | ( | "Use ble.gap().getAdvertisingData(...)" | ) | const |
Get a reference to the current advertising payload.
- Returns:
- Read back advertising data. Useful for storing and restoring payload.
| MBED_DEPRECATED | ( | "ble.gattServer().onDataWritten(...)" | ) | const |
Set up a callback for when an attribute has its value updated by or at the connected peer.
For a peripheral, this callback is triggered when the local GATT server has an attribute updated by a write command from the peer. For a Central, this callback is triggered when a response is received for a write request.
- Parameters:
-
[in] callback The event handler being registered.
- Note:
- It is possible to chain together multiple onDataWritten callbacks (potentially from different modules of an application) to receive updates to characteristics. Many services, such as DFU and UART, add their own onDataWritten callbacks behind the scenes to trap interesting events.
- It is also possible to set up a callback into a member function of some object.
| MBED_DEPRECATED ("Use ble.gap().accumulateAdvertisingPayload(appearance)") ble_error_t accumulateAdvertisingPayload(GapAdvertisingData MBED_DEPRECATED | ( | "Use ble.gap().accumulateAdvertisingPayloadTxPower(...)" | ) |
Accumulate an AD structure in the advertising payload.
Please note that the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used as an additional 31 bytes if the advertising payload is too small.
- Parameters:
-
[in] app The appearance of the peripheral.
- Returns:
- BLE_ERROR_NONE if the data was successfully added to the advertising payload.
Accumulate an AD structure in the advertising payload. Please note that the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used as an additional 31 bytes if the advertising payload is too small.
- Parameters:
-
[in] power The max transmit power to be used by the controller. This is only a hint.
- Returns:
- BLE_ERROR_NONE if the data was successfully added to the advertising payload.
| MBED_DEPRECATED | ( | "Use ble.securityManager().init(...)" | ) |
Enable the BLE stack's Security Manager.
The Security Manager implements the cryptographic algorithms and protocol exchanges that allow two devices to securely exchange data and privately detect each other. Calling this API is a prerequisite for encryption and pairing (bonding).
- Parameters:
-
[in] enableBonding Allow for bonding. [in] requireMITM Require protection against man-in-the-middle attacks. [in] iocaps To specify the I/O capabilities of this peripheral, such as availability of a display or keyboard, to support out-of-band exchanges of security data. [in] passkey To specify a static passkey.
- Returns:
- BLE_ERROR_NONE on success.
| MBED_DEPRECATED | ( | "Use ble.gap().getAdvertisingParams(...)" | ) | const |
Get the current advertising parameters.
- Returns:
- Read back advertising parameters. Useful for storing and restoring parameters rapidly.
| MBED_DEPRECATED | ( | "Use ble.gap().setAdvertisingParams(...)" | ) | const |
Set up a particular, user-constructed set of advertisement parameters for the underlying stack.
It would be uncommon for this API to be used directly; there are other APIs to tweak advertisement parameters individually (see above).
- Parameters:
-
[in] advParams The new advertising parameters.
| MBED_DEPRECATED | ( | "Use ble.gap().setAdvertisingTimeout(...)" | ) |
Set the advertising duration.
A timeout event is genenerated once the advertising period expired.
- Parameters:
-
[in] timeout Advertising timeout (in seconds) between 0x1 and 0x3FFF (1 and 16383). Use 0 to disable the advertising timeout.
| MBED_DEPRECATED | ( | "Use ble.gap().setTxPower(...)" | ) |
Set the radio's transmit power.
- Parameters:
-
[in] txPower Radio transmit power in dBm.
- Returns:
- BLE_ERROR_NONE if the new radio's transmit power was set correctly.
| MBED_DEPRECATED | ( | "ble.securityManager().onSecurityContextStored(callback)" | ) |
| MBED_DEPRECATED | ( | "Use ble.gap().getMinAdvertisingInterval(...)" | ) | const |
| MBED_DEPRECATED ("Use ble.gap().setAdvertisingType(...)") void setAdvertisingType(GapAdvertisingParams MBED_DEPRECATED | ( | "Use ble.gap().setAdvertisingInterval(...)" | ) |
Set the GAP advertising mode to use for this device.
- Parameters:
-
[in] advType New type of advertising to use.
Set the advertising interval.
- Parameters:
-
[in] interval Advertising interval in units of milliseconds. Advertising is disabled if interval is 0. If interval is smaller than the minimum supported value, then the minimum supported value is used instead. This minimum value can be discovered using getMinAdvertisingInterval().
This field must be set to 0 if connectionMode is equal to ADV_CONNECTABLE_DIRECTED.
- Note:
- Decreasing this value allows central devices to detect a peripheral faster at the expense of more power being used by the radio due to the higher data transmit rate.
- Note:
- WARNING: This API previously used 0.625ms as the unit for its 'interval' argument. That required an explicit conversion from milliseconds using Gap::MSEC_TO_GAP_DURATION_UNITS(). This conversion is no longer required as the new units are milliseconds. Any application code depending on the old semantics needs to be updated accordingly.
| MBED_DEPRECATED | ( | "Use ble.gap().setScanTimeout(...)" | ) |
Set up parameters for GAP scanning (observer mode).
- Parameters:
-
[in] timeout Scan timeout (in seconds) between 0x0001 and 0xFFFF; 0x0000 disables timeout.
- Returns:
- BLE_ERROR_NONE if the scan timeout was correctly set.
The scanning window divided by the interval determines the duty cycle for scanning. For example, if the interval is 100ms and the window is 10ms, then the controller will scan for 10 percent of the time. It is possible to have the interval and window set to the same value. In this case, scanning is continuous, with a change of scanning frequency once every interval.
Once the scanning parameters have been configured, scanning can be enabled by using startScan().
- Note:
- The scan interval and window are recommendations to the BLE stack.
| MBED_DEPRECATED | ( | "ble.securityManager().onPasskeyDisplay(callback)" | ) |
Set up a callback for when the passkey needs to be displayed on a peripheral with DISPLAY capability.
This happens when security is configured to prevent man-in-the-middle attacks, and the peers need to exchange a passkey (or PIN) to authenticate the connection attempt.
- Parameters:
-
[in] callback Event handler being registered.
| MBED_DEPRECATED | ( | "Use ble.gap().stopAdvertising(...)" | ) |
Stop advertising.
- Returns:
- BLE_ERROR_NONE if the advertising procedure has been successfully stopped.
| MBED_DEPRECATED | ( | "Use BLE::Instance() instead of BLE constructor." | ) |
Constructor for a handle to a BLE instance (the BLE stack).
BLE handles are thin wrappers around a transport object (that is, ptr. to BLEInstanceBase).
- Parameters:
-
[in] instanceID BLE Instance ID to get.
It is better to create BLE objects as singletons accessed through the Instance() method. If multiple BLE handles are constructed for the same interface (using this constructor), they share the same underlying transport object.
| MBED_DEPRECATED | ( | "ble.gattServer().onDataWritten(...)" | ) |
The same as onDataWritten() but allows an object reference and member function to be added to the chain of callbacks.
- Parameters:
-
[in] objPtr Pointer to the instance that is used to invoke the event handler ( memberPtr).[in] memberPtr Event handler being registered. It is a member function.
| MBED_DEPRECATED ("Use ble.gap().accumulateAdvertisingPayload(...)") ble_error_t accumulateAdvertisingPayload(GapAdvertisingData MBED_DEPRECATED | ( | "Use ble.gap().setAdvertisingData(...)" | ) | const |
Accumulate a variable length byte-stream as an AD structure in the advertising payload.
Please note that the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used as an additional 31 bytes if the advertising payload is too small.
- Parameters:
-
type The type that describes the variable length data. data Data bytes. len Data length.
- Returns:
- BLE_ERROR_NONE if the advertisement payload was updated based on matching AD type; otherwise, an appropriate error.
Set up a particular, user-constructed advertisement payload for the underlying stack. It would be uncommon for this API to be used directly; there are other APIs to build an advertisement payload (see above).
- Parameters:
-
[in] advData Advertising data to set.
- Returns:
- BLE_ERROR_NONE if the advertising data was set successfully.
| MBED_DEPRECATED | ( | "Use ble.gap().accumulateAdvertisingPayload(flags)" | ) |
Accumulate an AD structure in the advertising payload.
Please note that the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used as an additional 31 bytes if the advertising payload is too small.
- Parameters:
-
[in] flags The flags to add. Please refer to GapAdvertisingData::Flags for valid flags. Multiple flags may be specified in combination.
- Returns:
- BLE_ERROR_NONE if the data was successfully added to the advertising payload.
| MBED_DEPRECATED | ( | "ble.securityManager().onSecuritySetupInitiated(callback)" | ) |
Set up a callback for when the security setup procedure (key generation and exchange) for a link has started.
This will be skipped for bonded devices. The callback is passed in parameters received from the peer's security request: bool allowBonding, bool requireMITM and SecurityIOCapabilities_t.
- Parameters:
-
[in] callback Event handler being registered.
| MBED_DEPRECATED | ( | "Use ble.gap().getAppearance(...)" | ) |
| MBED_DEPRECATED | ( | "Use BLE::processEvents() and BLE::onEventsToProcess()." | ) |
Yield control to the BLE stack or to other tasks waiting for events.
This is a sleep function that returns when there is an application-specific interrupt. This is not interchangeable with WFE() considering that the MCU might wake up several times to service the stack before returning control to the caller.
| MBED_DEPRECATED | ( | "ble.securityManager().onLinkSecured(callback)" | ) |
Set up a callback for when a link with the peer is secured.
For bonded devices, subsequent reconnections with a bonded peer will result only in this callback when the link is secured, and setup procedures will not occur unless the bonding information is either lost or deleted on either or both sides. The callback is passed in a SecurityManager::SecurityMode_t according to the level of security in effect for the secured link.
- Parameters:
-
[in] callback Event handler being registered.
| MBED_DEPRECATED | ( | "ble.gattServer().onUpdatesDisabled(...)" | ) |
| MBED_DEPRECATED | ( | "Use ble.gap().getMaxAdvertisingInterval(...)" | ) | const |
| MBED_DEPRECATED | ( | "ble.gattServer().onDataRead(...)" | ) | const |
Set up a callback to be invoked on the peripheral when an attribute is being read by a remote client.
- Note:
- This functionality may not be available on all underlying stacks. You could use GattCharacteristic::setReadAuthorizationCallback() as an alternative.
- It is possible to chain together multiple onDataRead callbacks (potentially from different modules of an application) to receive updates to characteristics. Services may add their own onDataRead callbacks behind the scenes to trap interesting events.
- It is also possible to set up a callback into a member function of some object.
- Parameters:
-
[in] callback Event handler being registered.
- Returns:
- BLE_ERROR_NOT_IMPLEMENTED if this functionality isn't available; else BLE_ERROR_NONE.
| void onEventsToProcess | ( | const OnEventsToProcessCallback_t & | on_event_cb ) |
| void processEvents | ( | ) |
Process ALL pending events living in the BLE stack and return once all events have been consumed.
- See also:
- onEventsToProcess()
| SecurityManager & securityManager | ( | ) |
| const SecurityManager & securityManager | ( | ) | const |
A const alternative to securityManager().
- Returns:
- A const reference to a SecurityManager object associated to this BLE instance.
| ble_error_t shutdown | ( | void | ) |
Shut down the underlying stack, and reset state of this BLE instance.
- Returns:
- BLE_ERROR_NONE if the instance was shut down without error or the appropriate error code.
- Attention:
- init() must be called afterward to reinstate services and GAP state. This API offers a way to repopulate the GATT database with new services and characteristics.
Field Documentation
const InstanceID_t DEFAULT_INSTANCE = 0 [static] |
The value of the BLE::InstanceID_t for the default BLE instance.
Start scanning (Observer Procedure) based on the parameters currently in effect.
Set up a callback for connection events.
Create a connection (GAP Link Establishment).
Set the BTLE MAC address and type.
- Parameters:
-
[in] callback The application-specific callback to be invoked upon receiving every advertisement report. This can be passed in as NULL, in which case scanning may not be enabled at all.
- Returns:
- BLE_ERROR_NONE if the device successfully started the scan procedure.
Start the scanning procedure.
Packets received during the scan procedure are forwarded to the scan packet handler passed as argument to this function.
- Parameters:
-
[in] object Instance used to invoke callbackMember.[in] memberCallback Advertisement packet event handler. Upon reception of an advertising packet, the packet is forwarded to callbackinvoked fromobject.
- Returns:
- BLE_ERROR_NONE if the device successfully started the scan procedure.
- Parameters:
-
[in] type Type of the address to set. [in] address Value of the address to set. It is ordered in little endian.
- Returns:
- BLE_ERROR_NONE on success.
Fetch the Bluetooth Low Energy MAC address and type.
- Parameters:
-
[out] typeP Type of the current address set. [out] address Value of the current address.
- Returns:
- BLE_ERROR_NONE on success.
- Parameters:
-
peerAddr 48-bit address, LSB format. peerAddrType Address type of the peer. connectionParams Connection parameters. scanParams Parameters to use while scanning for the peer.
- Returns:
- BLE_ERROR_NONE if connection establishment procedure is started successfully. The onConnection callback (if set) is invoked upon a connection event.
This call initiates the disconnection procedure, and its completion is communicated to the application with an invocation of the onDisconnection callback.
- Parameters:
-
[in] connectionHandle [in] reason The reason for disconnection; sent back to the peer.
- Returns:
- BLE_ERROR_NONE if the disconnection procedure successfully started.
This call initiates the disconnection procedure, and its completion is communicated to the application with an invocation of the onDisconnection callback.
- Parameters:
-
reason The reason for disconnection; sent back to the peer.
- Returns:
- BLE_ERROR_NONE if the disconnection procedure successfully started.
- Note:
- This version of disconnect() doesn't take a connection handle. It works reliably only for stacks that are limited to a single connection. Returns the current Gap state of the device using a bitmask that describes whether the device is advertising or connected.
- Returns:
- The current GAP state of the device.
Get the GAP peripheral's preferred connection parameters. These are the defaults that the peripheral would like to have in a connection. The choice of the connection parameters is eventually up to the central.
- Parameters:
-
[out] params The structure where the parameters will be stored. The caller owns memory for this.
- Returns:
- BLE_ERROR_NONE if the parameters were successfully filled into the given structure pointed to by params.
Refer to Gap::ConnectionEventCallback_t.
- Parameters:
-
[in] connectionCallback Event handler being registered.
Append to a chain of callbacks to be invoked upon GAP disconnection.
- Parameters:
-
[in] disconnectionCallback Event handler being registered.
The same as onDisconnection() but allows an object reference and member function to be added to the chain of callbacks.
- Parameters:
-
[in] tptr Instance used to invoke mptr. [in] mptr Event handler being registered.
static const InstanceID_t NUM_INSTANCES = 1 [static] |
Generated on Tue Jul 12 2022 13:55:28 by
1.7.2