MediaTek-Labs / Arduino-Add-On-for-LinkIt-SDK

Arduino board support package for LinkIt 7697
https://docs.labs.mediatek.com/resource/linkit7697-arduino/en
34 stars 33 forks source link

Bluetooth LE notification not working #80

Closed weixiongmei closed 6 years ago

weixiongmei commented 6 years ago

When trying to enable the notification on the Android with my own code, it failed, and the problem is related to the descriptor not found for the characteristic, the APP "nRF Connected" can't enabled the notification too.

pablosun commented 6 years ago

Hi, thanks for reporting this issue.

Is LinkIt 7697 a Peripheral in this case? e.g. you want to receive the BLE attribute notification on the Android app nRF connected?

Is it possible to show the code snippet that you used to send the notification?

weixiongmei commented 6 years ago

I tried all the Linkit 7697 samples that installed with the Arduino BSP, no one works, i'm sure the code that i wrote for Android is good, because i have other BLE boards such ESP32 and nRF52832, they both works with my Android code. I also tried the Linkit 7697 with the "nRF Connect" tool that's downloaded from the Android App store, but still no luck. So the only possibility is the Linkit 7697 BSP.

On the android side, when trying to enable the notification, it returns the Descriptor not found error, i don't know iOS, haven't tried that...

Not just this, there are some other bugs such as MTU not configurable(Not really a bug, but when using the LBLECharacteristicBuffer class, it will send what ever the size it is in a single packet, for instance, if i don't call the setValueBuffer function, the default size of the buffer is 512 bytes, so when i send a read request from the Android side to the Linkit 7697, i will get a 512 bytes single packet, it seems like it just ignores the MTU).

pablosun commented 6 years ago

Hi, can you describe more clearly what the Android code does? e.g. which API retruns the "Desciptor not found" error? The example LBLE > Notification can be use with apps that receives BLE value notification, such as Lightblue Explorer.

On the MTU issue, there are 2 concepts here:

  1. No, LBLE library does not provide MTU adjustment. You can achieve this by calling the LinkIt SDK API bt_gatts_set_max_mtu.

  2. The characteristic value size and MTU are two different concepts - the MTU is determined by both the peripheral and the central, and the size of the value of a characteristic is defined by application developers. You can have a MTU of 50 bytes and sends a value of 4 bytes, and vice versa.

pablosun commented 6 years ago

One possible reason is that currently the Arduino BSP does not implement the Client Characteristic Configuration Descriptor(CCCD), which may be used by Android API android.bluetooth.BluetoothGatt.setCharacteristicNotification. Reference: https://stackoverflow.com/questions/27068673/subscribe-to-a-ble-gatt-notification-android

weixiongmei commented 6 years ago
                bluetoothle.subscribe((e) => {
                document.body.children[0].innerHTML += "Success:\r\n";
                document.body.children[0].innerHTML += "[" + e.name + "] Value:" + bluetoothle.bytesToString(bluetoothle.encodedStringToBytes(e.value)) + "\r\n";
                }, (e) => {
                document.body.children[0].innerHTML += "Fail: " + e.message + "\r\n";
                }, { address: e.address, service: "19B10010-E8F2-537E-4F6C-D104768A1214", characteristic: "19B10011-E8F2-537E-4F6C-D104768A1214" });

i used Cordova to write the mobile app, the above code is to enable the notification on the Android side, the error message returns Descriptor Not Found. The link that you attached is for iOS, maybe the Linkit 7697 works with iOS but not Android, you can use the app call "nRF Connect" from the Android store for debugging this issue. This tool app is uploaded by the nRF official. It has the same problem when reading the LBLECharacteristicBuffer, will get what ever size it is in a single packet.

Thanks for your great works, and best regards....

pablosun commented 6 years ago

Hi, can you download the attached quick fixes: updated_LBLE_lib.zip

and replace the unzipped content to %USERPROFILE%\appdata\Local\Arduino15\packages\LinkIt\hardware\linkit_rtos\0.10.12\libraries\LBLE\src? (Assuming you are using Windows version of Arduino IDE).

Hope this works.

weixiongmei commented 6 years ago

Hi pablosun,

Very appreciated, the notification works on Android now. When there's a chance, hope you can add the MTU adjustment, txPower adjustment, and changeable characteristic attribute adjustment(read, write, notification, indication). These features are very useful when developing BLE projects.

Best regards..... Thank you~~~~