Problems with data types RegisterForIntegers and more

Hi,

I am connecting an Arduino Nano 33 BLE to an Android smartphone to send the detection of a fall. I would like to set an alarm in the app and show the background of a label in red, for instance. My problem seems to be with the data type I am sending. I've tried different options: short floats, unsigned integers and bytes. This is the code I use in the Arduino to send an integer, for instance:

...

BLEUnsignedIntCharacteristic alarmCharacteristic ( BLE_UUID_ALARM_FLAG, BLERead | BLENotify );
FallService.addCharacteristic( alarmCharacteristic );
alarmCharacteristic.writeValue(0);

...

if (flagmin & flagmax)
{
alarmCharacteristic.writeValue(1);
}

And, these are the blocks I use to read the value in appinventor:

When the fall condition is activated, I see the number 1 with green background in the app but I fail to see a red background with the text FALL DETECTED. This seems to be due to a failure in the if block when I compare the received value to 1 but I cannot understand why. How can I do that comparison so I can detect the number 1 effectively?

Thank you

The IF fails to match because a list of numbers can never equal a number.
(Did you notice the trailing ‘s’ in the parameter name intValues ?)

Try this IF statement …

IF is in list(intValues, 1) THEN
fall detected logic

(I did not bother to check the is in list block to see which comes first, the list or the item. I leave that to you.)

1 Like

Thank you for your help. Shame on me, I should’ve read more carefully the BLE reference guide where it is clearly stated that the received data type is a list. Moreover, many examples I have seen use lists, but I thought that the idea was to populate a list with the incoming data in floats, integers or whatever which is precisely what is done automatically.

Please, let me ask you another question to make sure that I’ve been doing things correctly:

If I want to receive notifications of the magnitude of the acceleration and the magnitude of the angular speed, do I need to pack them in a string in the peripheral before sending the data and then parse that string to get the magnitudes in the central device? or can you register to receive data from more than one characteristic? I’ve tried the latter but I failed and I want to discard it if it is not possible.

Applications such as nRF Connect can receive notified data from several characteristics.

Thank you

I'm not a BLE expert enough to give you a firm answer on this.

From the past threads I've read, there are limits (32?) to the string length of BLE packets, so a big JSON message is probably inappropriate.

Using multiple UUIDs and multiple BLE components might work for you.

Thank you again for your time, I’ll check the info you sent.

It should be possible to register for multiple UUIDs with a single BLE component. You would only need multiple BLE components if connecting to more than one device.

1 Like

Thank you Evan,

I finally managed to receive two float data registering their UUID in a single BLE as you pointed out. The problem I had had before was with the selection of the UUID to process the data when a float was received. I usually declare my UUID in caps but appinventor strings for UUID are in small caps so the condition to know what float I was receiving never matched!

Just for the record, these are the blocks:

blocks

I also include the piece of debugging code that helped me to find the mismatch between the characteristic UUID (in small caps) and my string (in caps).

Thank you both for your help!
Regards

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.