SmartGattLib


Source link: https://github.com/movisens/SmartGattLib

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)

Example Android project with SmartGattLib available here. This is a fork of the Android BluetoothLeGatt Example project. Main modifications can be found in this commit.

Set up

  1. Add the JitPack repository and the dependency to your build file:
  repositories {

 maven {
 url "https://jitpack.io" 
}

}

dependencies {

 compile 'com.github.movisens:SmartGattLib:3.0'

}

or 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.*; import com.movisens.smartgattlib.attributes.*; import com.movisens.smartgattlib.helper.*;  // onConnected // TODO: iterate over available services UUID serviceUuid = null;// service.getUuid();
 if (Services.HEART_RATE.getUuid().equals(serviceUuid)) {

// TODO: iterate over characteristics
  UUID characteristicUuid = null;// characteristic.getUuid();

  if (Characteristics.HEART_RATE_MEASUREMENT.getUuid().equals(characteristicUuid)) {

// 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: " + Services.lookup(serviceUuid));
 
}
  // onCharacteristicChanged UUID uuid = null;// characteristic.getUuid();
 byte[] data = null;// characteristic.getValue();
  AbstractAttribute a = Characteristics.lookup(uuid).createAttribute(data);
 if (a instanceof HeartRateMeasurement) {

  HeartRateMeasurement heartRateMeasurement = ((HeartRateMeasurement) a);

  heartRateMeasurement.getHr();

  heartRateMeasurement.getEe();
 
}
 else if (a instanceof DefaultAttribute) {

  System.err.println("characteristic for " + uuid + " is unknown");
 
}
 else {

  System.out.println("unused characteristic " + a.getCharacteristic().getName());
 
}
  // write Attribute AbstractAttribute aa = new Weight(12.3);
 // TODO: Write aa.getBytes() to aa.getCharacteristic().getUuid();

License

Copyright 2017 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.

Resources

This is a fork of the java-mail api and javax.activation, which is made "Android ready".

This is library to easily use connection between android wear and handheld device.

A simple android library that lets user select a directory.

Android library to backport Material design and allow changing colors at run-time.

Small library that provides... bouncing dots. This feature is used in number of messaging apps (such as Hangouts or Messenger), and lately in Android TV (for example when connecting to Wifi).

A small library including an example app which uses the "floating label" pattern to show form validation.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes