bluetooth_advanced 0.0.83

SDKflutter
Platformandroidios

Flutter plugin project to communicate with bluetooth device.

Flutter package to communicate with bluetooth device

How to Use

To use bluetooth_advanced, follow the following steps:

Step1: Adding plugin dependency

add the plugin to your pubspec.yaml file:

bluetooth_advanced: [latest_version]

Step2: Importing the package.

import the plugin in [your_file].dart

import 'package:bluetooth_advanced/bluetooth_advanced.dart';

Step3: Init configuration details

here it is importance to set UUIDs that are similar to those used in your server device. UUIDs are unique identification information of your device which identifies the services provided by bluetooth device. Your application will connect to that device using this through standard protocols.

final _bluetoothAdvanced = BluetoothAdvanced();
print(await _bluetoothAdvanced.getDataCharactersticUUID());
print(await _bluetoothAdvanced.getServiceCharactersticUUID());
await _bluetoothAdvanced
          .setServiceCharactersticUUID([your_service_uuid]);
await _bluetoothAdvanced
          .setDataCharactersticUUID([your_data_uuid]);

Step4: Initialize Bluetooth

  • returns a stream which you can continously listen to:
_bluetoothAdvanced.initBluetooth();

Step5: Scan Devices

  • returns a stream which you can continously listen to the following states:
STATEDESCRIPTIONDATA TYPE/FORMAT
SCANNING_STARTEDStarted Scanning a paired deviceString
SCANNING_FINISHED_WITH_NO_DEVICEno device foundString
[device_address] , [device_name]return device address,name in comma seperated formatString: "01:23:45:67:89:10,MyBluetoothDevice"
_bluetoothAdvanced.scanDevices();

Step6: Connect Device

  • returns a stream which you can continously listen to the following states:
STATEDESCRIPTIONDATA TYPE / FORMAT
DEVICE_RECOGNIZINGRecognized the device with necessary informationString
DEVICE_CONNECTINGtrying to connect with the deviceString
DEVICE_CONNECTEDestablished connection to the deviceString
DEVICE_DISCONNECTEDconnection abortedString
DEVICE_CONNECTING_FAILEDtrying to connect result failureString
_bluetoothAdvanced.connectDevice();

Step7: Listen to Data

  • returns a stream which you can continously listen to the following states:
STATEDESCRIPTIONDATA TYPE / FORMAT
DEVICE_DATA_INITIATEDattempting data handshake with deviceString
DEVICE_DATA_CONNECTINGtrying to connect with the device to lsiten dataString
DEVICE_DATA_CONNECTEDestablished connection to the device to listen dataString
DEVICE_DATA_AVAILABLEdata is received and available in a formatString : "DEVICE_DATA_AVAILABLE:this is tha data received"
DEVICE_DATA_DISCONNECTEDdata connection was revokedString
_bluetoothAdvanced.listenData();

Step8: Revoke Connection

this will revoke connection with the device, if you dont call this function it will keep running in the background and will keep receiving data.

_bluetoothAdvanced.dispose();

Click here for more Example

Example Images:

Created by Javeria Iffat

FAQ

In case you need: to add new feature or you get any error or any help, please contact me at javeriaiffat312@gmail.com or javeria.iffat@lums.edu.pk please be kind if you get any errors, text me I'll be more than happy to help you all.

THANK YOU!