When using NUS, configure communication protocol

hello!

I am developing communication using Nordic UART Service.

 

It defines the protocol of data sent by the ble_nus_data_send() function.

err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle); )

When composing a communication protocol, for reliability, it usually starts with STX (0x02) and ends with ETX (0x03) and uses length and checksum.

|STX | Length | data~~~~~~ | checksum | ETX |

By the way, if Nordic UART Service is used this time, I think there will be a data structure for reliability as above in the payload of Nordic UART Service. Is it okay to omit it and transmit only data?

|STX | Length | data~~~~~~ | checksum | ETX |    =====>   only data~~~~~~ 

Additionally, I want to see the data packets from NUS, but I can't find them. If it is public, please link.

  • I think using NUS gives you flexibility regarding data structure. It's doable for you to send your data structure with NUS. You can check example from nRF52-ADC to see how they use NUS to send ADC values from multiple channels.

     // Send data over BLE via NUS service. Create string from samples and send string with correct length.
            uint8_t nus_string[50];
            bytes_to_send = sprintf(nus_string, 
                                    "CH0: %d\r\nCH1: %d\r\nCH2: %d\r\nCH3: %d",
                                    p_event->data.done.p_buffer[0],
                                    p_event->data.done.p_buffer[1],
                                    p_event->data.done.p_buffer[2],
                                    p_event->data.done.p_buffer[3]);
    
            err_code = ble_nus_data_send(&m_nus, nus_string, &bytes_to_send, m_conn_handle);
            if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_NOT_FOUND))
            {
                APP_ERROR_CHECK(err_code);
            }

  • hi

    Looking at the code you attached, it only transmits data.

    There is no checksum or CRC to validate the data I was wondering about above.

    As I think, since there are parts for validating data such as CRC in the BLE Payload anyway, can I omit it?

  • Hi David,

    Nordic UART Service does not add anything else as headers to the data. What you receive in the peer BLE data packet will have only those headers and checksum you included. So I do not understand what you mean by writing "is it okay to omit it?"

  • hi,

    Are the specifications of the entire BLE data packet of Nordic UART Service undisclosed?

    I can't find it... To validate data in the process of developing with NUS We are developing a configuration in which a separate header, length, and checksum are sent and checked again at the receiving end.

    By the way, thinking about it, as you informed me, I was already doing the above process to check the validity of the BLE Data Packet, but putting it in the data and checking it again seemed meaningless, so I made an inquiry.

    The final NUS Data excluded heder and checksum.

  • David_Kim said:
    By the way, thinking about it, as you informed me, I was already doing the above process to check the validity of the BLE Data Packet, but putting it in the data and checking it again seemed meaningless, so I made an inquiry.

    All the data integrity is already checked by the hardware and the Link Layer. So I do not think adding this again in the application adds any benefits. 

    The NUS does not have any special header on top of the BLE packets. What it has is the custom Service UUID and custom characteristics UUID numbers which can be found here.

Related