ayvazj / retrotooth

Retrofit inspired Bluetooth LE library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Retrotooth

Simplified Bluetooth LE communications inspired by Square's Retrofit library.

Usage

Define an interface for each service and characteristic you are interested in:

public interface HeartRateService {
    @READ(service = "180d", characteristic = "2a38")
    Call<String> getBodySensorLocation();

    @NOTIFY(service = "180d", characteristic = "2a37")
    Call<String> getHeartRateMeasurement();

    @WRITE(service = "180d", characteristic = "2a39")
    Call<Void> setHeartRateControlPoint();
}

Create an adapter and start using BLE

Retrotooth retrotooth = new Retrotooth.Builder()
    .with(this)
    .device(bluetoothDevice)
    .build();

HeartRateService heartRateService = retrotooth.create(HeartRateService.class);
Call<String> call = heartRateService.getBodySensorLocation();
call.enqueue(new Callback<String>() {
    @Override
    public void onResponse(Response<String> response) {
        Toast.makeText(DeviceControlActivity.this, "onResponse", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onFailure(Throwable t) {
        Toast.makeText(DeviceControlActivity.this, "onFailure", Toast.LENGTH_SHORT).show();
    }
 });

About

Retrofit inspired Bluetooth LE library

License:Apache License 2.0


Languages

Language:Java 100.0%