All Projects → iDevicesInc → Sweetblue

iDevicesInc / Sweetblue

Licence: gpl-3.0
BLE on Android, the easy way. THIS IS NOW DEPRECATED. Please visit website for info on new versions.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Sweetblue

bluetooth
Android Bluetooth examples
Stars: ✭ 80 (-76.4%)
Mutual labels:  bluetooth, ble
ruuvitag-demo
Demo of reading Bluetooth Low Energy sensor measurements of RuuviTag environmental sensors and feeding them to MQTT, a database and dashboards
Stars: ✭ 14 (-95.87%)
Mutual labels:  bluetooth, ble
bluetooth-manager
Java Bluetooth Manager. A library/framework for managing bluetooth adapters, bluetooth devices, GATT services and characteristics
Stars: ✭ 75 (-77.88%)
Mutual labels:  bluetooth, ble
IOsonata
IOsonata multi-platform multi-architecture power & performance optimized software library for fast and easy IoT MCU firmware development. Object Oriented design, no board package to define, just pure plug & play any boards
Stars: ✭ 40 (-88.2%)
Mutual labels:  bluetooth, ble
Rubble
(going to be a) BLE stack for embedded Rust
Stars: ✭ 292 (-13.86%)
Mutual labels:  ble, bluetooth
bluetooth-gatt-parser
Bluetooth GATT service and characteristic parser
Stars: ✭ 61 (-82.01%)
Mutual labels:  bluetooth, ble
ble-utilities-unreal
This is Unreal Engine plugin that allows to scan for BLE devices with Cycling Power service running, connect to one of them and subscribe for its notifications.
Stars: ✭ 48 (-85.84%)
Mutual labels:  bluetooth, ble
arduino-ble-gadget
Create your own Do-It-Yourself BLE enabled sensor gadget on the ESP32 platform.
Stars: ✭ 31 (-90.86%)
Mutual labels:  bluetooth, ble
JDY-08
JDY-08 Bluetooth transparent transmission module, with resource for KiCAD
Stars: ✭ 48 (-85.84%)
Mutual labels:  bluetooth, ble
IoT-iBeacon
An Ionic app for indoor localization and navigation using BLE iBeacons.
Stars: ✭ 39 (-88.5%)
Mutual labels:  bluetooth, ble
python-sonicare
Python library to communicate with a Phillips Sonicare toothbrush via Bluetooth Low Energy
Stars: ✭ 46 (-86.43%)
Mutual labels:  bluetooth, ble
Esp32 Ble2mqtt
A BLE to MQTT bridge running on an ESP32
Stars: ✭ 301 (-11.21%)
Mutual labels:  ble, bluetooth
awesome-bluetooth-security
List of Bluetooth BR/EDR/LE security resources
Stars: ✭ 220 (-35.1%)
Mutual labels:  bluetooth, ble
wx-ant-ble
微信、支付宝小程序BLE蓝牙SDK
Stars: ✭ 75 (-77.88%)
Mutual labels:  bluetooth, ble
Bluetooth-ble-beamer-and-scanner-for-tracing-corona-virus-infected-individual
Bluetooth ble beacon beamer and scanner for tracing corona virus infected person similar to Trace Together app
Stars: ✭ 26 (-92.33%)
Mutual labels:  bluetooth, ble
android-ble-made-easy
An Android Library for handling Bluetooth Low Energy on Android Easy
Stars: ✭ 34 (-89.97%)
Mutual labels:  bluetooth, ble
BLELib
This library contains many of the features you need to interact with BLE peripherals
Stars: ✭ 21 (-93.81%)
Mutual labels:  bluetooth, ble
H.E.L.P.
Home Environment Locating People 🍍
Stars: ✭ 19 (-94.4%)
Mutual labels:  bluetooth, ble
IOS-DFU-Library
OTA DFU Library for Mac and iOS, compatible with nRF5x SoCs
Stars: ✭ 400 (+17.99%)
Mutual labels:  bluetooth, ble
Easybluetooth
一款iOS BLE蓝牙调试工具,非常简单容易,也可以作为一个蓝牙库,快速集成和开发。 可以两步搞定蓝牙开发操作。 第一步连接设备,第二步特征读写数据。
Stars: ✭ 282 (-16.81%)
Mutual labels:  ble, bluetooth

