搜尋套件、儲存庫與 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).

所屬分類

原始碼儲存庫

使用此套件的專案