cordova-plugin-bluetoothle
cordova-plugin-bluetoothle copied to clipboard
Bluetooth LE advertiser started but not working
Hello,
I recently tried to implement the peripheral cycle on my ionic / angular app, without success. Previously I used https://github.com/don/cordova-plugin-ble-peripheral, which is working well but is not maintained anymore so that I needed to switch.
Here is the basic code, I used the @awesome-cordova-plugin/bluetoothle
adapter for having all the pipe in one block :
(the result is the same using the cordova plugin directly, which I can submit but is far longer)
from(this.ble.requestPermission()).pipe(
// Initialize bluetooth
switchMap(() => this.ble.initialize()),
// Initialize peripheral
switchMap((response) =>
this.ble.initializePeripheral({
request: true,
restoreKey: 'bluetoothleplugin',
})
),
// Add service on enabling
filter((initializeResult) => initializeResult.status === 'enabled'),
switchMap(() =>
this.ble.addService({
service: '1234',
characteristics: [
{
uuid: 'ABCD',
permissions: {
read: true,
write: true,
},
properties: {
read: true,
writeWithoutResponse: true,
write: true,
notify: true,
indicate: true,
},
},
],
})
),
// Start advertising
switchMap(() =>
from(
this.ble.startAdvertising({
service: '1234', //Android
mode: 'lowLatency',
connectable: true,
includeDeviceName: true,
includeTxPowerLevel: true,
})
)
)
)
.subscribe((status) => {
console.log('Advertising status', status);
});
No errors are thrown (also in Android studio logcat), and the startAdvertising
return seems good :
{
"mode": 2,
"timeout": 1000,
"txPowerLevel": 2,
"isConnectable": true,
"status": "advertisingStarted"
}
However the peripheral does not appears in scans, either on my laptop and on another smartphone. (which was also working properly on the previous implementation) I use a Fairphone 3+ with Android 10.
Do I miss something ?
Hi, Were you able to solve this problem? I'm having the same issue and I can't solve it
Nope ! Any support is still welcome ^^
This works for me:
this.ble.startAdvertising(
(success) => {
console.log(success);
},
(error) => {
console.log(error);
},
{
services: ['FE65'], //iOS
service: 'FE65', //Android
name: 'advertisingname',
timeout: 0,
},
);
timeout: 0