웹 애플리케이션에서 웹 블루투스 API에 접근할 수 있도록 해주는 플러터 패키지로, 브라우저를 통해 블루투스 저전력(BLE) 장치와 직접 상호작용할 수 있습니다. 기존의 플러터 프로젝트(웹 및 기타 플랫폼 포함)에 원활하게 통합되며, 웹 기반 IoT 솔루션 또는 장치 통신 앱을 개발하는 개발자를 위한 것입니다. BLE 주변기기의 탐지, 연결, 데이터 교환을 지원합니다. 다양한 환경 간 호환성을 고려하여 유지보수되고 있습니다.
사용 사례
웹 앱에서 BLE 장치에 연결하기
실시간 센서 데이터를 사용한 IoT 대시보드 구축
웹 기반 장치 제어 인터페이스 활성화
하이브리드 앱에 블루투스 기능 통합하기
크로스 플랫폼 블루투스 경험 만들기
주요 기능
웹에서 Web Bluetooth API에 대한 액세스
장치 탐지 및 페어링을 지원합니다
BLE 장치에서 실시간 데이터 스트리밍
Flutter와의 크로스 플랫폼 호환성
기존 Flutter 프로젝트와의 간단한 통합
적합한 대상
BLE 장치를 사용하는 웹 개발자
IoT 애플리케이션 제작자
블루투스 지원이 필요한 하이브리드 앱 개발자
블루투스 기능을 갖춘 웹 기능 프로토타이핑
최소한의 네이티브 코드가 필요한 프로젝트
고려 사항
블루투스 접근을 위해 사용자 권한이 필요합니다
Web Bluetooth API를 지원하는 브라우저에 한정
비 웹 플랫폼에 대한 지원 없음
브라우저 고유의 구현 세부 사항에 따라 다릅니다
안전한 컨텍스트(HTTPS)를 위해 추가 설정이 필요할 수 있습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Introduction
Flutter web bluetooth is a FlutterDart plugin to add support for the
web bluetooth api.
The library doesn't require Flutter at all giving you the option to use it with projects like
AngularDart.
It is also written in such a way that it will play nicely with Dart native projects.
So if you have a cross-platform app and want to add web support you don't have to use conditional exports to exclude
the library in native releases.
The web bluetooth is still a draft, because of this it is not (yet) supported in every browser.
Check canIUse.com for information about browser support.
Some parts of the api aren't available in every version of the browser.
Requirements
The device and browser you're testing on needs to support the web api. For Chrome on Linux this is hidden behind a flag.
I've created a patch file which you can use to launch Google Chrome, from flutter run with the required flag enabled.
Check the chrome-experimental-launch folder's README for more information.
You will also need a secure context or else the api will not be available. So either https, or localhost.
Usage
First check if the current browser supports the web bluetooth api.
// The bluetooth api exists in this user agent.final supported = FlutterWebBluetooth.instance.isBluetoothApiSupported;
After this we will need to check if bluetooth is available
// A stream that says if a bluetooth adapter is available to the browser.final available = FlutterWebBluetooth.instance.isAvailable;
Now request a device from the browser.
You must beforehand specify which services you want to connect to! If you do not request
access to a specific service then you won't be able to discover the service!
Some services are also part of a so called blocklist. This is different per browsers and these services are just off
limit. The Web Bluetooth Community Group has a list
of all block services and characteristics.
// Define the services you want to communicate with here!final requestOptions = RequestOptionsBuilder.acceptAllDevices(optionalServices: [
BluetoothDefaultServiceUUIDS.deviceInformation.uuid
]);
try {
final device = awaitFlutterWebBluetooth.instance.requestDevice(requestOptions);
} onUserCancelledDialogError {
// The user cancelled the dialog
} onDeviceNotFoundError {
// There is no device in range for the options defined above
}
Now that you have a device, you can go through the services and then find the characteristics you want to read.
await device.connect();
final services = await device.discoverServices();
final service = services.firstWhere((service) => service.uuid == BluetoothDefaultServiceUUIDS.deviceInformation.uuid);
// Now get the characteristicfinal characteristic = await service.getCharacteristic(BluetoothDefaultCharacteristicUUIDS.manufacturerNameString.uuid);
final value = characteristic.readValue();
// Now we have a [ByteData] object with the manufacturer name in it.
device.disconnect();
Once you have paired to a device you can communicate with it again without the user needing to pair to it again. Get a
reference back to all the connected devices by listening to the devices stream.
Note: This feature will only work if the "Experimental Web Platform features" flag is enabled.
// A stream with a [Set] of all the devices that the user has paired, and given permission for.FlutterWebBluetooth.instance.devices;
You can also overwrite the logger that his library uses. This allows you to decide where log messages go. See
logging on pub.dev for more info on how to intercept these
messages.