XBee to XBee communication (synchronization problem?)

Hi,

I need to establish secure communication between coordinator and few devices. Coordinator sends broadcast message with device’s ID in it and random number, and if device reads its own ID it needs to respond in following way:

  • device encrypts random number of coordinator, its own random number and its ID and sends message to coordinator
  • coordinator has encryption key, decrypts message, checks if its random number is correct, if it is than encrypt device’s random number and coordinator random number and send it back to device
  • device decrypts message and if random numbers are correct secure communication is established

So, in simple way:
-Coordinator sends broadcast message
-Device receives message and responds (if this is wanted device)
-Coordinator receives message and responds

But I’m having problems with synchronization, at least I think so :slight_smile: Communication establishes but after n attempts which takes too long (sometimes over a minute, sometimes 10 seconds), in example, device often receives wrong packet and vice versa. Since I’ll have 5-6 devices I need this process to be much quicker so I can establish secure communication between all devices in less than one minute, so let’s say 5-10 seconds for each device

At this moment my sketch covers establishing secure communication between coordinator and only one device

I would be really grateful if someone can check sketches below and try to improve them or tell me what can I do about it :slight_smile:

Thanks!

p.s. I’m using Arduino Xbee library

xbee_receive.ino (4.28 KB)

xbee_transmit.ino (3.1 KB)

I suspect that your problem starts with the coordinator broadcasting. Broadcast messages are low priority. They get sent only after the coordinator detects that there is nothing else being sent on the network.

Rather than using broadcast messages and hoping the correct end device/router node gets the message, you should look into API mode. The coordinator can send a message to a specific end device/router, and that end device/router can reply.

These messages, being between specific devices, are high priority messages, and are sent much sooner than broadcast messages.

Also, since it is the microprocessor on the radio that manages alerting the Arduino that the message is for it, rather than the Arduino deciding if the message is for it, the coding on the Arduino is far simpler.

The XBee library makes using API mode very easy.

Rob Faludi's book "Wireless Sensor Networks" belongs in your library. If it isn't already there, get it.

I suspect that your problem starts with the coordinator broadcasting

that's what I'm thinking also

Rather than using broadcast messages and hoping the correct end device/router node gets the message, you should look into API mode. The coordinator can send a message to a specific end device/router, and that end device/router can reply.

I am using API mode... I would do that but I can't, because (in theory) I can have device with unknown address...I'm doing this for faculty project and it has to be done this way. I would gladly take all devices' addresses and send unicast messages to each of them, but as I said, I can't

is there a way for coordinator to find out which devices (addresses) are on its network, maybe? than I could pick up their addresses and send unicast messages

Rob Faludi's book "Wireless Sensor Networks" belongs in your library. If it isn't already there, get it.

I have it already, nothing in it is solving my problem :) but it was very helpful for other stuff

I would do that but I can't, because (in theory) I can have device with unknown address.

In theory, maybe, but not in practice. The coordinator knows when a device joins the network. It can record the new device's address then.

It can also, at any time, get a list of all devices on the network, and refresh that list.

is there a way for coordinator to find out which devices (addresses) are on its network, maybe?

Yes, and Rob has a section of the book that deals with the specific command to do this.

I have it already, nothing in it is solving my problem

I can't help but think, then, that perhaps you just don't understand how the material applies to your problem. But, we'll get there.

Yes, and Rob has a section of the book that deals with the specific command to do this.

ok, i really didn't notice it...i'll check this out

thanks

@PaulS: now I see you can discover all nodes by ATND command, but I have never used AT commands…I suppose I have to use RemoteAtCommandRequest() class, but I’m not sure how, help would be appreciated :frowning:

tried to google it, but didn’t find anything appropriate…sorry, I know I’m pain in the ass but this is very important to me

just bumping thread...any help how to use ATND command in XBee library would be appreciated