搜索插件、代码仓与 APP 分类

flutter_bluetooth_serial 封面
插件详情v0.4.0

flutter_bluetooth_serial

一个基本的Flutter蓝牙串行库

Android
近 30 天下载
9560
喜欢数
377
Pub 分数
130

安装插件

flutter pub add flutter_bluetooth_serial

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个轻量级的 Flutter 包,用于在 Android 上连接和通信蓝牙串行设备。它支持 Flutter 应用与兼容硬件(如传感器、微控制器或自定义 IoT 设备)之间双向数据传输,使用标准蓝牙串行协议。该库抽象了低级别的蓝牙操作,提供易于使用的 API 来扫描、配对以及发送/接收数据。专为 Android 设计,支持基本蓝牙功能,无需复杂配置。

适合场景

  • 连接到基于Arduino的设备
  • 从蓝牙模块传输传感器数据
  • 通过蓝牙控制物联网设备
  • 与自定义硬件外设集成
  • 在移动应用中实现实时数据交换

主要特点

  • 蓝牙通信的简单API
  • 仅支持 Android
  • 双向数据传输
  • 设备发现和配对
  • 轻量且依赖极少

适合对象

  • 物联网应用开发者
  • 硬件集成项目
  • 教育机器人
  • 嵌入式系统原型设计
  • 仅限Android的蓝牙应用程序

使用建议

  • 仅限Android平台
  • 不支持 iOS
  • 需要在清单中授予蓝牙权限
  • 取决于设备与串行协议的兼容性
  • 基本功能集,不包含高级蓝牙配置文件

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

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.

Funding

Your contribution will help drive the development of quality tools for the Flutter and Dart developer community. Any amount will be appreciated. Thank you for your continued support!

BuyMeACoffee

PIX

Sua contribuição ajudará a impulsionar o desenvolvimento de ferramentas de qualidade para a comunidade de desenvolvedores Flutter e Dart. Qualquer quantia será apreciada. Obrigado pelo seu apoio contínuo!

PIX

Getting Started

Depending
# Add dependency to `pubspec.yaml` of your project.
dependencies:
  # ...
  flutter_bluetooth_serial: ^0.4.0
Installing
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

  • [Eduardo Folly](mailto:edufolly@gmail.com)
  • [Martin Mauch](mailto:martin.mauch@gmail.com)
  • [Patryk Ludwikowski](mailto:patryk.ludwikowski.7@gmail.com)

After version 0.3.0 we have a lot of collaborators. If you would like to be credited, please send me an [email](mailto:edufolly@gmail.com).

所属分类

源码仓库

使用此插件的项目