SmartGattLib is a Java library that simplifies the work with Bluetooth SMART devices. It provides all UUIDs of the adopted GATT specification and an convenient way to interpret the characteristics (e.g. Heart Rate, BatteryLevel).
Currently implemented and tested characteristics:
- BatteryLevel
- BodySensorLocation
- HeartRateMeasurement
- ManufacturerNameString
- More to come. Please commit pull request to add more characteristics.
The library has no dependencies and can be use with every Bluetooth SMART stack e.g.:
- Android API Level 18 (available soon)
- Samsung BLE SDK
- HTC OpenSense BLE API
- Motorola (seems obsolete)
Working with Bluetooth SMART devices is usually done in the following way:
- Scan for devices
- Connect to a GATT device
- Discover services
- Get characteristics for the services of interest (SmartGattLib helps identifying the services)
- Read characteristics or register for updates of the characteristics (SmartGattLib helps identifying the characteristics)
- Interpret the updates from the characteristics (SmartGattLib helps interpreting the data)
- Drop the SmartGittLib-0.1.jar to the libs folder of your Android project.
- Use the example below to identifiy services and characteristics and interpret their data
// onConnected
//TODO: iterate over available services
UUID serviceUuid = service.getUuid();
if (Service.HEART_RATE.equals(serviceUuid)) {
//TODO: iterate over characteristics
UUID characteristicUuid = characteristic.getUuid();
if (Characteristic.HEART_RATE_MEASUREMENT.equals(characteristicUuid)) {
// TODO: Enable notification
}
}
// onCharacteristicChanged
UUID characteristicUuid = characteristic.getUuid();
if (Characteristic.HEART_RATE_MEASUREMENT.equals(characteristicUuid)) {
byte[] value = characteristic.getValue();
HeartRateMeasurement hrm = new HeartRateMeasurement(value);
hrm.getHr();
hrm.getEe();
}