CONNECTION BETWEEN ANDROID 11 OS AND PSOC6

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

cross mob
jimctr
Level 2
Level 2
First like received 10 replies posted 10 sign-ins

There is an older post here but the code modifications do not work for me and I am getting slightly different results.  Solved: CONNECTION BETWEEN ANDROID 8.0 OS AND PROC BLE - Cypress Developer Community

Doesn't appear that I am able to attach project code here for UART-to-BLE Bridge, so I will just provide a link:

  Solved: transparent uart using CYBLE-416045-02 - Cypress Developer Community

I am able to connect as a Peripheral Device - using CYBLE-416045-02- using the CySmart App but using  another app like Serial Bluetooth Terminal (downloaded from Play Store of Google) and trying to connect, I get errors.

The Phone is able to see BLE_Serial and I need to set up a custom LE Profile:  

 

SerialTerminal.JPG

 

I end up getting a connection failure due to a write descriptor and gatt status 22, which appears to be because the Android device disconnects from the peripheral (It appears to connect as the LED on peripheral board turns solid green from a blinking blue LED) due to the write descriptor error it is receiving.

IConnection Failed: GATT status 22Connection Failed: GATT status 22

 

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
Yugandhar
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 5 likes given

Hello,

 

You have to enable notification from the smartphone then only you can see the data in the mobile.

Please refer to the attached modified project. Please let me know if this helps.

 

Thanks,

P Yugandhar.

View solution in original post

7 Replies
jimctr
Level 2
Level 2
First like received 10 replies posted 10 sign-ins

Modifying this case statement in host_main, I am able to connect to my phone an communicate with Serial Bluetooth Terminal in Android 11 (turns out this is only a partial solution. You can write on the phone and have the text appear on the terminal window of the PC, but you are not able to go the other direction.)

 

case CY_BLE_EVT_GATTS_WRITE_REQ:
{
cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE;

DEBUG_BLE("CY_BLE_EVT_GATTS_WRITE_REQ \r\n");
cy_stc_ble_gatt_write_param_t *write_req_param = \
(cy_stc_ble_gatt_write_param_t *)eventParam;
cy_stc_ble_gatts_db_attr_val_info_t attr_param;

//write_req_param = (cy_stc_ble_gatts_prep_write_req_param_t*)eventParam;

if (CY_BLE_SERVER_UART_SERVER_UART_RX_DATA_CHAR_HANDLE ==\
write_req_param->handleValPair.attrHandle){

//gattErr = Cy_BLE_GATTS_WriteAttributeValueLocal(&write_req_param->handleValPair);
gattErr = Cy_BLE_GATTS_WriteAttributeValuePeer(&write_req_param->connHandle, &write_req_param->handleValPair);

if (gattErr == CY_BLE_GATT_ERR_NONE){
DEBUG_BLE("Notifications Enabled \r\n");
DEBUG_BLE("Start Entering Data \r\n");

}

}//end if (CY_BLE_SERVER_UART_SERVER_UART_RX_DATA_CHAR_HANDLE

Cy_BLE_GATTS_WriteRsp(write_req_param->connHandle)

/******** First start by leaving in below ****/

DEBUG_BLE("Received GATT Write Request [bdHandle %02X]\r\n",\
write_req_param->connHandle.bdHandle);
attr_param.connHandle.bdHandle = write_req_param->connHandle.bdHandle;
attr_param.connHandle.attId = write_req_param->connHandle.attId;
attr_param.flags = CY_BLE_GATT_DB_PEER_INITIATED;
attr_param.handleValuePair = write_req_param->handleValPair;
attr_param.offset = 0;



DEBUG_BLE("write_req_param->handleValPair.attrHandle = %d",\
write_req_param->handleValPair.attrHandle);
DEBUG_BLE(" -> Should be = CUSTOM_SERV0_CHAR0_DESC0_HANDLE (%d)"\
"\r\n-> Should be = CUSTOM_SERV0_CHAR0_HANDLE(%d)\r\n",\
CUSTOM_SERV0_CHAR0_DESC0_HANDLE, CUSTOM_SERV0_CHAR0_HANDLE);


if(write_req_param->handleValPair.attrHandle == (CUSTOM_SERV0_CHAR0_DESC0_HANDLE))
{
if(Cy_BLE_GATTS_WriteRsp(write_req_param->connHandle) != CY_BLE_SUCCESS)
{
DEBUG_BLE("Failed to send write response \r\n");
}
else
{
DEBUG_BLE("GATT write response sent \r\n");
charNotificationEnabled = attr_param.handleValuePair.value.val[0];
DEBUG_BLE("charNotificationEnabled = %d\r\n", charNotificationEnabled);
printf("Notification Enabled.\r\n\n");
printf("Start entering data\r\n");
notificationPacket.connHandle = appConnHandle;
notificationPacket.handleValPair.attrHandle = CUSTOM_SERV0_CHAR0_HANDLE;
notificationPacket.handleValPair.value.val = buffer;
notificationPacket.handleValPair.value.len = NOTIFICATION_PKT_SIZE;
}
}
break;

0 Likes
jimctr
Level 2
Level 2
First like received 10 replies posted 10 sign-ins

Also appears when I implement this, I lose my ability to go back and forth serial communication with the two ble kits - which I was able to do prior to the code modification

0 Likes
lock attach
Attachments are accessible only for community members.
Yugandhar
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 5 likes given

Hello,

Could you please check whether the Notify is enabled before sending the data ? Please share your complete projects, we can check at our end.

You can also refer to the below attached 'PSoC6_BLE_UART' project which has UART-BLE peripheral and central examples. In this project, before sending the data, discovery process will takes place using UUID.  

Thanks,
P Yugandhar.

0 Likes
lock attach
Attachments are accessible only for community members.

Hi:  Those are the files that I modified to communicate with the phone.  Modification in host_main.c starting line 553 to 569.   This is what I am seeing:  1) Can transmit from phone to BLE kit which shows up on PC terminal, but does not appear I can transmit in the other direction, from PC terminal back to phone. 2) With modification to code, I can only transmit in one direction when using two kits, one peripheral and one central.

0 Likes
jimctr
Level 2
Level 2
First like received 10 replies posted 10 sign-ins

Hi Yugandhar:

You asked to check if notification was enabled.  Where exactly is this done?  Cysmart seems to indicate that Notifications are disabled if I go to GATT DB >  unknown service > Notify > Descriptors > Client Characteristic Configuration > Notifications disabled, Indications Disabled.

Thanks

 

OK, I see where this is done.   Notifications were disabled.  But upon enabling them, I don not see a change in behavior.  GATT DB  still reports that notifications are disabled.

 

 

jimctr_0-1612223717274.png

jimctr_1-1612225621328.png

 

Jim

0 Likes
lock attach
Attachments are accessible only for community members.
Yugandhar
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 5 likes given

Hello,

 

You have to enable notification from the smartphone then only you can see the data in the mobile.

Please refer to the attached modified project. Please let me know if this helps.

 

Thanks,

P Yugandhar.

jimctr
Level 2
Level 2
First like received 10 replies posted 10 sign-ins

This works great.  Thanks for fixing!

0 Likes