Coder Social home page Coder Social logo

smartgattlib's Introduction

SmartGattLib

SmartGattLib is a Java library that simplifies the work with Bluetooth SMART devices (a.k.a. Bluetooth Low Energy in Bluetooth 4.0). It provides all UUIDs of the adopted GATT specification and an convenient way to interpret the characteristics (e.g. Heart Rate, BatteryLevel).

Implemented and tested characteristics

  • BatteryLevel
  • BodySensorLocation
  • HeartRateMeasurement
  • ManufacturerNameString
  • More to come. Please commit pull request to add more characteristics.

Compatibility

The library has no dependencies and can be use with every Bluetooth SMART stack e.g.:

Integration

Working with Bluetooth SMART devices is usually done in the following way:

  1. Scan for devices
  2. Connect to a GATT device
  3. Discover services
  4. Get characteristics for the services of interest (SmartGattLib helps identifying the services)
  5. Read characteristics or register for updates (SmartGattLib helps identifying the characteristics)
  6. Interpret the updates from the characteristics (SmartGattLib helps interpreting the data)

Set up

  1. Download the latest .jar file from the releases page and place it in your Android app’s libs/ folder.
  2. Use the example below to identifiy services and characteristics and interpret their data

Example Usage

import com.movisens.smartgattlib.*;

// onConnected
//TODO: iterate over available services
UUID serviceUuid = service.getUuid();
if (Service.HEART_RATE.equals(serviceUuid)) { // Identify Service
	//TODO: iterate over characteristics
	UUID characteristicUuid = characteristic.getUuid();
	if (Characteristic.HEART_RATE_MEASUREMENT.equals(characteristicUuid)) { // Identify Characteristic
		// TODO: Enable notification e.g. for Android API 18:
		// BluetoothGattDescriptor descriptor = characteristic.getDescriptor(Descriptor.CLIENT_CHARACTERISTIC_CONFIGURATION);
		// descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
		// mBluetoothGatt.writeDescriptor(descriptor);
	}
}else{
	System.out.println("Found unused Service: " + Service.lookup(serviceUuid, "unknown"));
}

// onCharacteristicChanged
UUID characteristicUuid = characteristic.getUuid();
if (Characteristic.HEART_RATE_MEASUREMENT.equals(characteristicUuid)) { // Identify Characteristic
	byte[] value = characteristic.getValue();
	HeartRateMeasurement hrm = new HeartRateMeasurement(value); // Interpret Characteristic
	System.out.println("HR: " + hrm.getHr() + "bpm");
	System.out.println("EE: " + hrm.getEe() + "kJ");
}

License

Copyright 2013 movisens GmbH

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

smartgattlib's People

Contributors

jstumpp avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.