hey
I made a connection between two BLE devices one as peripheral and other as central. I am using CC2541 ibeacon for both central and peripheral.
I am facing two problems
1. Connection is established between central and peripheral and i am able to send a string of max 20 bytes from central to peripheral through characteristic 5. From central i am able to sent exact length and data to peripheral, but at the peripheral end when i am checking at writeCBs i am receiving data correctly but the length as 255 bytes(0xFF) for any string and also not able to receive second string/data from central. Only once it is receiving the write data wrong length. below is the code for both central and peripheral. I am using UART at both ends for writing and reading data at runtime.
#CENTRAL
if (keys)
{
msgPtr = (keyChange_t *)osal_msg_allocate( sizeof(keyChange_t) );
if (msgPtr)
{
msgPtr->keys = keys;
msgPtr->hdr.event = KEY_CHANGE;
msgPtr->state = false;
osal_msg_send (simpleBLETaskId, (uint8 *)msgPtr);
}
}
if (uartPktReceived)
{
uartPktReceived = 0;
req.pValue = GATT_bm_alloc( simpleBLEConnHandle, ATT_WRITE_REQ, uartPktSize, NULL );
if ( req.pValue != NULL )
{
// req.handle = simpleBLECharHdl;
req.handle = 0x0032; //connection handle for characteristic 5
req.len = uartPktSize;
for (i=0; i <= uartPktSize; i++)
{
req.pValue[i] = uartRxBuffer [i];
}
req.sig = 0;
req.cmd = 0;
status = GATT_WriteCharValue( simpleBLEConnHandle, &req, simpleBLETaskId );
if ( status != SUCCESS )
{
GATT_bm_free( (gattMsg_t *)&req, ATT_WRITE_REQ );
}
}
uartPktSize = 0;
}
#peripheral
2. From peripheral I would like send a notification to central after connection and the below program gives the notification sending part peripheral and also notification enabled code in central.
#peripheral
attHandleValueNoti_t noti;
noti.pValue = GATT_bm_alloc( 0, ATT_HANDLE_VALUE_NOTI, uartRxPktSize, NULL );
if ( noti.pValue != NULL )
{
noti.handle = 0x32; // attr value 5 handle
noti.len = uartRxPktSize;
memcpy (noti.pValue, uartRxBuffer, uartRxPktSize);
if ( GATT_Notification( 0, ¬i, FALSE ) != SUCCESS )
{
GATT_bm_free( (gattMsg_t *)¬i, ATT_HANDLE_VALUE_NOTI );
}
}
#central
static void simpleBLECentralProcessGATTMsg( gattMsgEvent_t *pMsg )
{
if ( simpleBLEState != BLE_STATE_CONNECTED )
{
// In case a GATT message came after a connection has dropped,
// ignore the message
return;
}
if (pMsg->method == ATT_HANDLE_VALUE_NOTI)
{
UARTWrite ("working-now");
}
else
if ( ( pMsg->method == ATT_READ_RSP ) ||
( ( pMsg->method == ATT_ERROR_RSP ) &&
( pMsg->msg.errorRsp.reqOpcode == ATT_READ_REQ ) ) )
{
if ( pMsg->method == ATT_ERROR_RSP )
{
uint8 status = pMsg->msg.errorRsp.errCode;
LCD_WRITE_STRING_VALUE( "Read Error", status, 10, HAL_LCD_LINE_1 );
}
else
{
// After a successful read, display the read value
uint8 valueRead = pMsg->msg.readRsp.pValue[0];
LCD_WRITE_STRING_VALUE( "Read rsp:", valueRead, 10, HAL_LCD_LINE_1 );
}
simpleBLEProcedureInProgress = FALSE;
}
else if ( ( pMsg->method == ATT_WRITE_RSP ) ||
( ( pMsg->method == ATT_ERROR_RSP ) &&
( pMsg->msg.errorRsp.reqOpcode == ATT_WRITE_REQ ) ) )
{
if ( pMsg->method == ATT_ERROR_RSP == ATT_ERROR_RSP )
{
uint8 status = pMsg->msg.errorRsp.errCode;
LCD_WRITE_STRING_VALUE( "Write Error", status, 10, HAL_LCD_LINE_1 );
}
else
{
// After a succesful write, display the value that was written and increment value
LCD_WRITE_STRING_VALUE( "Write sent:", simpleBLECharVal++, 10, HAL_LCD_LINE_1 );
}
simpleBLEProcedureInProgress = FALSE;
}
else if ( simpleBLEDiscState != BLE_DISC_STATE_IDLE )
{
simpleBLEGATTDiscoveryEvent( pMsg );
}
GATT_bm_free( &pMsg->msg, pMsg->method );
}
please help me to sort it out if any one faced this issue.