Manage float data received from ble

Dear ChrisWard,
thanks you for your fast reply, below the Arduino code:
/*
ARDUINO_BLE___send float data
*/

//includo le librerie
#include <ArduinoBLE.h> // library bluetooth
#include <Arduino_LSM9DS1.h> // library accellerometer

//dichiaro servizio bluetooth
BLEService TotalService ("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE TotalService

// BLE - custom 128-bit UUID, read/write central
BLEFloatCharacteristic ComandAccY1("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead);

//variable
float AccX = 0;
float AccY = 0;
float AccZ = 0;

//variable for millis
unsigned long time3;
unsigned long deltatime3;

//---___------***---___------***---___------***
void setup()
{
//open serial comunication
Serial.begin(9600);

//open serial comunication: ok
while (!Serial);

//Nano 33 BLE and sensors: ok
if (!BLE.begin())
{
Serial.println("starting BLE failed!");
while(1);
}

if (!IMU.begin())
{
Serial.println("Failed to initialize IMU!");
while (1);
}

// set advertised local name and service UUID:
BLE.setLocalName("FLOAT DATA");
BLE.setAdvertisedService(TotalService);

// add the characteristic to the service
TotalService.addCharacteristic(ComandAccY1);

// add service
BLE.addService(TotalService);

// set the initial value for the characeristic:
ComandAccY1.writeValue(0.00);

// start advertising
BLE.advertise();
Serial.println("Ready to start");
}

//---___------***---___------***---___------***
void loop() {

//list central
BLEDevice central = BLE.central();

//central is connected
if (central)
{
Serial.print("Connected to central: ");
//print MAC of central
Serial.println(central.address());

//while central is connected
while (central.connected())
{
  //call function
  FUNZAccelerometer1 ();
  
}

//print note when central is disconnected
Serial.print(F("Disconnected from central: "));
Serial.println(central.address());

}
}

//---___------***---___------***---___------***
void FUNZAccelerometer1 ()
{
//make 'delay' with millis
deltatime3 = millis() - time3;
if (deltatime3 >= 1000)
{
time3 = millis();
//read values if IMU: ok
if (IMU.accelerationAvailable())
{
IMU.readAcceleration(AccX, AccY, AccZ);
Serial.print(AccY);
Serial.print('\t');
AccY = AccY * 100;
ComandAccY1.writeValue(AccY);
Serial.println(AccY);
}
}
}

//---___------***---___------***---___------***

And here App Inventor app: BLE_float_data.aia (246.4 KB)

Do it possible make a PNG file of all code with just one click? Because, I know make a PNG one block for time.

The When Floats Received block always gives you a list, even though it is a list of one item.

Use the for each block to get the item(s) in that list one by one, and process them individually.
Her is a draggable replacement block ...

1 Like

Dear ABG,
thanks you for yuor best support.
Best Regards

Yes, via the right-mouse-click menu in the Blocks Work Area, select "Download Blocks as Image"

... let us know how you get on.

The Sketch has a lot of Serial.print functions that could get picked up by the App. If that is your intention, the data receive block in App Inventor should be .Strings Received. When it receives a float value, the value arrives as text but you can still use that value for math in App Inventor :slight_smile:

Hi Chris,

I am using a commercial sensor for my project and when I get data over BLE my string values is like that

DATA: V[]^]][[� DATA: DCBA@?>==>=<<;;<>BIP DATA: YX DATA: �D ", "bH DATA: JKKKJIHGp DATA: :BJPSTSRPNMKJHGFFGHI DATA: ", "FE DATA: �D ", "bH ", " DATA: ,,,-----� DATA: @><;97653210/...---- DATA: ", "03 DATA: �D ", "bH ", " DATA: DBA@@@@@ DATA: -,,++,05>FLOPPOMKIGF

Do you have any idea about how can I get correct sensor data

Hello Omer

What does the Data look like in the Arduino Terminal?

Edit - also, I need to see your Sketch

OXIMETER.aia (334.0 KB)

I am not using Arduino, I am using this smart device and I am able to establish Ble connection,
However, I did not get human-readable data.

image

Thanks

Do you have a brand name, model number for this device, to allow searching for technical data on it?

There are several articles in this Google search showing how to reverse engineer BLE oxymeter readings.

BLE oximeter UUID

1 Like

OK, I see that your data example is not raw data, you embellish it with "DATA:". While trying to establish type, do not add anything at all to incoming data, just let it stream into the TextBox, one data packet overwriting the next. I have tried converting the data to UTF-16, among other flavours, seems there is either something special or the data gets corrupted.

So yes, we need as much Technical data from the manufacture as possible.

....probably need to read Bytes. Also, use the most recent MIT BLE extension (make a fresh Project): Extension Version: 20201223

Now, here is an old BLE Project, BLE Health Thermometer, which demonstrates how to extract data, developed by Gerrikoio. It will be different for an Oximeter but the principle is the same. Note that as an old Project, it is not using the latest MIT BLE Extension.

BLE_HealthThermometer.aia (185.7 KB)

PLXP_v1.0.0.pdf (1.3 MB)

https://www.professorcad.co.uk/appinventortips#TipsBluetooth
(latest BLE AIX here)

Hi Chris,

Thank you for your help! I've read a lot of your comments on the MIT app forums and it's been very helpful, you're very supportive of everyone working on MIT App Inventor. I really appreciate it.

I have one more question, I read output data from the oximeter via nRf connect, and the output is like this:

In my app when I listen to these Characteristics I am able to see the first byte array which starts at 0x33 or 0x11 in the figure. I am sure my app is reading other value also but small amount of time so I can not see them. I need to read two bytes in the spesific byte array which always starts with 0xFF I am confused about two things

First, how can I only monitor byteArray which starts with 0xFF
Second after that how can I read only the fifth and sixth indexes.

thanks

Hi Omer

I actually do not know :thinking: But I think ABG would know.

Show us your .aia?

Hi Abg, I got some progress on my app. I am able to reach the required ByteArray and my output is below that fifth index shows oxygen level and the sixth is heart rate. I need to get rid of other numbers. Do you have any idea about that

Thanks

OXIMETER_Bytes.aia (345.3 KB)

DATA: [255, 68, 1, 0, 99, 82, 38, 2, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1]DATA: [255, 68, 1, 0, 99, 81, 48, 2, 0, 0, 0, 0, 5, 4, 4, 4, 4, 4, 4, 4]DATA: [255, 68, 1, 0, 99, 81, 48, 2, 5, 5, 5, 5, 2, 1, 1, 1, 1, 0, 0, 0]DATA: [255, 68, 1, 0, 99, 81, 48, 2, 3, 3, 2, 2, 0, 1, 2, 4, 5, 5, 22, 6]DATA: [255, 68, 1, 0, 99, 81, 48, 2, 0, 0, 0, 0, 4, 3, 3, 3, 3, 3, 3, 3]DATA: [255, 68, 1, 0, 99, 80, 48, 2, 5, 4, 4, 4, 2, 2, 1, 1, 1, 1, 0, 0]DATA: [255, 68, 1, 0, 99, 80, 48, 2, 3, 2, 2, 2, 0, 0, 0, 0, 1, 2, 4, 5]DATA: [255, 68, 1, 0, 99, 79, 48, 2, 0, 0, 0, 0, 0, 5, 4, 4, 4, 3, 3, 3]DATA: [255, 68, 1, 0, 99, 79, 48, 2, 6, 6, 5, 5, 5, 3, 3, 3, 3, 2, 2, 2]DATA: [255, 68, 1, 0, 99, 78, 48, 2, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1]DATA: [255, 68, 1, 0, 99, 78, 48, 2, 2, 2, 2, 1, 1, 6, 22, 6, 6, 5, 5, 5]DATA: [255, 68, 1, 0, 99, 78, 48, 2, 1, 2, 3, 5, 5, 3, 3, 3, 3, 3, 3, 3]DATA: [255, 68, 1, 0, 99, 78, 39, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 0, 0]DATA: [255, 68, 1, 0, 99, 77, 39, 2, 0, 0, 0, 0, 0, 0, 1, 3, 4, 5, 6, 22]DATA: [255, 68, 1, 0, 99, 77, 39, 2, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3]DATA: [255, 68, 1, 0, 99, 77, 39, 2, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0]DATA: [255, 68, 1, 0, 99, 77, 39, 2, 0, 0, 0, 0, 0, 1, 2, 4, 5, 5, 5, 21]DATA: [255, 68, 1, 0, 99, 77, 39, 2, 5, 5, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3]

These blocks should show the required numbers as you see them:


initialize global heartRate to
initialize global oxygenLevel to

The global variables are to help debug.

Since you did not name any Labels to receive the requested data values, I mushed them together with a JOIN.

P.S. These blocks can be dragged directly into your Blocks Editor workspace.

See A way to group projects by theme - #10 by ABG
for a demo.

OXIMETER_Bytes (1).aia (346.2 KB)

P.S. I have not seen any reference to floating point numbers in your project, and I am taking your word for it that the 5th and 6th bytes hold the data you want.

Bytes are not floating point numbers in AI2. They are whole numbers in the range 0-255 (unsigned) or -128 - 127 (signed).

2 Likes

Thank you Abg, I appreciate it. This is very helpful :pray:

Also, I have another question about the list. I am looking for an efficient way to do this or any sample in MIT app inventor.

Hello Chris,
I just tested your BLE_HealthThermometer project. It worked on the first try. Thank you for this example !!

How complicated is it to also read other Health BLE devices? Besides the Thermometer that just worked great with your App, I have a PulseOxymeter, Scale, Blood pressure and Glucometer.

Any pointers? Any links you may want to share?

Can you work with me reading these other devices? I'm willing to pay for your services.

I have a BLE scanner that can read all charateristics etc.

Thank you in advance,

Carlos Bieberach

Reading any kind of device is similar, I suggest you create a simple no-frills app, based on Thermometer, and try it.

I'm not available for hire but if you find you need a lot of help and want to pay for it, there is a 'Work for Hire' category on this forum.

On my site you will find some useful BLE things, not least a link to the standard GATT UUIDs for various items of equipment.

https://www.professorcad.co.uk/appinventortips#TipsBluetooth

The thermometer Project was created by my Power User colleague Gerrikoio, I can't take any credit for it.

1 Like