ble_app_uart example. send value from putty to dk board.

hi dev.

I study ble uart.

and I succeed connecting with dk board(peripheral) and nrf tool box(uart).

and I also connected with dk board and putty. // like that      computer(putty)  <---> dk board(peripheral) <----> smart phone(nrf toolbox / uart) //

so when I typed some words(ex 123, led) in putty, I can see that words in nrf tool box. 

and I can check the value of word "led"

for example, when I put  word - led , in putty,

I received the log in app, nrf toolbox uart - Notification received from 6e400000e-b5a3-f393-e0a9-e50e24dcca9e, value: (0x)6c-65-64-0d

and then what I want is like that -  if I type the value (0x)6c-65-64-0d in putty, I want to make LED3 on dk board turned on.

but... I have kept looking for that info.. I couldn't find it.

 

How can I do that?

Parents
  • Hello,

    You can use memcmp() for this.

    E.g.,

    #include "nrf_gpio.h"
    
    
    /**@brief   Function for handling app_uart events.
     *
     * @details This function will receive a single character from the app_uart module and append it to
     *          a string. The string will be be sent over BLE when the last character received was a
     *          'new line' '\n' (hex 0x0A) or if the string has reached the maximum data length.
     */
    /**@snippet [Handling the data received over UART] */
    void uart_event_handle(app_uart_evt_t * p_event)
    {
        static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
        static uint8_t index = 0;
        uint32_t       err_code;
    
        switch (p_event->evt_type)
        {
            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&data_array[index]));
                index++;
    
                if ((data_array[index - 1] == '\n') ||
                    (data_array[index - 1] == '\r') ||
                    (index >= m_ble_nus_max_data_len))
                {
                    if (index > 1)
                    {
                    
                        if (!memcmp(data_array, "led\r", index))
                        {
                            /* Toggle LED_3 if the value "6c-65-64-0d" is received over UART */
                            nrf_gpio_pin_toggle(LED_3);
                        }
    ...

    Best regards,

    Vidar

  • HI vidar berg

    thank you for your reply, I can study very well.

    I have a question similar to the one above, could I ask you?

    it's about uart send data as soon as I power on the board.

  • Hi, 

    Please create a new ticket for this question. Thanks.

Reply Children
No Data
Related