A basic Flutter Bluetooth Serial
  • Dart 60.6%
  • Java 32.9%
  • C++ 4%
  • Ruby 1.6%
  • Objective-C 0.9%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2021-08-17 19:52:44 -03:00
.github/ISSUE_TEMPLATE Add issue template for bugs 2019-08-19 14:51:39 +02:00
android Update flutter plugin v2 (#144) 2021-08-14 23:34:47 +02:00
example Updating version. 2021-08-17 19:52:44 -03:00
ios First commit. 2018-08-16 12:46:42 -03:00
lib Updating version. 2021-08-17 19:52:44 -03:00
.gitignore implemented nullable safety 2021-07-04 21:45:00 +02:00
CHANGELOG.md Updating version. 2021-08-17 19:52:44 -03:00
flutter_bluetooth_serial.iml First commit. 2018-08-16 12:46:42 -03:00
flutter_bluetooth_serial_android.iml First commit. 2018-08-16 12:46:42 -03:00
LICENSE License. 2020-04-01 10:26:01 -03:00
pubspec.yaml Updating version. 2021-08-17 19:52:44 -03:00
README.md Version 0.3.2 2021-07-15 22:47:42 -03:00

flutter_bluetooth_serial

pub package

Flutter basic implementation for Classical Bluetooth (only RFCOMM for now).

Features

The first goal of this project, started by @edufolly was making an interface for Serial Port Protocol (HC-05 Adapter). Now the plugin features:

  • Adapter status monitoring,

  • Turning adapter on and off,

  • Opening settings,

  • Discovering devices (and requesting discoverability),

  • Listing bonded devices and pairing new ones,

  • Connecting to multiple devices at the same time,

  • Sending and receiving data (multiple connections).

The plugin (for now) uses Serial Port profile for moving data over RFCOMM, so make sure there is running Service Discovery Protocol that points to SP/RFCOMM channel of the device. There could be max up to 7 Bluetooth connections.

For now there is only Android support.

Getting Started

Depending

# Add dependency to `pubspec.yaml` of your project.
dependencies:
    # ...
    flutter_bluetooth_serial: ^0.3.2

Installing

# With pub manager
pub get
# or with Flutter
flutter pub get

Importing

import 'package:flutter_bluetooth_serial/flutter_bluetooth_serial.dart';

Usage

You should look to the Dart code of the library (mostly documented functions) or to the examples code.

// Some simplest connection :F
try {
    BluetoothConnection connection = await BluetoothConnection.toAddress(address);
    print('Connected to the device');

    connection.input.listen((Uint8List data) {
        print('Data incoming: ${ascii.decode(data)}');
        connection.output.add(data); // Sending data

        if (ascii.decode(data).contains('!')) {
            connection.finish(); // Closing connection
            print('Disconnecting by local host');
        }
    }).onDone(() {
        print('Disconnected by remote request');
    });
}
catch (exception) {
    print('Cannot connect, exception occured');
}

Note: Work is underway to make the communication easier than operations on byte streams. See #41 for discussion about the topic.

Examples

Check out example application with connections with both Arduino HC-05 and Raspberry Pi (RFCOMM) Bluetooth interfaces.

Main screen and options Discovery and connecting Simple chat with server Background connection

To-do list

  • Add some utils to easier manage BluetoothConnection (see discussion #41),
  • Allow connection method/protocol/UUID specification,
  • Listening/server mode,
  • Recognizing and displaying BluetoothClass of device,
  • Maybe integration with flutter_blue one day ;)

You might also want to check milestones.

Credits

After version 0.3.0 we have a lot of collaborators. If you would like to be credited, please send me an email.

Thanks for all the support!