Networking methods

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.

Maximum payload

The maximum data payload size is defined as follows:



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 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:


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


    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";
    xbee900HP.send( rx_address, data);
  • Send Waspmote Frames:

    xbee900HP.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};
    xbee900HP.send( rx_address, data, 5);

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:

Send packets in broadcast mode:

Send packets using the expansion board:

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 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:



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 = xbee900HP.receivePacketTimeout( 10000 );

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:

Receive packets in broadcast mode (the same procedure as if it was unicast mode):

Receive packets using the expansion board:

Complete example, receive packets and send a response back to the sender:

Last updated