With the release of SweetBlue v3 (https://sweetblue.io), this project is no longer being actively developed. Consider this project as abandoned.



| Why? | Features | Getting Started | Licensing | Wiki | Toolbox


Why? ====

Android's BLE stack has some...issues...

SweetBlue is a blanket abstraction that shoves all that troublesome behavior behind a clean interface and gracefully degrades when the underlying stack becomes too unstable for even it to handle.

It’s built on the hard-earned experience of several commercial BLE projects and provides so many transparent workarounds to issues both annoying and fatal that it’s frankly impossible to imagine writing an app without it. It also supports many higher-level constructs, things like atomic transactions for coordinating authentication handshakes and firmware updates, flexible scanning configurations, read polling, transparent retries for transient failure conditions, and, well, the list goes on. The API is dead simple, with usage dependence on a few plain old Java objects and link dependence on standard Android classes. It offers conveniences for debugging and analytics and error handling that will save you months of work - last mile stuff you didn't even know you had to worry about.

Features

  • Full-coverage API documentation: http://idevicesinc.com/sweetblue/docs/api
  • Sample applications.
  • Battle-tested in commercial apps.
  • Plain old Java with zero API-level dependencies.
  • Rich, queryable state tracking that makes UI integration a breeze.
  • Automatic service discovery.
  • Full support for server role including advertising.
  • Easy RSSI tracking with built-in polling and caching, including distance and friendly signal strength calculations.
  • Highly configurable scanning with min/max time limits, periodic bursts, advanced filtering, and more.
  • Continuous scanning mode that saves battery and defers to more important operations by stopping and starting as needed under the hood.
  • Atomic transactions for easily coordinating authentication handshakes, initialization, and firmware updates.
  • Automatic striping of characteristic writes greater than MTU size of 20 bytes.
  • Undiscovery based on last time seen.
  • Clean leakage of underlying native stack objects in case of emergency.
  • Wraps Android API level checks that gate certain methods.
  • Verbose logging that outputs human-readable thread IDs, UUIDs, status codes and states instead of alphabet soup.
  • Wrangles a big bowl of thread spaghetti behind a nice asynchronous API - make a call on main thread, get a callback on main thread a short time later.
  • Internal priority job queue that ensures serialization of all operations so native stack doesn’t get overloaded and important stuff gets done first.
  • Optimal coordination of the BLE stack when connected to multiple devices.
  • Detection and correction of dozens of BLE failure conditions.
  • Numerous manufacturer-specific workarounds and hacks all hidden from you.
  • Built-in polling for read characteristics with optional change-tracking to simulate notifications.
  • Transparent retries for transient failure conditions related to connecting, getting services, and scanning.
  • Comprehensive callback system with clear enumerated reasons when something goes wrong like connection or read/write failures.
  • Distills dozens of lines of boilerplate, booby-trapped, native API usages into single method calls.
  • Transparently falls back to Bluetooth Classic for certain BLE failure conditions.
  • On-the-fly-configurable reconnection loops started automatically when random disconnects occur, e.g. from going out of range.
  • Retention and automatic reconnection of devices after BLE off->on cycle or even complete app reboot.
  • One convenient method to completely unwind and reset the Bluetooth stack.
  • Detection and reporting of BLE failure conditions that user should take action on, such as restarting the Bluetooth stack or even the entire phone.
  • Runtime analytics for tracking average operation times, total elapsed times, and time estimates for long-running operations like firmware updates.

Getting Started

  1. If using Android Studio or Gradle...
  2. Download the latest release to a subfolder of your project such as MyApp/src/main/lib/. This ZIP contains several samples, precompiled JARS, and API docs and is preferable to downloading from GitHub, which only contains the raw source.
  3. Open the app module's build.gradle file.
  4. If building with source, your gradle file should look something like this:
```

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.3'
    
    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 25
        ...
    }

    sourceSets {
        main.java.srcDirs += 'src/main/lib/sweetblue/src'
        main.res.srcDirs += 'src/main/lib/sweetblue/res'
        ...
    }
    ...
}

```
  1. If you're building with source from github, the sourceSet path is a bit different:
```
  
  android {
      compileSdkVersion 25
      buildToolsVersion '25.0.3'
      
      defaultConfig {
          minSdkVersion 18
          targetSdkVersion 25
          ...
      }
  
      sourceSets {
          main.java.srcDirs += 'src/main/lib/sweetblue/library/src/main/java'              
          main.res.srcDirs += 'src/main/lib/sweetblue/library/src/main/res'
          ...
      }
      ...
  }
  
  ```
  1. Else if building with JAR, it should look something like this:
```

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.3'
    
    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 25
        ...
    }

    dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
        ...
    }
    ...
}

```
  1. Now add these to the root of MyApp/AndroidManifest.xml:

    <uses-sdk android:minSdkVersion="18" android:targetSdkVersion="25" />
    <uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    
    <!-- NOTE: Location is a new requirement for scanning in Android M.  -->
    <!--       You may use ACCESS_FINE_LOCATION also or instead.         -->
    
  2. From your Activity or Service or Application instance, this is all it takes to discover a device, connect to it, and read a characteristic:

    // A ScanFilter decides whether a BleDevice instance will be created from a
    // BLE advertisement and passed to the DiscoveryListener implementation below.
    final ScanFilter scanFilter = new ScanFilter()
    {
    	@Override public Please onEvent(ScanEvent e)
    	{
    		return Please.acknowledgeIf(e.name_normalized().contains("my_device"))
    		             .thenStopScan();
    	}
    };
    
    // New BleDevice instances are provided through this listener.
    // Nested listeners then listen for connection and read results.
    // Obviously you will want to structure your actual code a little better.
    // The deep nesting simply demonstrates the async-callback-based nature of the API.
    final DiscoveryListener discoveryListener = new DiscoveryListener()
    {
    	@Override public void onEvent(DiscoveryEvent e)
    	{
    		if( e.was(LifeCycle.DISCOVERED) )
    		{
        		e.device().connect(new StateListener()
        		{
        			@Override public void onEvent(StateEvent e)
        			{
        				if( e.didEnter(BleDeviceState.INITIALIZED) )
        				{
        					e.device().read(Uuids.BATTERY_LEVEL, new ReadWriteListener()
        					{
        						@Override public void onEvent(ReadWriteEvent e)
        						{
        							if( e.wasSuccess() )
        							{
        								Log.i("", "Battery level is " + e.data_byte() + "%");
    								}
    							}
    						});
    					}
    				}
    			});
    		}
    	}
    };
    
    // This class helps you navigate the treacherous waters of Android M Location requirements for scanning.
    // First it enables bluetooth itself, then location permissions, then location services. The latter two
    // are only needed in Android M. This must be called from an Activity instance.
    BluetoothEnabler.start(this, new DefaultBluetoothEnablerFilter()
    {
    	@Override public Please onEvent(BluetoothEnablerEvent e)
    	{
        	if( e.isDone() )
        	{
        		e.bleManager().startScan(scanFilter, discoveryListener);
        	}
        	
        	return super.onEvent(e);
        }
    });
    

Licensing

SweetBlue is released here under the GPLv3. Please visit https://sweetblue.io for SweetBlue v3, as v2 is no longer licensable for commercial applications. In a nutshell, if you're developing a for-profit commercial app you may use this library for free for evaluation purposes, but most likely your use case will require purchasing a proprietary license before you can release your app to the public. See the FAQ for more details and https://tldrlegal.com/license/gnu-general-public-license-v3-%28gpl-3%29 for a general overview of the GPL.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].