My project have multiple transmitters and one receiver. The transmitters sends data that are detect with a accelerometer. I used Zigbee for this communcation.
Is there a better/other way for receiving this data.
Yes. Using delay() in the hope that serial data will have arrived by then will NOT work.
Either do nothing until all 9 bytes have arrived, or keep track of how many bytes have been available() and have been read(), storing each byte in the appropriate place.
First I send a ID value that gives an indication wich module sends.
Then I send a counter.
The last 3 values are the results from the accelerometer.
Because the counter value and the results of the accelerometer are greater then one byte. I split them in high byte and low byte. This can you find in this code:
payload.id = id; //ID
payload.teller[0] = highByte(teller); //High Byte counter
payload.teller[1] = lowByte(teller); //Low Byte counter
payload.accxg[0] = highByte(accxg); //High Byte X accelerometer
payload.accxg[1] = lowByte(accxg); //Low Byte X accelerometer
payload.accyg[0] = highByte(accyg); //High Byte Y accelerometer
payload.accyg[1] = lowByte(accyg); //Low Byte Y accelerometer
payload.acczg[0] = highByte(acczg); //High Byte Z accelerometer
payload.acczg[1] = lowByte(acczg); //Low Byte Z accelerometer
So I send some values/results in 2 packets of 1 byte.
So I send some values/results in 2 packets of 1 byte.
Nonsense. Your payload object (struct ?) contains at least 9 bytes.
Determining where a packet that consists entirely of binary data starts and ends is extremely difficult. The only really successful way involves sending more than twice as much data as the packet contains.
It is FAR simpler to send ASCII data, with known start and end markers that do not appear in the data. Since the data consists entirely of the characters '0' through '9', the minus sign, '-', and the decimal point, '.', it is easy to choose start and end markers that are not in that set.
Sending "<12, 453, 12.567, 13.776, -45.78>", makes it extremely simple to determine where a packet starts and end, and where the tokens in the packet start and end. Each token can be converted to a value using atof() or atoi(), depending on the position of the token in the packet.
Sending ASCII data means sending more data than sending binary data without sync markers. How much slower the process is depends on how you are sending the data. Baud rate, how many sync markers, etc.