Networking methods

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

Topology

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.

Addressing

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.

Maximum payload

The maximum data payload size is defined as follows:

Unicast

Broadcast

255 bytes

255 bytes

Figure: Maximum payload size

Sending data

Using Waspmote frame

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/

Sending function

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:

{
    char rx_address[] =0013A2004030F6BC”;
}
  • Define broadcast mode:

{
    char rx_address[] =000000000000FFFF”;
}

Finally, there are different function prototypes depending on the data sent. It is possible to send text messages or binary data:

  • Send strings:

{
    char data[] = “this_is_the_data_field”;
    xbee868LP.send( rx_address, data);
}
  • Send Waspmote Frames:

{
    xbee868LP.send( rx_address, frame.buffer, frame.length );
}
  • Send Array of bytes (it is mandatory to specify the length of the data field):

{
    uint8_t  data[5] = {0x00, 0x01, 0x54, 0x76, 0x23};
    xbee868LP.send( rx_address, data, 5);
}

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:

{
    xbee868LP.setSendingRetries(10);
}

Related variables:

_send_retries → stores the maximum number of application-level retries

Examples

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:

Receiving data

Receiving function

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

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:

{
    uint8_t  error;
    error = xbee868LP.receivePacketTimeout( 10000 );
}

Related variables:

_payload[] → Buffer where the received packet is stored _length → Length of the buffer _srcMAC[0-7] → Source's MAC address

Examples

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

Last updated