Communication between 3 Xbee+arduino UNO

New to Arduino and overall programming world. I am working with 3 Xbee+arduino (Node). I am trying to establish one communication like below:

  1. Node A will send one encrypted message to Node B.
  2. Node B will send another encrypted message back to Node A after processing the 1st message
  3. Node A will decrypt this message and encrypt some part of it and send to Node C.
  4. Node C will decrypt this message and encrypt some part of it and send to Node A.

Problems facing:
While Only Node A and B are connected, they are communicating fine. But when I am trying to insert C in this network things get messy. I made the program so that Node C will show a message like "No Message found" if it doesn't get any message. Now in Node A (Node A is getting messages as string value, and I am putting it together after getting a whole message], I feel it is getting both the messages haphazardly from Node B and C [The part of "No Message found"] at the same time. And for this my communication shows nothing productive.

My Questions:

  1. Is there anyway to distinguish for Node A to take only Node B's message at a particular time? [How can I make node A to identify or distinguish between Node B and Node C message? FYI: A is getting all encrypted message]
  2. How can I stop Node B after a specific time and turn the Node C on after that time? So that their message won't collide.
  3. I tried to change delay times but it is not working, making the whole situation more unstable.

I have been trying to get this solved for hours, not going anywhere.

I am working with 3 Xbee

What kind of XBees? Series 1 (point to point) or Series 2 (mesh network)?

How are the XBees configured?

  1. Node A will send one encrypted message to Node B.
  2. Node B will send another encrypted message back to Node A after processing the 1st message
  3. Node A will decrypt this message and encrypt some part of it and send to Node C.
  4. Node C will decrypt this message and encrypt some part of it and send to Node A.

So, Node A is the coordinator and Nodes B and C are the end points in a mesh network? Or, are they all points in a point to multipoint topology?

How are you doing encrypting and decrypting?

  1. Is there anyway to distinguish for Node A to take only Node B's message at a particular time?

Yes, and no. You could have nodes B and C not send anything except in response to a request from Node A. Then, there would be no confusion over which node the message that A got came from.

If nodes B and C need to blab at any time, then things are more challenging. You need to use API mode, instead of AT mode, so that the packet contains the ID of the sender, and the whole packet is received together.

  1. How can I stop Node B after a specific time and turn the Node C on after that time? So that their message won't collide.

See above. The answer is linked to how the devices are communicating, which you haven't defined.

  1. I tried to change delay times but it is not working, making the whole situation more unstable.

What delay times? I don't see any delay() in your code (Hint, hint).

Thanks for taking time out for answering my queries.

What kind of XBees? Series 1 (point to point) or Series 2 (mesh network)?

I am using Series 1 Xbees.

So, Node A is the coordinator and Nodes B and C are the end points in a mesh network? Or, are they all points in a point to multipoint topology?

According to my steps they are point to point while communicating with each other. Problem is The Node A is communicating with two different entity in different time.

How are you doing encrypting and decrypting?

I am using a simple encryption and decryption algorithm like RC4/RC5.

Yes, and no. You could have nodes B and C not send anything except in response to a request from Node A. Then, there would be no confusion over which node the message that A got came from.

Problem is Node A is not only sending a request but sending some messages. The Nodes (B and C) are working with the messages and then sending feedback. I can't understand how to do this part.

Additionally, I have tried putting a straightforward identification for each of them along with encrypted message - which does not work. The reason is as before: The Node B and Node C are sending data as string buffer. And Node A is also receiving them as buffer. So, during the time of Serial.available() > 0 {} it is putting all of them haphazardly [e.g. a[0] from B, a[1] from C, a[2] from C, a[3] from B ...].

What delay times? I don't see any delay() in your code (Hint, hint).

I used different delay times in Node B and Node C to see whether they make any difference, which turns out they don't.

Will there be anyway to resolve the problem without implementing API? Tried many documents about API but all seem so ambiguous.

According to my steps they are point to point while communicating with each other. Problem is The Node A is communicating with two different entity in different time.

How? I wasn't asking about configuration just to by typing. I have carpal tunnel syndrome, and typing is not always easy. Post your code, and describe how you have the XBees configured.

Using Andrew Rapp's XBee library, with the XBees in API mode is one way to solve ALL of your issues.