Masterarbeit Richard Stern. Flutter App, sich mit einem Bluetooth-Gerät verbindet und Berührungen auf einem Sensor visualisiert.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. [![pub package](https://img.shields.io/pub/v/flutter_blue.svg)](https://pub.dartlang.org/packages/flutter_blue)
  2. <br>
  3. <p align="center">
  4. <img alt="FlutterBlue" src="https://github.com/pauldemarco/flutter_blue/blob/master/site/flutterblue.png?raw=true" />
  5. </p>
  6. <br><br>
  7. ## Introduction
  8. FlutterBlue is a bluetooth plugin for [Flutter](http://www.flutter.io), a new mobile SDK to help developers build modern apps for iOS and Android.
  9. ## Cross-Platform Bluetooth LE
  10. FlutterBlue aims to offer the most from both platforms (iOS and Android).
  11. Using the FlutterBlue instance, you can scan for and connect to nearby devices ([BluetoothDevice](#bluetoothdevice-api)).
  12. Once connected to a device, the BluetoothDevice object can discover services ([BluetoothService](lib/src/bluetooth_service.dart)), characteristics ([BluetoothCharacteristic](lib/src/bluetooth_characteristic.dart)), and descriptors ([BluetoothDescriptor](lib/src/bluetooth_descriptor.dart)).
  13. The BluetoothDevice object is then used to directly interact with characteristics and descriptors.
  14. ## Usage
  15. ### Obtain an instance
  16. ```dart
  17. FlutterBlue flutterBlue = FlutterBlue.instance;
  18. ```
  19. ### Scan for devices
  20. ```dart
  21. /// Start scanning
  22. var scanSubscription = flutterBlue.scan().listen((scanResult) {
  23. // do something with scan result
  24. });
  25. /// Stop scanning
  26. scanSubscription.cancel();
  27. ```
  28. ### Connect to a device
  29. ```dart
  30. /// Create a connection to the device
  31. var deviceConnection = flutterBlue.connect(device).listen((s) {
  32. if(s == BluetoothDeviceState.connected) {
  33. // device is connected, do something
  34. }
  35. });
  36. /// Disconnect from device
  37. deviceConnection.cancel();
  38. ```
  39. ### Discover services
  40. ```dart
  41. List<BluetoothService> services = await device.discoverServices();
  42. services.forEach((service) {
  43. // do something with service
  44. });
  45. ```
  46. ### Read and write characteristics
  47. ```dart
  48. // Reads all characteristics
  49. var characteristics = service.characteristics;
  50. for(BluetoothCharacteristic c in characteristics) {
  51. List<int> value = await device.readCharacteristic(c);
  52. print(value);
  53. }
  54. // Writes to a characteristic
  55. await device.writeCharacteristic(c, [0x12, 0x34])
  56. ```
  57. ### Read and write descriptors
  58. ```dart
  59. // Reads all descriptors
  60. var descriptors = characteristic.descriptors;
  61. for(BluetoothDescriptor d in descriptors) {
  62. List<int> value = await device.readDescriptor(d);
  63. print(value);
  64. }
  65. // Writes to a descriptor
  66. await device.writeDescriptor(d, [0x12, 0x34])
  67. ```
  68. ### Set notifications
  69. ```dart
  70. await device.setNotifyValue(characteristic, true);
  71. device.onValueChanged(characteristic).listen((value) {
  72. // do something with new value
  73. });
  74. ```
  75. ## Reference
  76. ### FlutterBlue API
  77. | | Android | iOS | Description |
  78. | :--------------- | :----------------: | :------------------: | :-------------------------------- |
  79. | scan | :white_check_mark: | :white_check_mark: | Starts a scan for Bluetooth Low Energy devices. |
  80. | connect | :white_check_mark: | :white_check_mark: | Establishes a connection to the Bluetooth Device. |
  81. | state | :white_check_mark: | :white_check_mark: | Gets the current state of the Bluetooth Adapter. |
  82. | onStateChanged | :white_check_mark: | :white_check_mark: | Stream of state changes for the Bluetooth Adapter. |
  83. ### BluetoothDevice API
  84. | | Android | iOS | Description |
  85. | :-------------------------- | :------------------: | :------------------: | :-------------------------------- |
  86. | discoverServices | :white_check_mark: | :white_check_mark: | Discovers services offered by the remote device as well as their characteristics and descriptors. |
  87. | services | :white_check_mark: | :white_check_mark: | Gets a list of services. Requires that discoverServices() has completed. |
  88. | readCharacteristic | :white_check_mark: | :white_check_mark: | Retrieves the value of a specified characteristic. |
  89. | readDescriptor | :white_check_mark: | :white_check_mark: | Retrieves the value of a specified descriptor. |
  90. | writeCharacteristic | :white_check_mark: | :white_check_mark: | Writes the value of a characteristic. |
  91. | writeDescriptor | :white_check_mark: | :white_check_mark: | Writes the value of a descriptor. |
  92. | setNotifyValue | :white_check_mark: | :white_check_mark: | Sets notifications or indications on the specified characteristic. |
  93. | onValueChanged | :white_check_mark: | :white_check_mark: | Notifies when the characteristic's value has changed. |
  94. | state | :white_check_mark: | :white_check_mark: | Gets the current state of the Bluetooth Device. |
  95. | onStateChanged | :white_check_mark: | :white_check_mark: | Notifies of state changes for the Bluetooth Device. |
  96. ## Troubleshooting
  97. ### Scanning for service UUID's doesn't return any results
  98. Make sure the device is advertising which service UUID's it supports. This is found in the advertisement
  99. packet as **UUID 16 bit complete list** or **UUID 128 bit complete list**.