I'm trying to integrate this plugin into a cordova/ionic application with the aim of registering it as a peripheral. The code seems to run and I startAdvertising successfully, however I'm not able to detect my device over bluetooth from any other device. Could someone advise me what I'm doing wrong? Perhaps my expectations are wrong and I have misunderstood some portion of BLE.
Code here:
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { HomePage } from '../pages/home/home';
declare var window: any;
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage: any = HomePage;
advertisingParams = {
services: ['1234'],
service: '1234',
name: "MatrixV2T",
mode: "lowLatency",
connectable: true,
timeout: 500,
powerLevel: "high",
manufacturerId: 0x004C,
manufacturerSpecificData: "Rand"
}
serviceParams = {
service: "1234",
characteristics: [
{
uuid: "ABCD",
permissions: {
read: true,
write: true,
//readEncryptionRequired: true,
//writeEncryptionRequired: true,
},
properties: {
read: true,
writeWithoutResponse: true,
write: true,
notify: true,
indicate: true,
//authenticatedSignedWrites: true,
//notifyEncryptionRequired: true,
//indicateEncryptionRequired: true,
}
}
]
};
private async bleInit() {
return new Promise((resolve, reject) => window.bluetoothle.initialize(resolve, reject));
}
private async bleInitPeripheral() {
return new Promise((resolve, reject) => window.bluetoothle.initializePeripheral(resolve, reject, {
request: true,
restoreKey: "bluetoothleplugin"
}));
}
private async bleStartAdvertising() {
return new Promise((resolve, reject) => window.bluetoothle.startAdvertising(resolve, reject, this.advertisingParams));
}
private async bleAddService() {
return new Promise((resolve, reject) => window.bluetoothle.addService(resolve, reject, this.serviceParams));
}
private async getAdapterInfo() {
return new Promise((resolve, reject) => window.bluetoothle.getAdapterInfo(resolve, reject));
}
async init() {
console.log(await this.bleInit());
console.log(await this.bleInitPeripheral());
console.log(await this.bleAddService());
console.log(await this.bleStartAdvertising());
console.log(await this.getAdapterInfo());
}
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
this.init();
});
}
}
Hi all,
I'm trying to integrate this plugin into a cordova/ionic application with the aim of registering it as a peripheral. The code seems to run and I
startAdvertising
successfully, however I'm not able to detect my device over bluetooth from any other device. Could someone advise me what I'm doing wrong? Perhaps my expectations are wrong and I have misunderstood some portion of BLE.Code here:
Output:
I notice that "isDiscoverable" is always false.
Any help warmly appreciated!