flutter_bluetooth_serial
Flutter basic implementation for Classical Bluetooth (only RFCOMM for now).
Flutter basic implementation for Classical Bluetooth (only RFCOMM for now).
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.
# Add dependency to `pubspec.yaml` of your project.
dependencies:
# ...
flutter_bluetooth_serial: ^0.2.2
# With pub manager
pub get
# or with Flutter
flutter pub get
import 'package:flutter_bluetooth_serial/flutter_bluetooth_serial.dart';
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.
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 |
---|---|---|---|
BluetoothConnection
(see discussion #41),BluetoothClass
of device,flutter_blue
one day ;)You might also want to check milestones.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。