-21-
v7.1
Networking methods
7.5. Receiving Data
7.5.1. 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:
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
7.5.2. Examples
•
Receiving packets example:
http://www.libelium.com/development/waspmote/examples/868lp-03-receive-packets
•
Receive packets in broadcast mode (the same procedure as if it was unicast mode):
http://www.libelium.com/development/waspmote/examples/868lp-04b-receive-broadcast
•
Receive packets using the expansion board:
http://www.libelium.com/development/waspmote/examples/868lp-06b-expansion-board-reception
•
Complete example, receive packets and send a response back to the sender:
http://www.libelium.com/development/waspmote/examples/868lp-08b-complete-example-receive