Networking methods
Last updated
Last updated
It is important to keep in mind that XBee networks are defined by the networking parameters. Every XBee module within a network must share the same networking parameters. In the case of the XBee 900HP, every node in a network must have the same:
• PAN ID • Channel mask • Preamble ID
The XBee 900HP provides a star topology to create a network:
Star: a star network has a central node, which is linked to all
other nodes in the network. The central node gathers all data coming
from the network nodes
Every RF data packet sent over-the-air contains a Source Address and Destination Address field in its header. XBee 900HP supports long 64-bit addresses. A unique 64-bit IEEE source address is assigned at the factory and can be read with the functions explained in the chapter related to MAC address.
XBee 900HP supports unicast and broadcast transmissions:
Unicast: The unicast mode is the only mode that supports acknowledgements (ACKs). When a packet is sent using unicast mode, the receiving module sends an affirmative response to the sending module. If the sending module does not receive the ACK, it will re-send the packet up to ten times or until the ACK is received. To send a unicast message, the 64-bit receiver\'s address must be set correctly.
Broadcast: Used to transmit all modules in the same network. Any RF module within range will accept a packet that contains a broadcast address. When a packet is sent using broadcast mode, receiving modules do not send ACKs. All broadcast packets are automatically transmitted four times to ensure it is received. To send a broadcast message, the receiver address must be set to 0x000000000000FFFF.
The maximum data payload size is defined as follows:
Unicast
Broadcast
255 Bytes
255 Bytes
Figure: Maximum Payload Size
WaspFrame is a class that allows the user to create data frames with a specified format. It is a very useful tool to set the payload of the packet to be sent. It is recommended to read the Waspmote Frame Programming Guide in order to understand the XBee examples:
LINK PENDIENTE http://www.libelium.com/development/waspmote/documentation/data-frame-guide/
The function send()
sends a packet via XBee module.
Firstly, the destination address must be defined depending on the addressing mode:
Define unicast mode (must specify the destination MAC address). For
example:
Define broadcast mode:
Finally, there are different function prototypes depending on the data sent. It is possible to send text messages or binary data:
Send strings:
Send Waspmote Frames:
Send Array of bytes (it is mandatory to specify the length of the
data field):
The sending function implements application-level retries. By default, up to 3 retries are done in the case the sending process fails. If a different number of maximum retries is needed, the setSendingRetries()
function permits to do it. This function changes the value of the API variable. When a new send()
function is called, the new maximum number of retries will be used.
Keep in mind that using a high number of retries could lead to a longer execution time of the send()
function, which means more power consumption on Waspmote and less channel availability for the rest of network nodes. Probably, after 3 or 4 (failed) retries, it does not make sense to keep on trying.
Parameter range: From 0 to 10
Default: 3
Example of use:
Related variables:
xbee900HP._send_retries
→ stores the maximum number of application-level retries
Send packets in unicast mode:
https://development.libelium.com/waspmote/900hp-02-send-packets
Send packets in broadcast mode:
https://development.libelium.com/waspmote/900hp-04a-send-broadcast
Send packets using the expansion board:
https://development.libelium.com/waspmote/900hp-06a-expansion-board-send
Complete example, send packets in unicast mode and wait for a response:
https://development.libelium.com/waspmote/900hp-08a-complete-example-send
The function receivePacketTimeout()
waits a period of time trying to receive a packet through the XBee module. The period of time to wait is specified in millisecond units as input when calling the function.
The Waspmote API defines the following variables to store information from the received packets:
Variable
Description
uint8_t _payload[MAX_DATA]
Buffer to store the received packet
uint16_t _length
Specifies the length of the buffer contents
uint8_t _srcMAC[8]
Specifies the source MAC address when a packet is received
When this function is called, several answers might be expected:
\'0\' → OK: The command has been executed with no errors \'1\' → Error: timeout when receiving answer \'2\' → Error: Frame Type is not valid \'3\' → Error: Checksum byte is not available \'4\' → Error: Checksum is not correct \'5\' → Error: Error escaping character in checksum byte \'6\' → Error: Error escaping character within payload bytes \'7\' → Error: Buffer full. not enough memory space
Example of use:
Related variables:
xbee900HP._payload[]
→ Buffer where the received packet is stored
xbee900HP._length
→ Length of the buffer
xbee900HP._srcMAC[0-7]
→ Source\'s MAC address
Receiving packets example:
https://development.libelium.com/waspmote/900hp-03-receive-packets
Receive packets in broadcast mode (the same procedure as if it was unicast mode):
https://development.libelium.com/waspmote/900hp-04b-receive-broadcast
Receive packets using the expansion board:
https://development.libelium.com/waspmote/900hp-06b-expansion-board-reception
Complete example, receive packets and send a response back to the sender:
https://development.libelium.com/waspmote/900hp-08b-complete-example-receive