Hello,
I recently tried to implement the peripheral cycle on my ionic / angular app with @awesome-cordova-plugins/bluetooth-le
, without success.
Previously I used GitHub - don/cordova-plugin-ble-peripheral: Apache Cordova plugin for implementing BLE (Bluetooth Low Energy) peripherals., which is working well but is not maintained anymore so that I needed to switch.
Here is the code, which is quite basic :
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 ?