Networking methods
Last updated
Last updated
It is important to keep in mind that XBee networks are defined by the networking parameters. EveryXBee module within a network must share the same networking parameters. In the case of the XBee 868LP,every node in a network must have the same:
PAN ID
Channel mask
Preamble ID
The XBee 868LP provides a star topology to create a star network has a central node, which is linked to allother 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 itsheader. XBee 868LP supports long 64-bit addresses. A unique 64-bit IEEE source address is assigned at thefactory and can be read with the functions explained in the chapter related to MAC address.
XBee 868LP supports unicast and broadcast transmissions:
Unicast: The unicast mode is the only mode that supports acknowledgements (ACKs). When apacket is sent using unicast mode, the receiving module sends an affirmative response to thesending module. If the sending module does not receive the ACK, it will re-send the packet up to tentimes or until the ACK is received. To send a unicast message, the 64-bit receiver's address must beset correctly.
Broadcast: Used to transmit all modules in the same network. Any RF module within range willaccept 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 timesto ensure it is received. To send a broadcast message, the receiver address must be set to0x000000000000FFFF.
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 usefultool to set the payload of the packet to be sent. It is recommended to read the Waspmote FrameProgramming 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 thesending 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 iscalled, 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 ofnetwork nodes. Probably, after 3 or 4 (failed) retries, it does not make sense to keep on trying.
Parameter range: From 0 to 15. Default: 10.
Example of use:
Related variables:
_send_retries
→ stores the maximum number of application-level retries
Send packets in unicast mode:
https://development.libelium.com/waspmote/868lp-02-send-packets
Send packets in broadcast mode:
https://development.libelium.com/waspmote/868lp-04a-send-broadcast
Send packets using the expansion board:
https://development.libelium.com/waspmote/868lp-06a-expansion-board-send
Complete example, send packets in unicast mode and wait for a response:
The function receivePacketTimeout()
waits a period of time trying to receive a packet through the XBeemodule. 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 |
| Buffer to store the received packet |
| Specifies the length of the buffer contents |
| 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:
_payload[]
→ Buffer where the received packet is stored
_length
→ Length of the buffer
_srcMAC[0-7]
→ Source's MAC address
Receiving packets example:
https://development.libelium.com/waspmote/868lp-03-receive-packets
Receive packets in broadcast mode (the same procedure as if it was unicast mode):
https://development.libelium.com/waspmote/868lp-04b-receive-broadcast
Receive packets using the expansion board:
https://development.libelium.com/waspmote/868lp-06b-expansion-board-reception
Complete example, receive packets and send a response back to the sender:
https://development.libelium.com/waspmote/868lp-08b-complete-example-receive