nativescript-blufi
This plugin implements the blufi protocol for espressif on android. iOS is not supported.
Installation
Add the following to package.json: "@freevse/nativescript-blufi": "https://github.com/FREEVSE/nativescript-blufi/releases/download/1.0.0/freevse-nativescript-blufi-1.0.0.tgz"
Usage
You'll need to create a BlufiClient
and assign the proper handlers (GattCallback
and BlufiCallbackImpl
). The following
example uses @nativescript-community/ble to scan for clients, and then uses their UUID to create a new BlufiClient
object:
let _client: BlufiClient;
let _page: Page;
export function navigatingTo(args: EventData) {
//Get the bluetooth device passed from the previous page as Peripheral
_page = <Page>args.object;
let peripheral = _page.navigationContext['svc'] as Peripheral;
_page.bindingContext = new ConfigureDeviceViewModel(peripheral);
//Get the bluetooth device
let btDev = android.bluetooth.BluetoothAdapter.getDefaultAdapter().getRemoteDevice(peripheral.UUID);
//Set up the blufi flow
let ctx = application.android.context;
_client = new BlufiClient(ctx, btDev)
_client.setGattCallback(new GattCallback(_client))// This is weird...
_client.setBlufiCallback(new BlufiCallbackImpl());
_client.connect();
}