Note: Some functions, variables or types have been deprecated. Please see the class reference linked below for details.
Bluetooth low energy (BLE) is a low power wireless technology standard for building personal area networks. Typical applications of BLE are health care, fitness trackers, beacons, smart home, security, entertainment, proximity sensors, industrial and automotive.
Arm Mbed BLE, also called
BLE_API, is the Bluetooth Low Energy software solution for Mbed. Many Mbed targets and components support Mbed BLE. Developers can use it to create new BLE enabled applications.
BLE_API interfaces with the BLE controller on the board. It hides the BLE stack’s complexity behind C++ abstractions and is compatible with all BLE-enabled Mbed board. The Mbed OS
BLE_API automatically configuring the clocks, timers and other hardware peripherals to work at their lowest power consumption.
BLE_API, bridges and stacks
You can build a BLE application using Mbed OS,
BLE_API and a controller-specific Bluetooth stack together with some bridge software to adapt it to
BLE_APIas described above.
- The bridge software is specific to each vendor’s board. It provides the instantiations for the interfaces
BLE_APIoffers and helps drive the underlying controller and Bluetooth stack.
- The Bluetooth stack implements the Bluetooth protocol and is specific to the controller, so a vendor using different controllers may provide different stacks.
BLE_API offers building blocks to help construct applications. These fall into two broad categories:
ble/to express BLE constructs, such as GAP, GATT, services and characteristics.
ble/servicesto offer reference implementations for many of the commonly used GATT profiles. The code under 'services/' isn't essential, but it’s a useful starting point for prototyping. We continue to implement the standard GATT profiles.
The BLEDevice class and header
The entry point of Mbed's
BLE_API is the BLE class accessible using the header
ble/BLE.h. This class allows you to obtain a BLE object that includes the basic attributes of a spec-compatible BLE device and can work with any BLE radio:
#include "ble/BLE.h" BLE& mydevicename = BLE::Instance();
The class's member functions can be divided by purpose:
Basic BLE operations, such as initializing the controller.
Accessor to Bluetooth Modules that manage GAP, GATT or the security.
- Set up advertising and connection modes.
- Assign UUIDs to the service and its characteristic.
- Create an input characteristic.
- Construct a service class and add it to the BLE stack.
- Push notifications when the characteristic's value changes.
BLE class reference
|Initialization complete event. More...|
|Events to process event. More...|
|Opaque type used to store the ID of a BLE instance. More...|
|typedef FunctionPointerWithContext< OnEventsToProcessCallbackContext * >||OnEventsToProcessCallback_t|
|Events to process event handler. More...|
|typedef void(*||InitializationCompleteCallback_t) (InitializationCompleteCallbackContext *context)|
|Initialization complete event handler. More...|
|Public Member Functions|
|InstanceID_t||getInstanceID () const|
|Fetch the ID of a BLE instance. More...|
|void||onEventsToProcess (const OnEventsToProcessCallback_t &on_event_cb)|
|Register a callback called when the BLE stack has pending work. More...|
|Process ALL pending events living in the BLE stack and return once all events have been consumed. More...|
|ble_error_t||init (InitializationCompleteCallback_t completion_cb=nullptr)|
|Initialize the BLE controller/stack. More...|
|template<typename T >|
|ble_error_t||init (T *object, void(T::*completion_cb)(InitializationCompleteCallbackContext *context))|
|Initialize the BLE controller/stack. More...|
|bool||hasInitialized () const|
|Indicate if the BLE instance has been initialized. More...|
|Shut down the underlying stack, and reset state of this BLE instance. More...|
|const char *||getVersion ()|
|This call allows the application to get the BLE stack version information. More...|
|ble::Gap &||gap ()|
|Accessor to Gap. More...|
|const ble::Gap &||gap () const|
|A const alternative to gap(). More...|
|ble::GattServer &||gattServer ()|
|Accessor to GattServer. More...|
|const ble::GattServer &||gattServer () const|
|A const alternative to gattServer(). More...|
|ble::GattClient &||gattClient ()|
|Accessors to GattClient. More...|
|const ble::GattClient &||gattClient () const|
|A const alternative to gattClient(). More...|
|ble::SecurityManager &||securityManager ()|
|Accessors to SecurityManager. More...|
|const ble::SecurityManager &||securityManager () const|
|A const alternative to securityManager(). More...|
|This function allows the BLE stack to signal that there is work to do and event processing should be done (BLE::processEvent()). More...|
|Static Public Member Functions|
|static BLE &||Instance ()|
|Get a reference to the BLE singleton. More...|
|static BLE &||Instance (InstanceID_t id)|
|Get a reference to the BLE singleton corresponding to a given interface. More...|
|static const char *||errorToString (ble_error_t error)|
|Translate error code into a printable string. More...|
|Static Public Attributes|
|static const InstanceID_t||DEFAULT_INSTANCE = 0|
|The value of the BLE::InstanceID_t for the default BLE instance. More...|
|static const InstanceID_t||NUM_INSTANCES = 1|
|The number of permitted BLE instances for the application. More...|