cordova-plugin-bluetoothle icon indicating copy to clipboard operation
cordova-plugin-bluetoothle copied to clipboard

Bluetooth LE advertiser started but not working

Open treb93 opened this issue 2 years ago • 5 comments

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 ?

treb93 avatar Jun 06 '22 09:06 treb93

Hi, Were you able to solve this problem? I'm having the same issue and I can't solve it

marcui13 avatar Feb 03 '23 15:02 marcui13

Nope ! Any support is still welcome ^^

treb93 avatar Feb 03 '23 17:02 treb93

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,
    },
);

jcconneqtech avatar Apr 05 '23 08:04 jcconneqtech

timeout: 0

marcelinojung avatar Dec 25 '23 06:12 marcelinojung