chipweinberger / flutter_blue_plus

Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android, iOS, macOS
Other
788 stars 478 forks source link

[Help]: Advertising Data #1036

Closed Yolo-cell-hash closed 1 month ago

Yolo-cell-hash commented 1 month ago

Requirements

Have you checked this problem on the example app?

Yes

FlutterBluePlus Version

1.32.12

Flutter Version

3.24.3

What OS?

Android

OS Version

Android 14

Bluetooth Module

-

What is your problem?

Can I somehow advertise my device data / any custom data to the BLE device ? I tried reading some references to get here


class AdvertiseData {
  final FlutterBlue flutterBlue = FlutterBlue.instance;

  Future<void> advertiseDeviceData() async {
    final advertisementData = AdvertisementData(
      localName: 'My BLE Device',
      serviceUuids: [Guid('12345678-1234-5678-1234-56789abcdef0')],
    );

    FlutterBluePlus flb = FlutterBluePlus();
    await flb.startAdvertising(
      advertisementData: advertisementData,
      timeout: Duration(seconds: 30), // Advertise for 30 seconds
    );

    print('Advertising started');
  }
}

Is there any way to achieve this ?

Logs

'AdvertisementData' isn't a function. 
'Guid' isn't a function
The method 'startAdvertising' isn't defined for the type 'FlutterBluePlus'.
MrCsabaToth commented 1 month ago

I think what you want is so called "peripheral mode" of Bluetooth: when your device (probably a phone or tablet) augments a Bluetooth device. Most of the Bluetooth plugins (including FBP) do not support / target peripheral mode. The few plugins I saw and tried didn't work, but let me know if you find any because I'm also interested.

chipweinberger commented 1 month ago

this is addressed in the readme:

Introduction

FlutterBluePlus is a Bluetooth Low Energy plugin for Flutter.

It supports BLE Central Role only (most common).

If you need BLE Peripheral Role, you should check out FlutterBlePeripheral, or bluetooth_low_energy.

the answer is no. Try https://pub.dev/packages/bluetooth_low_energy instead.

If you instead want to send data to a connected peripheral, just call chr.write(...)