1

In my project I am using 3 sensors. I am sending a regular stream of sensors data to Bluetooth module but now I want to send data in form of packet (which may be 30 bytes or 40 bytes of size) in which first 10 bytes contain the first sensor data while next 10 bytes contain second sensor data and so on. But problem here is I am not finding something relevant to my approach. Can any one suggest me some link or some way to do this.

Thanks in advance.

3
  • 1
  • It is unclear to me, what the actual problem is here. For imposing a packet protocol onto the serial stream for binary data you normally just send a start byte (or start byte sequence), which you defined, then send the length of the packet and then the data. Not much more to it. Is that, what you are asking for?
    – chrisl
    May 17 '21 at 16:32
  • 1
    Yes i want this. Can you please help me how to do this using arduino IDE software?
    – Namra Noor
    May 18 '21 at 10:39
1

There are many ways to transmit binary data over a byte-stream based interface like Serial (which is used by common bluetooth modules like the HC-05/HC-06). I will only describe one here.

First we need to define a start byte, which marks the start of a new packet. That can be any arbitrary value, for example 0xFF. It is also possible to use a specific byte sequence as start marker. This start byte/sequence is what we send first when transmitting a packet.

Then we want to transmit the size of the following data. With small to normal packet sizes a single byte is enough here (giving room for up to 255 bytes).

Sometimes you might want to compute a CRC hash value to check for data corruption. That could also be send here. But unless you have a system, which really is loosing/corrupting data, you don't need it. I suggest you first try it without and check, if corrupted data is really a thing for your setup.

And then we are sending the actual data. How exactly you are doing this depends on how the data is stored in your code. Though you will use Serial.write() in some way. If you want a more specific answer in this regard, you need to include your code, so that we can see how you are storing your sensor data.

On the receiving side you would then wait for the start marker, read the size byte and then read bytes until you have received as many, as the size byte said. As you have multiple sensors, you could send the sensor data of each sensor in it's own packet. The data could then be formatted like: 1 byte sensor ID, X byte sensor data.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.