Skip to content

Latest commit

 

History

History
36 lines (29 loc) · 1.11 KB

README.md

File metadata and controls

36 lines (29 loc) · 1.11 KB

BluetoothSmart

BluetoothSmart is a library that allows a more objective approach to communicating with Bluetooth Smart devices.

Use

In order to begin, a device must be created that extends the SmartDevice object:

@SmartDeviceDef
public class MyDevice extends SmartDevice {
}

In order to filter the device out, the class must also provide an identifier:

@Identifier
public static boolean identify(byte[] data) {
	return Arrays.equals(Arrays.copyOfRange(data, 9, 11), MY_MANUFACTURER_ID);
}

To scan for devices, use the DeviceScanner instance:

DeviceScanner scanner = DeviceScanner.getInstance();
scanner.addDeviceType(MyDevice.class);
if (BluetoothAdapter.getDefaultAdapter.isEnabled())
	scanner.startScan(DeviceScanner.SCAN_MODE_LOW_LATENCY);

SmartDevice objects can now contain specially annotated variables that can infer data from advertisements:

@AdInteger(start=20) private int mBatteryLevel;
@CharDef(service = SERVICE_UUID, id = CHARACTERISTIC_UUID) public Characteristic BATTERY_LEVEL;

JavaDoc will soon be provided as well as some samples to work with common BLE devices.