Defining a packet length when sending via BLE (HM10 Module, Arduino Mega)

Hi All,

I am using a Arduino Mega to collect readings from a pressure sensor and send to a phone, for a certain period every day. The Arduino takes readings 1000 readings over 10 seconds and sends them to the phone via mySerial.print(sensor read) function. The problem is that sometimes a pressure reading will get divided across 2 packets.

Is there a way to define the start and end of a packet to be sent? I have done a lot of research and it doesn't seem to be a discussed topic. Essentially we have a packet flag of "83"(In ASCII) and we will get packets like the below:

38 33 34 35 36
38 33 34 36 35
38 33 34 37 35 38
33 34 36

Packet 3 contains some data that should be contained in our 4th value. And we are worried that we will lose data with the packets in this manner.
Is there a way to say that the packet only contains open flag and 1 pressure reading?

Yes! There are many approaches though. And I cannot tell which one is the best, because that has many considerations.

Probably the easiest for a beginner is adding 'special' characters at the front and back. For example $[yourdata];

Another option is to add a 'message header' to what you are sending. Which contains the type of message, and the length of the message in binary data, often paired with a checksum to make sure it arrived properly.

I'd recommend the special characters though.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.