What is the most used way to understand what is last packet with ble?

Hi all,

maybe a dumb question, but here to listen any advice. I am using nus to receive data from a phone, packets are in chuncks of 256 bytes, which is the "most used" way to understand when last packet is received?

From what I saw it's responsablity of the application so using a byte counter and check that len is the same? Using a terminator?

Is there a way with protocol?

Thanks!

  • Depends on how you are receiving the data? Normally the API you use to receive data have callbacks which have the argument of length (size of data sent) of the data received. The packets that is sent as chunks from peer are normally packed within this size. If the last packet is very specific to your application or the sender, then ofcourse yes, you need to remember this in your application by implementing a reverse counter. You decrement the reverse counter by the amount of data you received until the counter reaches 0.

  • Hi all,

    maybe a dumb question, but here to listen any advice. I am using nus to receive data from a phone, packets are in chuncks of 256 bytes, which is the "most used" way to understand when last packet is received?

    From what I saw it's responsablity of the application so using a byte counter and check that len is the same? Using a terminator?

    Is there a way with protocol?

    Hi there space waves!

    Your question isn't dumb at all—it's a common challenge when dealing with data transmission. Here are a few methods you can use to determine when the last packet is received:

    Byte Counter: As you mentioned, you can use a byte counter to keep track of the total number of bytes received. Once the expected length is reached, you know you've received the complete data. This method requires that you know the total length of the data in advance.

    Terminator: Another common approach is to use a specific terminator byte or sequence of bytes to indicate the end of the data. This is similar to how strings are terminated with a null character in C. When the receiver detects this terminator, it knows the transmission is complete.

    Protocol-Specific Methods: Some protocols have built-in mechanisms for indicating the end of a transmission. For example, in TCP/IP, the end of a message can be indicated by closing the connection. If you're using a specific protocol, check its documentation to see if it provides a way to signal the end of data.

    Checksum or CRC: Including a checksum or cyclic redundancy check (CRC) at the end of your data can help ensure that the entire message has been received correctly. The receiver can calculate the checksum or CRC of the received data and compare it to the transmitted value to verify completeness.

    Length Field: Include a length field at the beginning of your data. This field specifies the total length of the data being transmitted. The receiver reads this length field first and then knows how many bytes to expect.

    Each method has its pros and cons, and the best choice depends on your specific use case and constraints. If you have control over both the sender and receiver, you can choose the method that best fits your needs.

Related