Article

An Introduction to All the Basics of Bluetooth Low Energy (BLE)

Young woman checking her blood sugar using glucometer synchronizing it with smart watches app on yellow background using BLE

What Is Bluetooth Low Energy (BLE)?

Bluetooth Low Energy (BLE) is a subset of Bluetooth 5. BLE was originally released in 2010, and it created a new stack of Bluetooth protocols that used significantly less power without a loss of range. Since then, Bluetooth Low Energy has ushered in a new era of low-powered Internet of Things (IoT) devices.

BLE is power-friendly and implemented on all major operating systems, making it a great option for close-range communication with “smart” objects.

Since its inception this technology has been updated many times to include more features such as:

  • Higher speeds of transmission
  • Faster discovery time
  • Longer range
  • Heightened security
  • More sophisticated device tracking
  • Bluetooth Mesh, a technology which allows BLE devices (called “nodes”) to communicate and extend their range over a Bluetooth network.
  • Bluetooth Low Energy Audio, announced in January of 2020 as an upcoming specification, will allow for multi-device streaming, hearing aid, and other new applications.

BLE’s Role in the Internet of Things (IoT)

Much of the appeal of BLE as a technology lies in its ability to efficiently offer direct wireless communication between devices in range of each other. While this makes BLE a natural and obvious fit for offline scenarios, it also plays a crucial role in many connected products.

For example, many wearable devices use BLE to communicate back to an internet-connected smartphone, tablet, or computer. That device, in turn, passes data to the cloud where it is stored and referenced for tools like dashboards. In these scenarios, the connected device essentially acts as an internet-connected hub between the wearable and the cloud services it relies upon. This allows the wearable to use minimal power for data transmission — and stay up to date whenever it syncs up to your smartphone, tablet, or computer.

How Do You Get a Connected Product Online? Provisioning With BLE.

Bluetooth Low Energy is commonly used to streamline the setup of smart devices that connect to Wi-Fi. This process is known as provisioning. For example, Google’s Chromecast provisioning process uses BLE instead of relying entirely on Wi-Fi communications. The Chromecast mobile app uses Bluetooth Low Energy communications to pass wireless access credentials to the Chromecast device. From there, the Chromecast connects directly to Wi-Fi to stream video. This technology plays a key role in solving the “last-mile” problem of getting credentials onto the internet-connected device to begin with.

Today, many connected products use Bluetooth Low Energy as a fast and efficient way to provision their devices within an IoT ecosystem.

BLE’s Role in Local Positioning

BLE is also used for local positioning applications such as Apple’s iBeacon technology and other BLE-based beacon solutions. BLE beacons placed at known locations can communicate with BLE-enabled phones and tablets to position users within spaces where GPS might not be available (shopping malls, convention centers, theme parks, hospitals, etc.).

Does BLE Mesh?

Since 2017, BLE has included a protocol called Bluetooth Mesh that enables BLE products to communicate with each other to form a large-scale, low-energy network. A key advantage to Bluetooth Mesh is its rapid adoption and standardization, allowing more devices to be compatible and allowing professionals to develop without having to learn multiple competing proprietary protocols.

Bluetooth Mesh technology is increasingly utilized for solutions such as:

  • Standardizing home automation protocols
  • Enabling easier control of home lighting automation
  • Providing network capability in emerging markets
  • Providing a low-cost network for tools, lighting or other devices in buildings and factories
  • Providing a viable network for infrastructure devices such as air quality monitors in cities

How Does Bluetooth Low Energy Work?

Every BLE device has a framework for how data is sent to and from the device. This framework is known as the Generic Attribute Profile (GATT) of the device.

At a high level, the GATT is divided into services, and each service has a set of characteristics. The characteristics are basically data points that can be read or written. In a wearable, for example, you might have characteristics for your heartrate, how many steps you’ve taken, the length of your stride, etc.

The GATT also defines the operations you can perform on each characteristic. Some common operations are:

  • Read: Read a value from the characteristic
  • Write: Write a value to the characteristic
  • Notify/Indicate: Receive notifications when the characteristic’s value changes

In some cases, services and characteristics are reserved for specific types of devices and information. For example, a heart rate monitor will always have a service with identifier 0x180D (Heart Rate) that has characteristics 0x2A37 (the heart rate measurement) and 0x2A38 (the body sensor location).

The most important step you can take as a developer is to fully document the GATT profile for the device to understand its full interface and capabilities. This should be done well before any actual development begins.

Bluetooth Low Energy in iOS

The BLE implementation for iOS is all included in the Core Bluetooth framework. Apple has provided very helpful documentation detailing the data structure and use of this framework.

Basically, the data structure follows its physical representation. Using a CBCentralManager, you can scan for and connect to devices (CBPeripheral). The central manager’s functionality is limited to device discovery, connection, and disconnection. Once connected to a device, however, the CBPeripheral object is the main method for interacting with the device. You can discover the device’s services (CBService), discover a service’s characteristics (CBCharacteristic) and interact directly with the characteristics.

BLE in Android

Bluetooth Low Energy in Android is a little less straightforward. The main interface is the BluetoothAdapter, which is required for any and all Bluetooth activity. Once a device (BluetoothGatt) is discovered, you can connect to that object by calling a method (.connectGatt()) on it. The returned object is the connected device, which you can interact with in the same way as above.

One interesting difference between the Bluetooth Low Energy API on Android and iOS is the way that each platform handles asynchronous communication. Callbacks in the code (LeScanCallback and BluetoothGattCallback) are passed to the discovery and connection to handle errors or successes. But these classes need to be extended and implemented differently on each platform to properly discover devices, connect to them, and receive updates from them. At Vervint, we have created code in GitHub repositories to accommodate these different approaches, which you can find in the section below.

Cross-Platform Bluetooth LE

Sharing code in a cross-platform app means that the implementation details for each platform can be abstracted away. This gives developers a blank canvas on which to build a new interface for BLE.

For ease of re-use, Vervint has created a NuGet package (Xamarin.BluetoothLE) with the iOS and Android Bluetooth LE implementation abstracted away. You can view/contribute to the source on Github. The framework is largely based on the Monkey.Robotics project, but we have made some important updates and changes. For example, because of the confusion introduced by the callbacks in Android, the framework is modeled more closely to the iOS implementation of BLE. With C#, we can then raise events when asynchronous communication events occur.

The documentation for the Xamarin.BluetoothLE package can be found here.

Vervint: BLE and Mobile App Development Experts

With the incredibly fast growth of IoT, BLE has rapidly become a dominant standard of communication. If you want help with your mobile app development project, Vervint is here and ready to help you and your team no matter where you are in the mobile app development process. Contact Vervint today!

About the Author

mm

Matt Brickner & Taylor Brushwyler

Author Title

Matt Brickner is Vervint’s Mobile Application Development Team Lead. With nearly two decades of application development experience, Matt has expanded Vervint’s app dev, mobile and IoT capabilities over the last ten years. With end-to-end experience planning, implementing and managing all manner of software systems, Matt enjoys working with teams to solve real-world problems with pragmatic and creative solutions. Taylor Brushwyler is a senior consultant at Vervint with nearly a decade of professional experience and a BS in Computer Science from Hope College. With a strong background in web and mobile app development and experience in IoT, Taylor brings a unique skillset and insightful perspective to each of his projects. Outside of work, Taylor enjoys coffee, beer, a good book and all things sports.