user3763273
user3763273

Reputation: 13

JAVA: Receive data in chunks from RFduino to Android, combine into string from start to end character.

I hope you bright minds can help me out with a JAVA problem. I'm fairly new to programming and haven't been able to crack this through the last few days.

I have an RFduino that sends data (byte array that i convert in to a string) like

*1403263507\n300\n1750,1750,1750,1750,1775,1775,1775,1775,1775,1800,1800,1800,1800,1800\n68,68,68,68,68,67,67,67,68,68,68,68,68,68A.

This is temperature and humidity readings among some other info. The problem is that I unintentionally receive the data in chunks like

First chunk: *1403263507\n300\n1750,1750,1750,1750, and

second chunk: 1775,1775,1775,1775,1775,1800,1800,1800,1800,1800\n68,68,68,68,68,67,67,67,68,68,68,68,68,68A.

The sizes of these string chunks are different every time, as well as the whole string of data from * to A.

I've added the * and the A to be able to figure out when the whole string starts (at *) and ends (A). A chunk of data can also contain both the end and beginning of a new string like

68,68,68,68,68A*1403263507\n300\n1750,

So my question is:

How do i create one string that consists of the different chunks i received, starting with '*' and ending with A? And how do I complete one string and start one new if I receive the beginning and ending of two different strings like 68,68,68,68,68A*1403263507\n300\n1750,"

Thanks! All help is very much appreciated!

Upvotes: 1

Views: 179

Answers (0)

Related Questions