This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

I'd like to know how to control the board with the app in the ble_app_uart.

Hello, everyone.
I use the ble_app_uart on the nrf52DK board and SDK V17.  
I would like to send data from the app using RX characteristics of UART service.  The function I want is to control the LED on the board by sending data from the app like the example of the ble_app_blinky.  I succeeded in sending data through the app, but on the other hand, I haven't tried sending app yet.
If I send data using RX characteristics of UART service, it seems to be output to the serial port, what should I do to use it?
I think I should read the data that came from the serial port, but I don't know how.
Can you give me some advice on this?
Thank you in advance!
Parents
  • Hi

    The data sent from the mobile app to the nRF52 is being handled by the nus_data_handler(..) function, on line 196 of main.c. 

    As you can see from the code the standard example is simply taking all the received data and outputting it to the UART using the app_uart_put function. 

    If you want to change this behavior you just need to change what happens in this function, and add some different processing to it. 

    As an example, to change the handler to blink LED_2 whenever the string "hello" is sent, you can implement the function as follows:

    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
        uint8_t string_buffer[BLE_NUS_MAX_DATA_LEN+1];
    
        if (p_evt->type == BLE_NUS_EVT_RX_DATA)
        {
            memcpy(string_buffer, p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
            string_buffer[p_evt->params.rx_data.length] = 0;
    
            if(strcmp("hello", string_buffer) == 0)
            {
                nrf_gpio_pin_toggle(LED_2);
            }
        }
    
    }
     

    Best regards
    Torbjørn

  • LED control succeeded by sending text.
    Thank you!

Reply Children
Related