Client reading characteristics and accepting notifications

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

cross mob
PeBe_1604221
Level 3
Level 3
10 sign-ins 5 sign-ins 5 questions asked

Hi,

I am working on a PSoC6 BLE project using the CYBLE-416045-02 module and PSoC Creator V4.4. The BLE is running in Central mode and connects to four Peripheral devices. The peripheral devices implement custom services and characteristics that supply data to the Central using Notifications These peripheral devices are pre-existing and are based on PSoC 4 devices – I have all the definition information for these custom services and characteristics that they implement.

I have the basic PSoC6 Central device working in that I can discover the Peripheral devices and connect to them. However, I am struggling to understand how to implement the Client code to both read from the peripherals, and to respond to notifications from the peripherals. I can find many code examples for Server implementations, but very few for Client implementations.

 

Reading SIG Standard Service Characteristics

The API includes functions for reading characteristics of the SIG services, for example Cy_BLE_BASC_GetCharacteristicValue. These functions have a parameter of type cy_stc_ble_conn_handle_t which is a struct with a member called attId. The documentation says that this member “Identifies the active ATT connection Instance.” I cannot find any more information about this member.

Please would you tell me what this “active ATT connection Instance” is and how I can get its value to use in setting this struct member?

 

Reading Custom Service Characteristics

I cannot find any example of doing this on the Client side. I see in the API documentation that there is a function called Cy_BLE_GATTC_ReadCharacteristicValue – is this the function that should be used for reading custom characteristics? Please would you explain the detail of reading custom characteristics?

 

Responding to Notifications Received by Client

Once I have established a connection to a Peripheral, I see that the Central starts to receive CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF events. I assume that this is because of the notifications produced by the Peripheral. I see that this event’s parameter is of type cy_stc_ble_gattc_handle_value_ntf_param_t, but I cannot find any definition of this type in the documentation. It seems to be an alias for cy_stc_ble_gatt_write_param_t, which is described as a write parameter, not a read parameter, so I am confused.

Please can you explain to me how to correctly extract the data in the notification, and how to respond to the BLE stack that the notification has been received?

 

If you can point me to any examples would help with these questions, that would be much appreciated.

Thanks in advance for your help.

Kind regards,

Peter

0 Likes
1 Solution

Hello,

You will get the handles below the indexes as shown in below image.

Yugandhar_0-1663763131347.png

Could you please try 'Generate Application' and rebuild the project ? Please let me know the version of PSoC Creator, PDL which you are using ?

cy_stc_ble_gattc_handle_value_ind_param_t is for GATT handle value indication. For notifications, CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF will be received and you have to check the structure cy_stc_ble_gattc_handle_value_ntf_param_t. This structure will be updated with the attribute handle of the characteristic( which has notify property). From above fig, char handles are 0x001Cu and 0x001Fu.

Thanks,
P Yugandhar.

View solution in original post

0 Likes
8 Replies
Yugandhar
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 5 likes given

Hello,

The data field attId will identifies the active ATT connection instance i.e., if we define maximum number of connections as 4, then this value will be 3 for the first device connected and this value will be 2 for the second device connected. You can refer to the CE217640_BLE_Phone_Alert_Client project. It uses Cy_BLE_PASSC_GetCharacteristicValue function to read the characteristic Value from a Server.

Cy_BLE_GATTC_ReadCharacteristicValue is used to read a Characteristic Value from a peer GATT Server, when the GATT Client application knows the Characteristic Value Handle. Internally, Read Request is sent to the peer GATT Server. If the read operation is successful, GATT Server sends a Read Response. This response results in CY_BLE_EVT_GATTC_READ_RSP event at the GATT Client's end, and response is passed to the application.

CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF event indicates that Notification data is received from GATT Server device. The event parameter is a pointer to a structure of type cy_stc_ble_gattc_handle_value_ntf_param_t.
Please refer to the CE222046_GATT_In code example from the PSoC Creator for more information on central device operation. Below is the code snippet for reading notification data in client.

Yugandhar_0-1663174023269.png

 

Thanks,
P Yugandhar.

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

Hi,

Firstly, thanks for your fast response. I was away on another project for a few days, but I am now back to this.

Regarding the handling of the CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF event. I had a look at the example project you pointed me to, however, the code there does not actually process the notification data. I did some more reading to figure out how to do this. I see that the from the cy_stc_ble_gattc_handle_value_ind_param_t struct, I can get a cy_ble_gatt_db_attr_handle_t. But I cannot find what to compare that handle with to figure out what characteristic is contained in the notification.

The peripheral device that is sending the notifications has a custom service called “Barometer” and two characteristics called “Pressure” and “Temperature”. I see in the generated BLE_config.h file there are the following lines:

/**
 * Below are the indexes and handles of the defined Custom Services and 
 * their characteristics.
 */
