flutter_reactive_ble : how can I obtain serviceId, characteristicId, and deviceId

I obtained devices through scanForDevices in flutter_react_ble, and the result looks like this:

DiscoveredDevice(id: F0EC76B3-7C7D-2460-5AFA-8F1B586E1849, name: AD_401_RAC_056905_WW_db5a, serviceData: {}, serviceUuids: [feb9], manufacturerData: [196, 0, 2, 146, 21, 22, 128], rssi: -92, connectable: Connectable.available)

From here, how can I obtain serviceId, characteristicId, and deviceId?

>Solution :

A DiscoveredDevice only presents information that was advertised.

There is not a single Service ID. There is the list of advertised Service ID, which may not be all of the IDs. In this case, device.serviceUuids is [feb9].

Characteristics are not advertised. You must connect to the device (connectToDevice), discover all the services (discoverAllServices, getDiscoveredServices), and then you can get the characteristics for each service (service.characteristics). The result of getDiscoveredServices will include all of the available services, which may be more services than device.serviceUuids.

The example app demonstrates how to do all of these steps.

It’s not clear what you mean by "deviceID." There are many things this could be (not all of which are available on all platforms, so you need to explain if this is intended to run on both iOS and Android). But you could start with device.id. On iOS there is, by design, no way to get a consistent and persistent identifier for an arbitrary BLE device, so it depends on your use case what identifier you want.

Leave a Reply