Home > Blockchain >  Flutter acquire data from BLE
Flutter acquire data from BLE

Time:12-09

Hi I'm trying to get some measurement data from a ble decice and display it in my flutter app. I'm also using flutter_reactive_ble

I have two characteristics, one for reading and one for writing. I subscribe an event listener to the readCharacteristic and then I write a request just like below

_ble!.writeCharacteristicWithoutResponse(characteristicWrite, value: [0x99, 0x00, 0x19]);

As the value parameter i'm sending a list of hex value. Every value has it's role, as the ble's manual defines below: enter image description here

I'm using the hex values of the manual's example, and the device sends me the 10 first measurements, which is correct, because every req response has maximum 10 measurements. The thing is that, in the scenario of having 20 measurements, I can't get the last 10. I tried of doing the following

await _ble!.writeCharacteristicWithoutResponse(characteristicWrite, value: [0x99, 0x00, 0x01, 0x99]);

I added 0x01 in the values list, because the manual says

value 1: continue with next group

But data is not getting sent.

How is it possible to get all the measurements, and further more, get for example the 5 last? Can anybody help me or give me a hint? Thank you for your time

CodePudding user response:

The data always has to be 3 bytes long that you send. i.e.

[0x<header>, 0x<command>, 0x<checksum>]

In your second example you have too many bytes. It looks like you have an extra command. i.e.

[0x<header>, 0x<command>, 0x<command>, 0x<checksum>]

For the second write take out the 0x00 and make sure the checksum is correct. i.e:

[0x99, 0x01, 0x1A] 

You send this second write after you receive the first 10 measurements

  • Related