Bluetooth Smart, or Bluetooth Low Energy (BLE), is a low-energy, low-throughput subset of the Bluetooth specification designed for applications that only need to communicate sparsely (IoT), enabling them to thus be powered by small batteries during long periods of time.
In Bluetooth Smart the information is organized in Services and Characteristics, instead of being sent in bulk one after the other. The relationship between both can be thought of as the one between folders and files or structures and variables, where the former serves as a logical container while the data is managed by the latter. Each Service can have one or more Characteristics and the application one or more Services.
For instance, a differential robot application could have the following BLE structure:
- Service 1: Info
- Characteristic 1: Serial Number
- Service 2: Drive
- Characteristic 1: Left Wheel
- Characteristic 2: Right Wheel
- Service 3: Sensors
- Characteristic 1: GPS
- Characteristic 2: Accelerometer
Here the Services group the Characteristics in logical groups, even if one long list of Characteristics would have also worked.
Characteristic Serial Number would be readable, in order to get the info from the robot, whereas Left Wheel and Right Wheel would be writable to control the speeds of the wheels.
However, apart from reading and writing, Characteristics can also notify or indicate. This means that once they've been subscribed to, they will automatically update the values as they change. This is extremely useful to avoid checking for updates and rather simply getting them as they change. Indications are similar to notifications but they require an ACK, making them preferable for use cases where speed is sacrificed for reliability. While either could work, Accelerometer should probably be notifying since it's more important to have up-to-date values than losing a few frames, and GPS should be indicating since it updates about once a second and so it's important to know if the reception has failed to resend the data.
With the basics covered, the best way to put it into practice is getting a development board, in this case the Nordic Semiconductor nRF51 DK with the nRF51822 SoC, a Cortex-M0 with a BLE 4.2 radio, and an integrated JTAG/SWD programmer.
In the GitHub repository below there is a set of basic examples using Nordic's SDK and SoftDevice BLE stack to show how to set up Services and Characteristics and send data over Bluetooth while using GPIOs, PWM, ADC and others.
Happy hacking!