How to communicate with Cypress BLE device runnning UART_to_BLE_Central project using Android Java code?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
rotu_3236376
Level 3
Level 3
First like received

Hello-

I have a custom device with a Cypress BLE4 Semiconductor installed and running the UART_to_BLE_central code project (day 20).  This device is running in central mode.  My peripheral is actually an Android Samsung Galaxy S7 phone runing Java API 24.   I have created a custom serivce on the phone that replicates the same service as the USB BLE Dongle Cypress provides with the development kit.  This one: CY5670 http://www.cypress.com/documentation/development-kitsboards/cy5670-cysmart-usb-dongle

The Mobile App is able to advertise and connects successfully with the central and I can view Data Packets being sent back and forth using my Hollong BLE Sniffer.   My question is pretty simple but I need help with it.   After connection, how do I send information back to the device?  I understand from BLE technology that the Peripheral needs to broadcast updates back to all connected devices however I am not sure where the Cypress code is actually reading this.  After connection is made and the Scan data is returrned I only recieve 1 Write request to my Descriptor callback function saying to "Enable Communctions".  I believe this is from the app_BLE.c file, void enableNotifications() function.

What I expect is for it to handle all requests after the successful BLE connection at the void HandleUartTxTraffic(void) function in app_UART.c code. While monitoring the logs from the sniffer it seems that communications is consistently being sent in the PDU packets but I am unable to retrieve any of it because nothing is hitting my callback function.   Anyone have experience with Android BLE development with Cypress products?  All comments and questions welcome.

0 Likes
1 Solution

Hi Madhu-

This is very insightful information, as I was indeed trying to update with the  "WriteNoResponse" CDD2 characteristic and then updating the service. I will modify my code to send updates using Notifcations only which is the "Notify" CDD1 characteristic.

I will keep everyone posted with my progress.

Thanks,

Rohan

View solution in original post

7 Replies
Anonymous
Not applicable

Hi,

The UART BLE Central project is a GATT Client. Which means it can perform read and write on the peripheral device and accpet notifications from the peripheral.

So the mobile app peripheral must act as a GATT Server (Receives write from the Cypress Device and sends notifications to the Cypress device).

Instead of sending notifications from the android app, are you trying to send write? If so the write would fail.

You need to send notifications from the android app which will trigger a CYBLE_EVT_GATTC_HANDLE_VALUE_NTF event in the app_ble.c of the UART Central project and is in turn handled by the HandleUartRxTraffic API.

Regards,

- Madhu Sudhan

Hi Madhu-

This is very insightful information, as I was indeed trying to update with the  "WriteNoResponse" CDD2 characteristic and then updating the service. I will modify my code to send updates using Notifcations only which is the "Notify" CDD1 characteristic.

I will keep everyone posted with my progress.

Thanks,

Rohan

Madhu-

Your counci was superb. That is exactly what I was doing. And your instruction to use the notification characteristic worked perfectly. I can now recieve writechar requests as well as send notifications to the cypress device.

thank you again for your help.

Rohan

Madhu-

I have a puzzling question for you.  Why am able to send notifications from my Peripheral to Central only once?

For some reason right after I connect to the device over BLE.  I get a Descriptor Write Request from the Central [1,0] and then I complete the request and send back informaiton by changing my value in the characteritic(CDD1) and send notificaiton, I succesfully get the expected response.  However, when I try to send a second notification, it fails.  I recieve nothing back.  Is this happening because I am no longer getting Descriptor Write requests from the client?  Are all notifications handled by the CYBLE_EVT_GATTC_HANDLE_VALUE_NTF  event?

Please let me know what you think about this.

Rohan

0 Likes

Hello Rohan,

     Are you waiting for the "onNotificationSent" callback function to be invoked before sending the second notification?

When multiple notifications are to be sent, an application must wait for this callback to be received before sending additional notifications.

Please refer the below code example for an android peripheral device.

ble-test-peripheral-android/app/src/main/java/io/github/webbluetoothcg/bletestperipheral at master ·...

Actually you need to refer this file - >  ble-test-peripheral-android/Peripheral.java at master · WebBluetoothCG/ble-test-peripheral-android ·...

-Gyan

0 Likes

Hi Gyan,

Yes I am waiting for this waiting for the "onNotificationSent" callback.  In fact I am adding a delay of 2000ms between each call as I realize there is a delay with the device after each notification.  I wonder if the issue is how the device is reading chars from the stack.  It is reading this from a function called "scang_num".  I wonder if the Char I am sending is not getting matched in here.  I am sending  this
"1".getbytes() in Java which should equate to [49].  My problem is I am not sure if this being read from the CYBLE_EVT_GATTC_HANDLE_VALUE_NTF  handle event anymore, once the connection and descriptor write request has been made.

void scang_num(auto const rom char *sg_string, unsigned char *sg_addr)

{

unsigned char in_num = 0;

unsigned int ret_num = 0;

printg(sg_string);       //print string

putcharg('?');           //print "?"

do                       //loop

{

in_num = getcharg();

putcharg(in_num);

if ((in_num >47) && (in_num <58) )      //if ASCII number

                   {

   ret_num = (ret_num*10) + (unsigned int)(in_num-48);

   }

}

        while ((in_num != 13) & (in_num != 10));   //until EOL

if (ret_num > 255) ret_num = 255;          //if greater than 255 set = 255

*sg_addr = (unsigned char) ret_num;

putcharg('\n');          //print carriage return

}

0 Likes

Hello Madhu-

I figured out the problem... I was not send the "\n" new line feed or "End of statement" command.  Everything is working as expected now!

Thanks,

Rohan

0 Likes