I need to comunicate several devices through a logical message bus, and I have several challenges:
The physical layer will be a combination of radio and wire (2 wires). Some devices can connect directly by a wire, others will not, and I am thinking about using XBee shields (ZigBee).
There will be several masters and several slaves.
The protocol must resolve collisions.
The communication must be safe (every message sent is received) and secure (encrypted).
The architecture is mesh.
The message structure will be "Device address + Instruction + Data" (several bytes long).
A protocol is a description of intention. The description can not resolve collisions. The implementation of that description/protocol may, or may not, be able to resolve collisions. Doing so is not easy.
The communication must be safe (every message sent is received) and secure (encrypted).
How will you know if a message is sent? How will you ensure that a master re-sends a request that fails to get through, or that a slave re-sends a reply that fails to get through? Which node will be responsible for all the checking?
Is encryption REALLY necessary? Encryption/decryption typically requires more resources than the Arduino has. What kind of data are you sending that requires encryption? Would sending the data in binary, rather than ASCII, work?
The message structure will be "Device address + Instruction + Data" (several bytes long).
Source address or destination address? How will the end-of-packet be identified?
A protocol is a description of intention. The description can not resolve collisions. The implementation of that description/protocol may, or may not, be able to resolve collisions. Doing so is not easy.
You are right, collisions will happen, as in Ethernet, but I need this to be transparent to upper layers... And developers. I wish I will even create a lib.
PaulS:
The communication must be safe (every message sent is received) and secure (encrypted).
How will you know if a message is sent? How will you ensure that a master re-sends a request that fails to get through, or that a slave re-sends a reply that fails to get through? Which node will be responsible for all the checking?
I am thinking in a "Take the bus / send message / receive confirmation / release the bus" mechanism (somehow like Ethernet http://www.javvin.com/protocolEthernet.html). If receiver is dead, abort after 3 tries.
I am thinking about using NewSoftSerial as a lower layer, because of the interrupt feature, but if it is too heavy it will be necesary to adapt it or code something from scratch.
PaulS:
Is encryption REALLY necessary? Encryption/decryption typically requires more resources than the Arduino has. What kind of data are you sending that requires encryption? Would sending the data in binary, rather than ASCII, work?
No, it is not. I have already dismissed that requirement.
PaulS:
The message structure will be "Device address + Instruction + Data" (several bytes long).
Source address or destination address? How will the end-of-packet be identified?
[/quote]
Fixed size packets: "Dest @ + Source @ + Fixed size data" (instruction is not relevant here)
Yep I know about 485, in fact that's what I'm using.
Signal + return.
I thought this meant 1 signal line.
With most 485 transceivers I don't think it's practical to detect clashes at the bit level which is a nice feature because the clash can be made non-destructive, ie the winner carries on and there's no loss of data.
I was doing bit-level detection but decided that byte-level detection was good enough, this means that by the time a clash is detected the damage is done and both transmitters will have to try again.
In my single-master protocol this is not very important, it might be for you though depending on how many masters there are and the frequency they want bus access.