Hello
I'm using the nRF51 DK and I have a UART over BLE link set up between the board and a phone with the nRF UART app. I'm trying to get the board to execute a particular function when a certain string is received from the app. For example, the string {'R','e','a','d'} should get the board to start a function that sends data back to the app.
I was wondering what the best way of doing this is?
I currently have it working, but my solution seems unstable as the BLE frequently disconnects. Basically, I edited the "nus_data_handler" function found in the "ble_app_uart_s110_pca10028" example. I copy the data as it is received into an array, and execute functions based on what data is received. Is this an appropriate place to do these actions or is there an alternative?
Here is a simplified version of the function I'm using:
static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)
{
for (uint32_t i = 0; i < length; i++)
{
UART_copy_array[i]=p_data[i];
while(app_uart_put(p_data[i]) != NRF_SUCCESS)
{
}
}
while(app_uart_put('\n') != NRF_SUCCESS);
if((UART_copy_array[0]=='R')&&(UART_copy_array[1]=='e')&&(UART_copy_array[2]=='a')&&(UART_copy_array[3]=='d')){
//Execute Function
}
}
Any help would be much appreciated.
Thanks