Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you provide a sample app with only FlutterBleLib plugin? #443

Open
ghost opened this issue Mar 6, 2020 · 7 comments
Open

Can you provide a sample app with only FlutterBleLib plugin? #443

ghost opened this issue Mar 6, 2020 · 7 comments

Comments

@ghost
Copy link

ghost commented Mar 6, 2020

Hi, i am new to Flutter and Dart. I find it difficult to understand the usage of FlutterBleLib using the sample app.
There is lots of code about Bloc and rxDart which is difficult to read. Can you provide a sample app without design patten or unrelated plugins?

@mikolak
Copy link
Collaborator

mikolak commented Mar 6, 2020

Hi!

Creating a new simplified sample app will take time.

For the time being, you can start with just two files:
Initialisation https://github.com/Polidea/FlutterBleLib/blob/develop/example/lib/devices_list/devices_bloc.dart#L52

Scanning for peripherals:
https://github.com/Polidea/FlutterBleLib/blob/develop/example/lib/devices_list/devices_bloc.dart#L111
(same file)

Most of operations on a connected peripheral
https://github.com/Polidea/FlutterBleLib/blob/develop/example/lib/test_scenarios/peripheral_test_operations.dart

@leech001
Copy link

Still, if it is not difficult, I would like to see a simple example of using the library.

@sonnny
Copy link

sonnny commented Apr 22, 2020

See link below simple example, assumed you know device name, service and char uuid, use nrf connect to find out. It just writes to the device.

link for simple ble write example

@JasonEdinburgh
Copy link

@sonnny link http://sayaw.net/flutter/another_ble.html is broken

@sonnny
Copy link

sonnny commented Sep 24, 2020

@JasonEdinburgh good link http://orasna.com/flutter/another_ble.html

This is a basic example.

@JasonEdinburgh
Copy link

Thank you @sonnny

But I need something that shows how to catch the exceptions that are thrown when calling peripheral.connect etc.

My current code does this to initiate a connection and send/receive via characteristics (nordic uart service), but I occasionally get unhandled exceptions. I am not sure yet if they originate in other threads/isolates.

` try {
_connectPressed = true;
Peripheral peripheral = myPeripherals[widget.deviceId];
await peripheral.connect(timeout: Duration(seconds: 2)).catchError((theError) {
print("Caught Error in peripheral.connect ($theError)");
return;
});
print("connected");
await peripheral.discoverAllServicesAndCharacteristics(transactionId: "discovery").catchError((theError) {
print("Caught Error in peripheral.discoverAllServicesAndCharacteristics ($theError)");
return;
});
print("discoverAllServicesAndCharacteristics completed");
await peripheral.services().catchError((theError) {
print("Caught Error in peripheral.services ($theError)");
return;
});
await peripheral.writeCharacteristic(NUS_SERVICE_UUID, WRITE_TO_DEVICE_CHARACTERISTIC_UUID, dataToSend, withResponse).catchError((theError) {
print("Caught Error in peripheral.writeCharacteristic ($theError)");
return;
});

    peripheral.monitorCharacteristic(NUS_SERVICE_UUID, READ_FROM_DEVICE_CHARACTERISTIC_UUID).listen((characteristicWithValue) {
      talkToDevice(characteristicWithValue, peripheral);
    }).onError((theError) {
      print("Caught Error in peripheral.monitorCharacteristic ($theError)");
      return;
    });

} catch (ex, st) {
print("exception caught ${ex.toString()} at $st");
} finally {
print("finally setting _connectPressed = false");
_connectPressed = false;
}`

@ride4sun
Copy link

ride4sun commented Dec 9, 2020

Is there any progress on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants