Building Bluetooth Services in Zephyr
Part 2: Implementing the Services
In part 1, I showed how to start up Bluetooth with advertising. That included source code that set up advertising for a few different Bluetooth services.
A Bluetooth peripheral device is defined by the set of Bluetooth services that it supports. The peripheral advertises those services. A service is like a mini application. There are many standard services: see Bluetooth-Guids.
Each service contains a set of characteristics — which are like ports that are read from and/or written to.
Device Information Service
The Device Information Service is a read-only collection of string data defining the device.
Implementing the service is easy. It’s statically defined and has no actual ‘code’. Since the startup code advertises the DIS that’s all we need.
Here you can see the Model Number String, Manufacturer Name String, … that all come from those statically defined sets of a data and one simple read method shared by all of the characteristics.
Battery Level Service
The battery level service contains one BLE read-only characteristic that is programmatically updated. When the value is updated any connected devices get a notification.