#define CY_BLE_CUSTOMC_BAROMETER_SERVICE_INDEX   (0x00u) /* Index of Barometer service in the cy_ble_customCServ array */
#define CY_BLE_CUSTOMC_BAROMETER_PRESSURE_CHAR_INDEX   (0x00u) /* Index of Pressure characteristic */
#define CY_BLE_CUSTOMC_BAROMETER_PRESSURE_CHARACTERISTIC_USER_DESCRIPTION_DESC_INDEX   (0x00u) /* Index of Characteristic User Description descriptor */
#define CY_BLE_CUSTOMC_BAROMETER_PRESSURE_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_INDEX   (0x01u) /* Index of Client Characteristic Configuration descriptor */
#define CY_BLE_CUSTOMC_BAROMETER_TEMPERATURE_CHAR_INDEX   (0x01u) /* Index of Temperature characteristic */
#define CY_BLE_CUSTOMC_BAROMETER_TEMPERATURE_CHARACTERISTIC_USER_DESCRIPTION_DESC_INDEX   (0x00u) /* Index of Characteristic User Description descriptor */
#define CY_BLE_CUSTOMC_BAROMETER_TEMPERATURE_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_INDEX   (0x01u) /* Index of Client Characteristic Configuration descriptor */


 

The comment in this code says “Below are indexes and handles” but I can only see indexes, no handles.

Please can you explain in a bit more detail how I should be doing this?

For your reference I have attached the complete BLE_config.h file.

 

Thanks again for your help,

Peter

0 Likes

Hello,

You will get the handles below the indexes as shown in below image.

Yugandhar_0-1663763131347.png

Could you please try 'Generate Application' and rebuild the project ? Please let me know the version of PSoC Creator, PDL which you are using ?

cy_stc_ble_gattc_handle_value_ind_param_t is for GATT handle value indication. For notifications, CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF will be received and you have to check the structure cy_stc_ble_gattc_handle_value_ntf_param_t. This structure will be updated with the attribute handle of the characteristic( which has notify property). From above fig, char handles are 0x001Cu and 0x001Fu.

Thanks,
P Yugandhar.

0 Likes
lock attach
Attachments are accessible only for community members.
PeBe_1604221
Level 3
Level 3
10 sign-ins 5 sign-ins 5 questions asked

Hi,

Thanks again for the response.

I had already tried “Generate Application” (also trying “Clean” beforehand), but as I mentioned in my previous post, this results in the generation of only the INDEX defines, not the HANDLE defines. I have just tried it again and got the same result.

I am using V4.4 of PSoC creator. To be honest, I am not exactly sure what version of the PDL I am using because I see many version numbers in many different places. I think it is V3.1.3. Here is a screen shot of the Project/Build Settings/Peripheral Driver Library dialog window:

PeBe_1604221_0-1663827200063.png

Something that may or may not be significant here is how I created this service in the GATT Settings tab of the BLE component. I did this by saving the service from the BLE component in the Peripheral project, and then loading it into this Central project. The Peripheral project is a PSoC 4 project.

For your reference, I have attached the entire Central project.

Many thanks,

Peter

0 Likes

Hello, 

Please add the services details in the GATT Server as shown below. Make sure that the Peripheral GATT Server and Central GATT Server details are matching. 

Yugandhar_0-1663830298049.png

 

Thanks,

P Yugandhar. 

0 Likes
PeBe_1604221
Level 3
Level 3
10 sign-ins 5 sign-ins 5 questions asked

Hi,

Thanks for your response. I have made some progress, but still do not have it working. I have two follow-up questions:

  1. As per your response, I have moved the Barometer service from the Client to the Server folders in the GATT Settings, and I now see the HANDLE defines as expected in BLE_config.h. Notice that I say “moved” – i.e. I removed it from the Client. I initially had it in both as per your screen clip but after that I stopped receiving notifications, so I then deleted it from the Client, and I then started receiving notifications again.

    I have done some reading on these GAT Server and Client roles, but still do not fully understand their relationship. For example, in your YouTube video here , the Peripheral device generating the data has the custom service declared in the Server section, and the Central device that is reading the data, has this service declared in the Client section (as I original had it). Why, in this case, should this service be in the Server section and not the Client section as in that video?

  2. Although I am receiving the notifications, and now have the defines for the HANDLE values, I still cannot decode the notifications because none of the values of the attribute handles received in the event notification parameters match any of the HANDLE defines that I have in BLE_config.h. This is what I am using to extract the attribute handle value:

      cy_stc_ble_gattc_handle_value_ind_param_t* gattHandlePtr = (cy_stc_ble_gattc_handle_value_ind_param_t*)eventParam;
      cy_ble_gatt_db_attr_handle_t attributeHandle = gattHandlePtr->handleValPair.attrHandle;​

    I know that the definitions of the custom characteristics in the GATT Settings for the BLE component are correct because I have used the Save Service/Load Service feature to copy them from the Peripheral project. I have confirmed that the UUIDs are the same, and I have run Generate Application. I know that the Peripheral notifications are correct because I can receive them OK on another Central device. How am I supposed to extract the correct attribute handle values to match the HANDLE defines in BLE_config.h?

Kind regards,

Peter

0 Likes

Hello, 

1. To see the BLE Service handles in the central device, you have to declare the services (which are defined in peripheral) in the Server side of central device. Please make sure that the Peripheral GATT Server and Central GATT Server services/characteristics handle values are matching in the BLE_config.h files.

Could you please share the peripheral and central ble configuration files(.ble) for checking at my end?

Thanks,

P Yugandhar. 

 

0 Likes
PeBe_1604221
Level 3
Level 3
10 sign-ins 5 sign-ins 5 questions asked

Hi,

Thanks for this response, but my last questions was posted about six weeks ago. Since then I struggled on and managed to get it working, and am now working on a different part of the project. If I need more help with this I will re-visit this post.

Kind regards,

Peter

0 Likes