I think I should read the data that came from the serial port, but I don't know how.
Thank you in advance!
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
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
Thank you for your help!
I'll refer to it and try it.
LED control succeeded by sending text.
Thank you!
That's great, glad I could be of help