Bluetooth LOW ENERGY - how to enable NOTIFICATION?

2,612 views
Skip to first unread message
Assigned to andrew.f...@gmail.com by halatmi...@gmail.com

aulker62

unread,
Aug 2, 2016, 4:34:03 PM8/2/16
to MIT App Inventor Forum
Friends...

I have a question. I made a BLE app, and i can send data from my phone to remote BLE device as well.  But BLE device can't send data to my phone.  I tried my remote BLE device with other Google Play Store BLE apps.  , when i enable notifications the other apps., my remote BLE device can send data to my phone as well (other apps.)

So, i need to enable notification of my App Inventor BLE program. I read about it,  i have to use ( 0x2902 or 01 00) some numbers, but i haven't no idea.
Which blocks must i use with these numbers?

I need your help.
Many thanks...

Ghica

unread,
Aug 3, 2016, 11:00:54 AM8/3/16
to MIT App Inventor Forum
Show a screenshot of your relevant blocks and maybe also of your Arduino sketch. What kind of BLE device do you have?
Cheers, Ghica.

Dje

unread,
Aug 3, 2016, 11:36:25 AM8/3/16
to MIT App Inventor Forum
Hi. I have the same problem.

If you install an App from Play Store called 'nrf Connect' and connect to your BLE device you will see how 0x2902 (Descriptor) and 01-00 or 00-00 (value) are used when turning notifications on or off. Just as for you, I need to send the two byte 01-00 or 00-00 value to the device. I haven't found a way to do that using any of the data write blocks. Not surprisingly, it is not accepted as a text string, byte or Integer. 

When I connect to the device with notify enabled, I can only receive the data through 'ByteValueChanged', (which may be the correct way to receive data?) rather than 'ByteValueRead'. Further, there does not seem to be any way of knowing which characteristic sent the notification, and therefore it cannot be filtered. Basically, I seem to be only able to receive single byte or integer data and strings, and not multi-byte sequences.

In other implementations, I've seen statements like:

gatt.setCharacteristicNotification(characteristic, true);

descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);

gatt.writeDescriptor(descriptor);

App Inventor block versions of these seem to be missing and I'm not sure that the existing blocks can be used to implement the same functionality. 
If this is the case, then I'm sure we would both like to know how it is done, or that suitable blocks will be added in the near future.
Not sure that any of this helps, but I hope someone can.

Ghica

unread,
Aug 3, 2016, 11:54:08 AM8/3/16
to MIT App Inventor Forum
Hi,
The App Inventor BLE implementation is very experimental. I will try to find a more precise answer for you.

Abraham Getzler

unread,
Aug 3, 2016, 12:42:25 PM8/3/16
to MIT App Inventor Forum
There is a way to build up hex values in a string using a feature of the Web component.
This works only a byte at a time,so you have to JOIN the resulting bytes.

I can't speak to what will happen when you try to transmit these codes.

The embedded x'00 looks particularly troublesome, as I have seen that is a default delimiter value in the Designer BlueTooth component.

See attached blocks.

ABG

hexify.png
hexify_0A.png
hexify_0D.png

Dje

unread,
Aug 4, 2016, 2:10:51 PM8/4/16
to MIT App Inventor Forum
Hi Abraham,

Thanks for your suggestion, but I still don't think there is any way to send these bytes to change the state of a ble Notification. Following on from your approach though, wouldn't it be possible to create a two byte hex value by using two joined maths 'Decimal to Hex' blocks (as attached)?

Coming back to the original problem though, I wish that App Inventor support would give some indication of whether it is in fact possible to change notification state AND to be able to know the characteristic that actually sent a data update.

Thanks,

Dje.
two hex bytes.JPG

Abraham Getzler

unread,
Aug 4, 2016, 2:22:52 PM8/4/16
to MIT App Inventor Forum
The AI2 math conversion blocks are useful as a teaching tool,
but do not emit true hex values, just readable text.

You can verify this by requesting the string length of their output.

Try converting 255 from decimal to hex, then take its length.
It won't be 1 byte.

ABG

Ghica

unread,
Aug 5, 2016, 7:25:32 AM8/5/16
to MIT App Inventor Forum
I will again try to draw the attention of developers to the notification question.
Cheers, Ghica.

Dje

unread,
Aug 5, 2016, 12:11:32 PM8/5/16
to MIT App Inventor Forum
Thanks Ghica,

That would be very much appreciated. I recall reading a web page recently that went into some detail describing the process of deciding on the components needed for ble in AI2. Notifications was certainly one of the features thought necessary. I feel that it would be possible by implementing a block that can send multiple hex bytes, similar to the block that can send multiple bytes in the bluetooth classic block set. There would stiil be a need though to know the characteristic of the event that sent the notification to distinguish between different events.

Thanks
Dje
Reply all
Reply to author
Forward
0 new messages