1 Star 0 Fork 0

wscaco3 / flutter_bluetooth_serial

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

flutter_bluetooth_serial

pub package

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

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 recieving 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.2.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.

MIT License Copyright (c) 2018 Eduardo Folly Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

abreudiego94/flutter_bluetooth_serial的备份 展开 收起
Dart 等 5 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wscaco3/flutter_bluetooth_serial.git
git@gitee.com:wscaco3/flutter_bluetooth_serial.git
wscaco3
flutter_bluetooth_serial
flutter_bluetooth_serial
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891