- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi I have this code for the Server Side following the tutorials from the videos and documents...
My problem is how do I code for its Client Side... say that I want to control the LED of the Client from the button of Server.
Its been done to the Custom CapSense project where the client is updated of the capsense value.
I want to show to another BLE device if a button is pressed at the server, the LED is on at the client...
CODE FOR CLIENT
case CYBLE_EVT_GATTS_WRITE_REQ:
/* This event is generated when the connected Central */
/* device sends a Write request. */
/* The parameter ‘eventParam’ contains the data written */
/* Extract the Write data sent by Client */
wrReqParam = (CYBLE_GATTS_WRITE_REQ_PARAM_T *) eventParam;
if (wrReqParam->handleValPair.attrHandle == CYBLE_DOORSTATUS_STATUS_DOORCCD_DESC_INDEX)
{
CyBle_GattsWriteAttributeValue(&wrReqParam->handleValPair, 0, &connectionHandle, CYBLE_GATT_DB_LOCALLY_INITIATED);
doorNotify = wrReqParam->handleValPair.value.val[0];
}
CyBle_GattsWriteRsp(connectionHandle);
break;
for(;;)
{
/* CyBle_ProcessEvents() allows BLE stack to process pending events */
CyBle_ProcessEvents();
if (bleConnected)
{
uint8 button = SW2_Read();
CYBLE_GATTS_HANDLE_VALUE_NTF_T buttonHandle;
buttonHandle.attrHandle = CYBLE_DOORSTATUS_STATUS_CHAR_HANDLE;
buttonHandle.value.len = 1;
buttonHandle.value.val = &button;
CyBle_GattsWriteAttributeValue(&buttonHandle, 0, &connectionHandle, 0);
if (doorNotify)
CyBle_GattsNotification(connectionHandle, &buttonHandle);
}
}
What events do I needed for my Client and what functions are needed to trigger those events?
Kind Thanks.
These are my custom
Solved! Go to Solution.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Cyrus,
When you press a button on server side , you can send a notification (Button Status) as you are doing correctly.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if (bleConnected)
{
uint8 button = SW2_Read();
CYBLE_GATTS_HANDLE_VALUE_NTF_T buttonHandle;
buttonHandle.attrHandle = CYBLE_DOORSTATUS_STATUS_CHAR_HANDLE;
buttonHandle.value.len = 1;
buttonHandle.value.val = &button;
if (doorNotify)
CyBle_GattsNotification(connectionHandle, &buttonHandle);
}
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
When you send a notification from the server side , An event called as CYBLE_EVT_GATTC_HANDLE_VALUE_NTF will be triggered at client side which holds the Notification data received from server device. A pseudo code looks like below at Client Side.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
void AppCallBack(uint32 event, void *eventParam)
{
CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T NotifyParam;
uint8 ButtonStatus;
switch (event)
{
case CYBLE_EVT_GATTC_HANDLE_VALUE_NTF:
NotifyParam= (CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T*) eventParam;
ButtonStatus=NotifyParam->handleValPair.value.val[0]
break:
.
.
.
.
.
.
}
}
-Gyan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have disabled the notification on Client Char. Config., now I really have to read the attributes...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It sounds like you want the client to read the data from the server. That should be as simple as calling a CyBle_GattcReadCharacteristicValue() function. (Read attribute, service, characteristic, probably using a handle value associated with the switch BLE service that holds the data you want)
The server will automatically return the requested value unless you configure it not to. Then, you will want to handle the case CYBLE_EVT_GATTC_READ_RSP: event to deal with the read response containing the data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Cyrus,
When you press a button on server side , you can send a notification (Button Status) as you are doing correctly.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if (bleConnected)
{
uint8 button = SW2_Read();
CYBLE_GATTS_HANDLE_VALUE_NTF_T buttonHandle;
buttonHandle.attrHandle = CYBLE_DOORSTATUS_STATUS_CHAR_HANDLE;
buttonHandle.value.len = 1;
buttonHandle.value.val = &button;
if (doorNotify)
CyBle_GattsNotification(connectionHandle, &buttonHandle);
}
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
When you send a notification from the server side , An event called as CYBLE_EVT_GATTC_HANDLE_VALUE_NTF will be triggered at client side which holds the Notification data received from server device. A pseudo code looks like below at Client Side.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
void AppCallBack(uint32 event, void *eventParam)
{
CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T NotifyParam;
uint8 ButtonStatus;
switch (event)
{
case CYBLE_EVT_GATTC_HANDLE_VALUE_NTF:
NotifyParam= (CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T*) eventParam;
ButtonStatus=NotifyParam->handleValPair.value.val[0]
break:
.
.
.
.
.
.
}
}
-Gyan