Beruflich Dokumente
Kultur Dokumente
Networking Guide
Index
Document Version: v0.5 - 07/2011 Libelium Comunicaciones Distribuidas S.L.
INDEX
1. General Considerations......................................................................................................................................... 6
1.1. Waspmote Libraries ............................................................................................................................................................................................6 1.1.1. Waspmote XBee Files.........................................................................................................................................................................6 1.1.2. Constructor ...........................................................................................................................................................................................6 1.2. API Functions.........................................................................................................................................................................................................6 1.3. API extension.........................................................................................................................................................................................................7 1.4. Waspmote reboot ................................................................................................................................................................................................7 1.5. Constants pre-defined .......................................................................................................................................................................................7
2. Initialization ........................................................................................................................................................... 8
2.1. Initializing ...............................................................................................................................................................................................................8 2.2. Setting ON ..............................................................................................................................................................................................................8 2.3. Setting OFF ............................................................................................................................................................................................................9
7. Connectivity ......................................................................................................................................................... 21
7.1. Topologies ........................................................................................................................................................................................................... 21 7.2. ZigBee Architecture ......................................................................................................................................................................................... 22 -2v0.5
Index
7.2.1. ZigBee Device Objects ................................................................................................................................................................... 22 7.2.2. ZDO Management Plane............................................................................................................................................................... 22 7.2.3. Application Support Sub-layer (APS)........................................................................................................................................ 22 7.2.4. Network Layer ................................................................................................................................................................................... 22 7.2.5. Security Plane.................................................................................................................................................................................... 23 7.2.6. Application Framework ................................................................................................................................................................. 23 7.2.7. Service Access Points...................................................................................................................................................................... 23 7.2.8. Application Endpoints ................................................................................................................................................................... 23 7.2.9. Application Profiles ......................................................................................................................................................................... 23 7.2.10. Attributes ......................................................................................................................................................................................... 23 7.2.11. Clusters.............................................................................................................................................................................................. 24 7.2.12. Binding .............................................................................................................................................................................................. 24 7.2.13. Waspmote Application Level .................................................................................................................................................... 24 7.3. ZigBee Addressing ........................................................................................................................................................................................... 25 7.3.1. Device Addressing ........................................................................................................................................................................... 25 7.3.2. Application Layer Addressing ..................................................................................................................................................... 25 7.4. Connections........................................................................................................................................................................................................ 25 7.4.1. Broadcast ............................................................................................................................................................................................ 25 7.4.2. Unicast ................................................................................................................................................................................................. 25 7.4.3. Many to one ....................................................................................................................................................................................... 26 7.4.4. Parameters involved ....................................................................................................................................................................... 26 7.5. Discovering and Searching Nodes ............................................................................................................................................................. 27 7.5.1. Structure used in Discovery ......................................................................................................................................................... 27 7.5.2. Searching nodes............................................................................................................................................................................... 28 7.5.3. Node discovery to a specific node............................................................................................................................................. 29 7.6. Sending Data ...................................................................................................................................................................................................... 29 7.6.1. API Frame Structure ........................................................................................................................................................................ 29 7.6.2. Application Header ......................................................................................................................................................................... 29 7.6.3. Fragmentation .................................................................................................................................................................................. 30 7.6.4. Structure packetXBee..................................................................................................................................................................... 30 7.6.5. Sending without API header ....................................................................................................................................................... 30 7.6.6. Examples ............................................................................................................................................................................................. 30 7.7. Receiving Data ................................................................................................................................................................................................... 34 7.7.1. Examples ............................................................................................................................................................................................. 35
Index
9.1. Router Joining a Network .............................................................................................................................................................................. 41 9.1.1. Example ............................................................................................................................................................................................... 41 9.2. End Device Joining a Network ..................................................................................................................................................................... 41 9.2.1. Example ............................................................................................................................................................................................... 42 9.3. Router / End Device Wake Up from Reset Process ................................................................................................................................ 43 9.4. Channel Verification ......................................................................................................................................................................................... 43 9.4.1. Router Channel Verification ......................................................................................................................................................... 43 9.4.2. End Device Channel Verification ................................................................................................................................................ 43 9.5. Related Parameters .......................................................................................................................................................................................... 43 9.5.1. Association Indication.................................................................................................................................................................... 43 9.5.2. Number of Remaining Children ................................................................................................................................................. 44 9.5.3. Channel Verification ........................................................................................................................................................................ 44 9.5.4. Join Notification ............................................................................................................................................................................... 44 9.6. Node Discovery ................................................................................................................................................................................................. 45 9.6.1. Node Discovery ................................................................................................................................................................................ 45 9.6.2. Node Discovery Time...................................................................................................................................................................... 45 9.6.3. Node Discovery Options ............................................................................................................................................................... 46
Index
13.3.1. Trust Center ..................................................................................................................................................................................... 55 13.3.2. Managing Security Keys.............................................................................................................................................................. 55 13.4. Examples ........................................................................................................................................................................................................... 56 13.4.1. Configuring a network using security without a Trust Center ...................................................................................... 56 13.4.2. Configuring a network using security and the coordinator as a Trust Center ........................................................ 56
-5-
v0.5
General Considerations
1. General Considerations
1.1. Waspmote Libraries
1.1.1. Waspmote XBee Files
WaspXBeeCore.h ; WaspXBeeCore.cpp, WaspXBeeZB.h, WaspXBeeZB.cpp
1.1.2. Constructor
To start using Waspmote XBee library, an object from class WaspXBeeZB must be created. This object, called xbeeZB, is created inside Waspmote XBee library and it is public to all libraries. It is used through the guide to show how the Waspmote XBee library works. When creating this constructor, some variables are defined with a value by default.
Related Variables xbeeZB.sourceMacHigh[0-3] stores the 32 upper bits of MAC address xbeeZB.sourceMacLow [0-3] stores the 32 lower bits of MAC address When returning from xbeeZB.getOwnMacLow the related variable xbeeZB.sourceMacLow will be filled with the appropriate values. Before calling the function, the related variable is created but it is empty. Almost every function has a related variable, and it will be indicated when the function was explained. There are three error flags that are filled when the function is executed:
error_AT: it stores if some error occurred during the execution of an AT command function error_RX: it stores if some error occurred during the reception of a packet error_TX: it stores if some error occurred during the transmission of a packet
All the functions return a flag to know if the function called was successful or not. Available values for this flag:
0 : Success. The function was executed without errors and the variable was filled. 1 : Error. The function was executed but an error occurred while executing. 2 : Not executed. An error occurred before executing the function. -1 : Function not allowed in this module.
To store parameter changes after power cycles, it is needed to execute the writeValues function. Example of use
{ xbeeZB.writeValues(); // Keep values after rebooting }
-6-
v0.5
General Considerations
Related Variables xbeeZB.commandAT[0-100] stores the response given by the module up to 100 bytes
sent on each packet. This size shouldnt be bigger than 1500. it bigger.
DATA_MATRIX: it defines the data size for each fragment. As the maximum payload is 100bytes, there is no reason to make MAX_PARSE: it defines the maximum data that is received in each call to treatData. If more data are received, they will
be stored in the UART buffer until the next call to treatData. However, if the UART buffer is full, the following data will be written on the buffer, so be careful with this matter.
MAX_BROTHERS: it defines the maximum number of brothers that can be stored. MAX_FRAG_PACKETS: it defines the maximum number of fragments that can be received from a global packet. If a packet
is divided in more fragments, when it is detected all the fragments will be deleted and the packet will be discarded.
MAX_FINISH_PACKETS: it defines the maximum number of finished packets that can be stored. DATA_OFFSET: it is used as an input parameter in setDestinationParams. It specifies that the data given as a parameter must
be added at the end of the packet. It allows the generation of one packet from several calls to setDestinationParams with different types of data. are the data to send. It also sets the addresses to the packet.
DATA_ABSOLUTE: it is used as an input parameter in setDestinationParams. It specifies that the data given as a parameter XBEE_LIFO: it specifies the LIFO replacement policy. If one packet is received and the finished packets array is full, this policy
will free the previous packet received and it will store the data from the last packet. will free the first packet received and it will store the data from the last packet. will discard this packet.
XBEE_FIFO: it specifies the FIFO replacement policy. If one packet is received and the finished packets array is full, this policy XBEE_OUT: it specifies the OUT replacement policy. If one packet is received and the finished packets array is full, this policy
-7-
v0.5
Initialization
2. Initialization
Before starting to use a module, it needs to be initialized. During this process, the UART to communicate with the module has to be opened and the XBee switch has to be set on.
2.1. Initializing
It initializes all the global variables that will be used later. It returns nothing. The initialized variables are:
protocol : specifies the protocol used (802.15.4 in this case). freq : specifies the frequency used (2,4GHz in this case). model : specifies the model used. There are two possible models: Normal(2mW) or PRO(50mW). totalFragmentsReceived : specifies the number of fragments expected from a packet pendingPackets : specifies the packets pending of fragments to be completed pos : specifies the position to use in received packets discoveryOptions : specifies the options in Node Discovery awakeTime : specifies the time to be awake before go sleeping sleepTime : specifies the time to be sleeping scanChannels : specifies the channels to scan scanTime : specifies the time to scan each channel timeEnergyChannel : specifies the time the channels will be scanned encryptMode : specifies if encryption mode is enabled powerLevel : specifies the power transmission level timeRSSI : specifies the time RSSI LEDs are on sleepOptions : specifies the options for sleeping parentNA : specifies the address of the parent deviceType : specifies the type of the device extendedPAN : specifies the extended PAN ID maxUnicastHops : specifies the maximum number of hops in an Unicast transmission maxBroadcastHops : specifies the maximum number of hops in an Broadcast transmission stackProfile : specifies the stack of ZigBee protocol used joinTime : specifies the time the Coordinator allows nodes joining the network channelVerification : specifies if the router needs a Coordinator to maintain in the network joinNotification : specifies is a message is sent when a node joins the network aggregateNotification : specifies the time between consecutive aggregate route broadcast messages encryptOptions : specifies the options for encryption mode networkKey : specifies the network key powerMode : specifies the power mode used
Example of use
{ xbeeZB.init(ZIGBEE,FREQ2_4G,NORMAL); // initializes the variables }
2.2. Setting ON
It opens the UART and switches the XBee ON. The baud rate used to open the UART is defined on the library (38400bps by default). Example of use
{ xbeeZB.ON(); // Opens the UART and switches the XBee ON }
-8-
v0.5
Node Parameters
3. Node Parameters
When configuring a node, it is necessary to set some parameters which will be used lately in the network, and some parameters necessary for using the API functions.
Related Variables xbeeZB.sourceMacHigh[0-3] stores the 32 upper bits of MAC address xbeeZB.sourceMacLow [0-3] stores the 32 lower bits of MAC address
-9-
v0.5
Node Parameters
Related Variables xbeeZB.PAN_ID[0-7] stores the 64-bit Extended PAN ID NOTE: Extended PAN ID is used when a specific ID wants to be used, setting this parameter to a value different from zero will make the module only chooses this ID. If it is set to zero, any ID will be chosen.
Related Variables xbeeZB.extendedPAN[0-7] stores the 64-bit Operating Extended PAN ID NOTE: Operating Extended PAN ID is the current ID the module is working on. If Extended PAN ID is set to a value different from zero, both will have the same value. If Extended PAN ID is set to zero, the module will select randomly a value to use as PAN ID.
-10-
v0.5
Node Parameters
NOTE: Operating PAN ID is the current ID the module is working on, but specified only with 16 bits instead of using 64 bits. It is used to reduce overheads on application level tasks.
Related Variables xbeeZB.nodeID[0-19] stores the 20-byte max string Node Identifier
3.7. Channel
This parameter defines the frequency channel used by the module to transmit and receive. ZigBee works on 2.4GHz band, using 16 channels. Channel is selected by the Coordinator when starting the network, and it can not be modified.
Channel Number 0x0B Channel 11 0x0C Channel 12 0x0D Channel 13 0x0E Channel 14 0x0F Channel 15 0x10 Channel 16 0x11 Channel 17 0x12 Channel 18 0x13 Channel 19 0x14 Channel 20 0x15 Channel 21 0x16 Channel 22 0x17 Channel 23 0x18 Channel 24 0x19 Channel 25 0x1A Channel 26
Frequency 2,400 2,405 GHz 2,405 2,410 GHz 2,410 2,415 GHz 2,415 2,420 GHz 2,420 2,425 GHz 2,425 2,430 GHz 2,430 2,435 GHz 2,435 2,440 GHz 2,440 2,445 GHz 2,445 2,450 GHz 2,450 2,455 GHz 2,455 2,460 GHz 2,460 2,465 GHz 2,465 2,470 GHz 2,470 2,475 GHz 2,475 2,480 GHz
Supported by Normal / PRO Normal / PRO Normal / PRO Normal / PRO Normal / PRO Normal / PRO Normal / PRO Normal / PRO Normal / PRO Normal / PRO Normal / PRO Normal / PRO Normal / PRO Normal / PRO Normal Normal
-11-
v0.5
Node Parameters
Example of use:
{ xbeeZB.getChannel(); // Get Channel }
-12-
v0.5
Node Parameters
It selects the channel and PAN ID (both 64-bit and 16-bit) to start the network. It can allow routers and end devices to join the network. It can assist in routing data. It can not sleep. It has to be always awake.
It must join a ZigBee network before it can transmit, receive or route data. After joining, it can allow routers and end devices to join the network. After joining, it can route data. It can not sleep. It has to be always awake.
It must join a ZigBee network before it can transmit or receive data. It can not allow devices to join the network. It must always transmit and receive RF data through its parent. It can not route data. It can sleep.
In ZigBee networks, the coordinator must select a PAN ID (64-bit and 16-bit) and channel to start a network. After that, it behaves essentially like a router. The coordinator and routers can allow other devices to join the network and route data. After an end device joins a router or coordinator, it must be able to transmit or receive RF data through that router or coordinator. The router or coordinator that allowed the end device to join becomes its parent. Since the end device can sleep, the parent must be able to buffer or retain incoming data packets destined for the end device until it is able to wake up and receive the data.
-13-
v0.5
Packet Parameters
4. Packet Parameters
4.1. Structure used in packets
Packets are structured in API libraries using a defined structure called packetXBee. This structure has many fields to be filled by the user or the application: /************ IN ***********/ uint8_t macDL[4]; // 32b Lower Mac Destination uint8_t macDH[4]; // 32b Higher Mac Destination uint8_t mode; // 0=unicast ; 1=broadcast ; 2=cluster ; 3=synchronization uint8_t address_type; // 0=16B ; 1=64B uint8_t naD[2]; // 16b Network Address Destination char data[MAX_DATA]; // Data of the sent message. All the data here, even when > Payload uint16_t data_length; // Data sent length. Real used size of vector data[MAX_DATA] uint16_t frag_length; // Fragment length. Used to send each fragment of a big packet uint8_t SD; // Source Endpoint uint8_t DE; // Destination Endpoint uint8_t CID[2]; // Cluster Identifier uint8_t PID[2]; // Profile Identifier uint8_t MY_known; // 0=unknown net address ; 1=known net address uint8_t opt; // options: 0x08=Multicast transmission /******** APLICATION *******/ uint8_t packetID; // ID for the packet uint8_t macSL[4]; // 32b Lower Mac Source uint8_t macSH[4]; // 32b Higher Mac Source uint8_t naS[2]; // 16b Network Address Source uint8_t macOL[4]; // 32b Lower Mac Origin Source uint8_t macOH[4]; // 32b Higher Mac Origin Source uint8_t naO[2]; // 16b Network Address origin char niO[20]; // Node Identifier Origin. To use in transmission, it must finish #. uint8_t RSSI; // Receive Signal Strength Indicator uint8_t address_typeS;// 0=16B ; 1=64B uint8_t typeSourceID; // 0=naS ; 1=macSource ; 2=NI uint8_t numFragment; // Number of fragment to order the global packet uint8_t endFragment; // Specifies if this fragment is the last fragment of a global packet uint8_t time; // Specifies the time when the first fragment was received /******** OUT **************/ uint8_t deliv_status; // Delivery Status uint8_t discov_status; // Discovery Status uint8_t true_naD[2]; // Network Address the packet has been really sent to uint8_t retries; // Retries needed to send the packet
macDL & macDH mode
64-bit destination address. It is used to specify the MAC address of the destination node. Transmission mode chosen to transmit that packet. Available values : 0 : Unicast transmission 1 : Broadcast transmission 2 : Application binding transmission, using clusters and endpoints 3 : Synchronization packet Address type chosen, between 16-bit and 64-bit addresses. Always set to 1 in ZigBee. 0 : 16-bit address 1 : 64-bit address -14v0.5
address_type
Packet Parameters
naD
16-bit Destination Network Address. It is used in data transmissions. Data to send in the packet. It is used to store the data to send in unicast or broadcast transmissions to other nodes. All the data to send must be stored in this field. The API function responsible for sending data will take care of fragmenting the packet if it exceeds the maximum payload. Its max size is defined by MAX_DATA, a constant defined in API libraries. Data really sent in the packet. Due to data field is an array of max defined size, each packet could have a different size. Fragment data length. It is used by the API function responsible for sending data in the internal process of fragmenting packets. Source Endpoint. Destination Endpoint. Cluster ID. Profile ID. It specifies if the 16-bit address is known before sending the packet. Available values are: 0 : 16-bit address unknown 1 : 16-bit address known Options for the transmitted packet. Options available in ZigBee are: 0x08: Enables Multicast transmission. ID used in the application level to identify the packet. It is filled by the transmitter and it is used by the receiver to manage the received packet and the pending fragments. 64-bit Source MAC Address. It is filled by the receiver, and it specifies the address of the node which has delivered the message. It is useful in multi-hops networks to know which node has delivered the message. 16-bit Source Network Address. It is filled by the receiver, and it specifies the address of the node which has delivered the message. It is useful in multi-hops networks to know which node has delivered the message. 64-bit Origin MAC Address. It is filled by the receiver, and it specifies the address of the node which has sent originally the packet. It is useful in multi-hops networks to know which node has created and sent the message. 16-bit Origin Network Address. It is filled by the receiver, and it specifies the address of the node which has sent originally the packet. It is useful in multi-hops networks to know which node has created and sent the message. Origin Node Identifier. It is filled by the receiver, and it specifies the node identifier of the node which has sent originally the packet. It is useful in multi-hops networks to know which node has created and sent the message. -15v0.5
data
data_length
frag_length
SD
DE
CID
PID
MY_known
opt
packetID
naS
naO
niO
Packet Parameters
RSSI
Received Signal Strength Indicator. It specifies in dBm the RSSI of the last received packet via RF. In a fragmented packet, it contains the average of all received fragments RSSI. Address type used to send the packet by the transmitter. In ZigBee, it is always set to 1. 0 : 16-bit transmission 1 : 64-bit transmission Source ID type used to send the packet. It is filled by the transmitter and it specifies the ID at application level. 0 : 16-bit Network Address ID 1 : 64-bit MAC Address ID 2 : Node Identifier ID Number of the fragment indicating the position in the fragmented packet. It is filled by the transmitter to indicate if the sent fragment is the first, second or last one. Specifies if the sent fragment is the last fragment of a packet. It is filled by the transmitter. Specifies the time when the first fragment was received. Delivery status returned when transmitting a packet. It specifies the success or failure reason of the last packet sent: 0x00 : Success 0x02 : CCA failure 0x15 : Invalid Destination Endpoint 0x21 : Network ACK failure 0x22 : Not Joined to the Network 0x23 : Self-addressed 0x24 : Address not found 0x25 : Route not found
address_typeS
typeSourceID
numFragment
endFragment time
deliv_status
discov_status
Discovery stats returned when transmitting a packet. It specifies the processes executed to find the destination node: 0x00 : No Discovery Overhead 0x01 : Address Discovery 0x02 : Route Discovery 0x03 : Address and Route Discovery true_naD 16-bit Network Address the packet was delivered to (if success). If not success, this address matches the 16-bit address given in the transmission packet.
retries
66Bytes 74Bytes
-16-
v0.5
Packet Parameters
Related Variables xbeeZB.maxPayloadBytes[0-1] stores the maximum payload is available at the moment
-17-
v0.5
NOTE: XBee-PRO maximum value is +17dBm and XBee-PRO(International) is +10dBm NOTE2: dBm is a standard unit to measure power level taking as reference a 1mW signal. Values expressed in dBm can be easily converted to mW using the next formula: mW = 10^(value dBm/10) Graphics about transmission power are exposed next:
dBm
mW
Example of use
{ xbeeZB.setPowerLevel(0); // Set Power Output Level to the minimum value xbeeZB.getPowerLevel(); // Get Power Output Level }
-18-
v0.5
dBm
mW
Related Variables xbeeZB.valueRSSI stores the RSSI of the last received packet The ideal working mode is getting maximum coverage with the minimum power level. Thereby, a compromise between power level and coverage appears. Each application scenario will need some tests to find the best combination of both parameters.
-19-
v0.5
Radio Channels
6. Radio Channels
XBee ZigBee module works on 2.4GHz band, so there are 16 channels that can be used. These channels are explained in Chapter 2. When starting a network, the Coordinator performs an energy scan to find the channel with less energy. When joining a network, the router or end device performs an active scan to find any coordinator or router available to join. There are some parameters involved in this channel election.
-20-
v0.5
Connectivity
7. Connectivity
7.1. Topologies
ZigBee provides different topologies to create a network:
Star: a star network has a central node, which is linked to all other nodes in the network. All messages travel via the central
node.
Figure 7.1 : Point-to-Multipoint Topology Tree: a tree network has a top node with a branch/leaf structure below. To reach its destination, a message travels up the
ZigBee is aimed at working on star or tree. Peer-to-Peer topologies does not have sense since only End Devices can sleep. Mesh topologies may be found interesting, but due to only End Devices can sleep, a real mesh can not be done. To work on a pure (p2p) mesh topology, it is recommended to choose another protocol as DigiMesh.
-21-
v0.5
Connectivity
-22-
v0.5
Connectivity
7.2.10. Attributes
Each data item that passes between devices of a ZigBee network is called an attribute. Each attribute has its own unique identifier. For example, a switch device can have an attribute with identifier OnOff whose value represents the action to be performed: On (0xFF), Off (0x00), Toggle (0xF0). -23v0.5
Connectivity
7.2.11. Clusters
A number of attributes are grouped into a cluster, where each cluster has its own unique identifier. For example, for an HCL Switch Remote Control (SRC) device, there is a cluster with the identifier OnOffSRC containing the attribute OnOff. Clusters may be mandatory or optional for a device to support. An Application Profile can have several associated clusters. For example, the Home Controls-Lighting (HCL) profile includes the clusters OnOffSRC and ProgramSRC for an SRC device. The Application Profile defines which clusters are mandatory and which clusters are optional for the device. The clusters supported by a device determine the other devices to which it can communicate. For example, for two devices operating together in temperature monitoring and control, both of them must support compatible clusters concerned with temperature. The sensor device must have an output cluster containing the monitored temperature, and the controller must support an input cluster which can use a temperature to make control decisions.
7.2.12. Binding
At a high level, binding is the process of establishing a relationship between nodes that can communicate in a meaningful way, for example, linking switches with lights. It therefore determines the overall functionality of the network. The information is exchanged as clusters - in order to bound two applications, they must have compatible clusters. For example, for two applications in different nodes for temperature control, one must be able to generate an output cluster related to temperature, and the other must be able to consume it as an input cluster. The binding between two applications is specified by:
The source network address and endpoint of the application where the cluster is generated The destination network address and endpoint of the receiving application The cluster ID of the cluster being sent between them
Bindings are stored in a binding table. This lists the cluster IDs, the network addresses and application endpoints for each association. The types of binding that can be achieved are one-to-one, one-to-many, many-to-one and many-to-many:
One-to-one: A binding in which an endpoint is bound to one (and only one) other endpoint . One-to-many: A binding in which a source endpoint is bound to more than one destination endpoint . Many-to-one: A binding in which more than one source endpoint is bound to a single destination endpoint . Many-to-many : A binding in which more than one source endpoint is bound to more than one destination endpoint.
Bindings (the binding entries table) can be stored either on the network Coordinator (indirect binding) or locally on the node generating the source output cluster (direct binding).
-24-
v0.5
Connectivity
unique to each node in the network, but it may change. ZigBee requires data to be sent to the 16-bit network address of the destination device. This requires the 16-bit network address to be discovered before transmitting the data, executing a process called Address Discovery. 64-bit Address : Each node contains a unique 64-bit address. The 64-bit address uniquely identifies a node and is therefore permanent. It is assigned by the manufacturer and it can not be changed.
7.4. Connections
All data packets are addressed using both device and application layer addressing fields. Data can be sent as a broadcast, or unicast transmission.
7.4.1. Broadcast
Broadcast transmissions within the ZigBee protocol are intended to be propagated throughout the entire network such that all nodes receive the transmission. To accomplish this, all devices that receive a broadcast transmission will retransmit the packet 3 times. Each node that transmits the broadcast will also create an entry in a local broadcast transmission table. This entry is used to keep track of each received broadcast packet to ensure the packets are not endlessly transmitted. For each broadcast transmission, the ZigBee stack must reserve buffer space for a copy of the data packet. Since broadcast transmissions are retransmitted by each device in the network, broadcast messages should be used sparingly. Broadcast transmissions are sent using a 64-bit address of 0x0000FFFF. Any RF module in the PAN will accept a packet that contains a broadcast address. When configured to operate in Broadcast Mode, receiving modules do not send ACKs (Acknowledgments). See examples in chapter 7.6 for further information.
7.4.2. Unicast
Unicast ZigBee transmissions are always addressed to the fact that 16-bit address of the destination device. However, only the 64-bit address of a device is permanent due to the 16-bit address can change. Therefore, ZigBee devices may employ network address discovery to identify the current 16-bit address that corresponds to a known 64-bit address, and route discovery to establish a route. See examples in chapter 7.6 for further information.
Network Address Discovery
-25-
v0.5
Connectivity
Data transmissions are always sent to the 16-bit network address of the destination device. However, since the 64-bit address is unique to each device and is generally known, ZigBee devices must discover the network address that was assigned to a particular device when it joined the PAN before they can transmit data. To do this, the device initiating a transmission sends a broadcast network address discovery transmission throughout the network. This packet contains the 64-bit address of the device the initiator needs to send data to. Devices that receive this broadcast transmission check to see if their 64-bit address matches the 64-bit address contained in the broadcast transmission. If the addresses match, the device sends a response packet back to the initiator, supplying the network address of the device with the matching 64-bit address. When this response is received, the initiator can then transmit data.
Route Discovery
ZigBee employs mesh routing to establish a route between the source device and the destination. Mesh routing allows data packets to traverse multiple nodes (hops) in a network to route data from the source to its destination. Routers and coordinators can participate in establishing routes between source and destination devices using a process called route discovery. The Route discovery process is based on the AODV (Ad-hoc On demand Distance Vector routing) protocol.
ZigBee includes acknowledgment packets at both the Mac and Application Support (APS) layers. When data is transmitted to a remote device, it may traverse multiple hops to reach the destination. As data is transmitted from one node to its neighbour, an acknowledgment packet (ACK) is transmitted in the opposite direction to indicate that the transmission was successfully received. If the ACK is not received, the transmitting device will retransmit the data up to 4 times. This ACK is called the Mac layer acknowledgment. In addition, the device that originated the transmission expects to receive an acknowledgment packet (ACK) from the destination device. This ACK will traverse the same path that the data traversed, but in the opposite direction. If the originator fails to receive this ACK, it will retransmit the data, up to 2 times until an ACK is received. This ACK is called the ZigBee APS layer acknowledgment.
It sets the maximum unicast hops limit and the unicast timeout. The timeout is computed as: (50*NH)+100ms. The default value of 0x1E (1,6seconds) is enough to traverse around 8 hops. Example of use:
{ xbeeZB.setMaxUnicastHops(0x03); // Set max unicast hops limit xbeeZB.getMaxUnicastHops(); // Get max unicast hops limit }
-26-
v0.5
Connectivity
Related Variables xbeeZB.maxUnicastHops stores the max unicast hops limit
Maximum Broadcast Hops
It sets the maximum number of hops for each broadcast data transmission. Example of use:
{ xbeeZB.setMaxBroadcastHops(0x10); // Set max broadcast hops limit xbeeZB.getMaxBroadcastHops(); // Get max broadcast hops limit }
Time between consecutive aggregate route broadcast messages. Using this parameter, many to one transmissions will be enabled. Example of use:
{ xbeeZB.setAggregateNotification(0x20); // Set time between aggregate messages xbeeZB.getAggregateNotification (); // Get time between aggregate messages }
// 16b Network Address // 32b Lower Mac Source // 32b Higher Mac Source // Node Identifier // Parent 16b Network Address // Device Type: 0=End 1=Router 2=Coord // Status: Reserved // Profile ID // Manufacturer ID // Receive Signal Strength Indicator
16-bit Network Address of the reported module. 64-bit MAC Source Address of the reported module.
SH & SL
-27-
v0.5
Connectivity
NI
Node Identifier of the reported module Parent 16-bit network address. It specifies the 16-bit network address of its parent. Device Type. It specifies if the node is a Coordinator, Router or End Device. Status. Reserved by xbeeZB. Profile ID. Profile ID used for application layer addressing. Manufacturer ID. ID set by the manufacturer to identify the module. Not returned in ZigBee.
PMY
DT
ST
PID
MID
RSSI
To store the found nodes, an array called scannedBrothers has been created. It is an array of structures Node. A constant called MAX_BROTHERS is defined to specify the maximum number of found brothers. A variable called totalScannedBrothers is defined to indicate the number of brothers discovered. Using this variable as the index in the scannedBrothers array allows to read the information discovered about each node. Example of use:
{ xbeeZB.scanNetwork(); // Discovery nodes }
Related variables xbeeZB.totalScannedBrothers stores the number of brothers discovered. xbeeZB.scannedBrothers Node structure array that stores in each position the info related to each found node. For example, xbeeZB.scannedBrothers[0].DT should store the Device Type of the first found node.
Related variables paq_sent Stores the 16-bit and 64-bit addresses of the searched. For example paq_sent->MY[0] & paq_sent->MY[1] stores the 16-bit NA of the searched node.
-28-
v0.5
Connectivity
Related variables xbeeZB.totalScannedBrothers stores the number of brothers discovered. In this case its value will be 1 xbeeZB.scannedBrothers Node structure array that stores in each position the info related to each found node. It will store in the first position of the array the information related to the found brother
-29-
v0.5
Connectivity
To add some application level features to the receiver, some fields have been added like Application ID or Source ID. Source ID identifies the origin node which created the packet. It is useful in multi-hops networks, to identify the origin node to an answer. To identify this node, three Source IDs can be chosen:
MAC Address: 64-bit MAC Source Address Network Address: 16-bit Network Address Node Identifier: 20-byte max string NI
The different fields of this header and its structure inside the API Frame Structure are:
Application ID: it specifies the ID at application level. It allows to identify a single packet among several packets in the Fragment Number: it specifies the position of the fragment in its packet. The first fragment shows the total number of
receiver.
fragments of the packet. First Fragment Indicator [#]: optional field that is included in the first fragment to indicate that it is the first fragment. Source Type ID: it specifies the source ID type chosen. The possibilities are MAC, 16-bit or NI. Source ID: it specifies the source ID of the origin node. It is related to the previous field. Data: it stores the data sent in each fragment or packet.
7.6.3. Fragmentation
When the data length of a packet exceeds the maximum payload, the packet has to be fragmented to reach the destination. If the packet is not fragmented, the module will discard it before transmission. NOTE: Due to restricted memory in Waspmote, the maximum recommended data in a packet is 1500 Bytes (to be fragmented).
The API function takes care of the rest of the process, returning a success or failure to the process.
7.6.6. Examples
To simplify the examples and make them easy to read, there are some lines that dont work exactly in C/C++.
Sending a packet of 50 bytes without API header { char* data; for(int c=0;c<50;c++) // Set the data { data[c]=A; } xbeeZB.send(0013A2004030F66A,data); }
-30-
v0.5
Connectivity
Sending a 50-bytes data packet. Unicast. 16-bit Network Address Unknown. 16-bit NA Source ID Type. { packetXBee* paq_sent; // create packet to send char* data; paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee)); paq_sent->mode=UNICAST; // set Unicast mode paq_sent->MY_known=0; // set 16-bit NA unknown paq_sent->packetID=0x52; // set ID application level paq_sent->opt=0x00; // set options. No option selected. for(int c=0;c<50;c++) // Set the data { data[c]=A; } xbeeZB.setOriginParams(paq_sent, 1221, MY_TYPE); xbeeZB.setDestinationParams(paq_sent, 0013A2004030F686, data, MAC_TYPE, DATA_ABSOLUTE); state=xbeeZB.sendXBee(paq_sent); // Call function responsible to send data if(!state) { delivery_status=paq_sent->deliv_status; discovery_status=paq_sent->discov_status; delivered_address=paq_sent->true_naD; retries=paq_sent->retries; } free(paq_sent); paq_sent=NULL; }
The data field in the API frame generated by the function sendXBee is:
Figure 7.8 : API Application Header Sending a 50-bytes data packet. Unicast. 16-bit Network Address Known. 64-bit MAC Source ID Type. { packetXBee* paq_sent; // create packet to send char* data; paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee)); paq_sent->mode=UNICAST; // set Unicast mode paq_sent->MY_known=1; // set 16-bit NA known paq_sent->packetID=0x52; // set ID application level paq_sent->opt=0x00; // set options. No option selected. for(int c=0;c<50;c++) // Set the data { data[c]=A; } xbeeZB.setOriginParams(paq_sent, 0013A2004030F66A, MAC_TYPE); xbeeZB.setDestinationParams(paq_sent, 1221, data, MY_TYPE); xbeeZB.setDestinationParams(paq_sent, 0013A2004030F686, data, MAC_TYPE, DATA_ABSOLUTE); state=xbeeZB.sendXBee(paq_sent); // Call function responsible to send data if(!state) { delivery_status=paq_sent->deliv_status; discovery_status=paq_sent->discov_status; delivered_address=paq_sent->true_naD; retries=paq_sent->retries; } free(paq_sent); paq_sent=NULL;
-31-
v0.5
Connectivity
}
The data field in the API frame generated by the function sendXBee will be:
Figure 7.9 : API Application Header Sending a 50-bytes data packet. Broadcast. Node Identifier Source ID Type. { packetXBee* paq_sent; // create packet to send char* data; paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee)); paq_sent->mode=BROADCAST; // set Broadcast mode paq_sent->MY_known=0; // set 16-bit NA unknown paq_sent->packetID=0x52; // set ID application level paq_sent->opt=0x00; // set options. No option selected. for(int c=0;c<50;c++) // Set the data { data[c]=A; } xbeeZB.setOriginParams(paq_sent, forrestNode-01, NI_TYPE); xbeeZB.setDestinationParams(paq_sent, 000000000000FFFF, data, MAC_TYPE, DATA_ABSOLUTE); state=xbeeZB.sendXBee(paq_sent); // Call function responsible to send data if(!state) { delivery_status=paq_sent->deliv_status; discovery_status=paq_sent->discov_status; delivered_address=paq_sent->true_naD; retries=paq_sent->retries; } free(paq_sent); paq_sent=NULL; }
The data field in the API frame generated by the function sendXBee will be:
Figure 7.10 : API Application Header Sending a 200-bytes data packet. Unicast 16-bit Network Address Unknown. 16-bit Source ID Type. { packetXBee* paq_sent; // create packet to send char* data; paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee)); paq_sent->mode=UNICAST; // set Unicast mode paq_sent->MY_known=0; // set 16-bit NA unknown paq_sent->packetID=0x52; // set ID application level paq_sent->opt=0x00; // set options. No option selected. for(int c=0;c<200;c++) // Set the data { data[c]=A; } xbeeZB.setOriginParams(paq_sent, 1221, MY_TYPE); xbeeZB.setDestinationParams(paq_sent, 0013A2004030F686, data, MAC_TYPE, DATA_ABSOLUTE);
-32-
v0.5
Connectivity
state=xbeeZB.sendXBee(paq_sent); // Call function responsible to send data if(!state) { delivery_status=paq_sent->deliv_status; discovery_status=paq_sent->discov_status; delivered_address=paq_sent->true_naD; retries=paq_sent->retries; } free(paq_sent); paq_sent=NULL; }
Due to the large amount of data, the packet needs to be fragmented before being sent. The maximum data payload is 74Bytes (see chapter 3) and the application header will occupy a maximum of 6 Bytes (in the first fragment), so there will be three fragments, sending 68Bytes(data) in first fragment, 69Bytes(data) in second fragment and 63Bytes(data) in third fragment.
Figure 7.11: API Application Header Sending a 50-bytes data packet. Application Layer Addressing. 64-bit Source ID Type
When using application layer addressing, the modules use the structure above to send the packets. Application header is inserted in RF Data field as in device addressing examples.
{ packetXBee* paq_sent; // create packet to send char* data; paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee)); paq_sent->mode=CLUSTER; // set Application Layer Addressing paq_sent->SD=0x12; // set source endpoint paq_sent->DE=0x13; // set destination endpoint
-33-
v0.5
Connectivity
paq_sent->CID={0x14,0x15}; // set Cluster Identifier ** paq_sent->PID={0x16,0x17}; // set Profile ID ** paq_sent->MY_known=1; // set 16-bit NA known paq_sent->packetID=0x52; // set ID application level paq_sent->opt=0x00; // set options. No option selected. for(int c=0;c<50;c++) // Set the data { data[c]=A; } xbeeZB.setOriginParams(paq_sent, 0013A2004030F66A, MAC_TYPE); xbeeZB.setDestinationParams(paq_sent, 1221, data, MY_TYPE, DATA_ABSOLUTE); xbeeZB.setDestinationParams(paq_sent, 0013A2004030F686, data, MAC_TYPE, DATA_ABSOLUTE); state=xbeeZB.sendXBee(paq_sent); // Call function responsible to send data if(!state) { delivery_status=paq_sent->deliv_status; discovery_status=paq_sent->discov_status; delivered_address=paq_sent->true_naD; retries=paq_sent->retries; } free(paq_sent); paq_sent=NULL; } ** Code Simplification. Arrays must be filled one by one.
When using application layer addressing, both destination address(MAC & NA) and application address(SD, DE, CID, PID) should be set in the packet. A explicit addressing frame is sent when using application layer addressing which is a bit different from normal transmit frame and includes all the fields above. The data field in the API frame generated by the function sendXBee will be:
packets.
When a packet or fragment is received, the algorithm used in reception API function is: 1. Check if the fragment is a new packet or belongs to an existing packet. If it is a new packet, an structure index is created and linked to the array index previously created. The application level information is stored in that structure. If it belongs to -34v0.5
Connectivity
an existing packet, it doesnt store any information. Create an structure matrix and link it to the corresponding position in the multidimensional matrix array. The position is calculated upon the information stored in the index array. Store the data in the corresponding position of the matrix. Check if the packet is complete. If the packet is complete, a packetXBee structure is created and linked to the corresponding position in the array of finished packets. The different fragments are ordered and copied to this structure, as the application level information. The index and row of matrix are released, to free memory. If the packet is not complete, goes to next step. Exit the function.
2. 3. 4.
5.
When a packet is received via RF, the module will send the data via UART, so it is recommended to check periodically if data is available. The API function responsible of reading packets can read more than one fragment, but the XBee module may overflow its buffer, so it is recommended to read packets one by one. When a packet is completed, it will be stored in a finished packets array called packet_finished. This array should be used by the application to read the received packet. A variable called pos is used to know if there are pending received packets : if pos=0, there is no packet available ; if pos>0, there will be as many pending packets as its value (pos=3, 3 pending packets).
7.7.1. Examples
Received 50-byes data packet. Unicast. 16-bit NA Source ID Type { state=xbeeZB.treatData(); // Read a packet when XBee has noticed it to us if( xbeeZB.pos>0 ) { /* Available info: (there are more available information) */ network_address[0]=packet_finished[xbeeZB.pos-1]->naS[0]; network_address[1]=packet_finished[xbeeZB.pos-1]->naS[1]; } }
Available Information packet_finished[xbeeZB.pos-1]->naS : stores the 16-bit network address of the sender. packet_finished[xbeeZB.pos-1]->macSH : stores the 32 upper bits of MAC sender address. packet_finished[xbeeZB.pos-1]->macSL : stores the 32 lower bits of MAC sender address. packet_finished[xbeeZB.pos-1]->naO : stores the 16-bit network address of the origin sender. packet_finished[xbeeZB.pos-1]->mode : stores the transmission mode. Unicast in this case. packet_finished[xbeeZB.pos-1]->data : stores the data received. Max size MAX_DATA. packet_finished[xbeeZB.pos-1]->packetID : stores the packet ID of the received message. 0x52 in this case. packet_finished[xbeeZB.pos-1]->typeSourceID : stores the source type ID used in the message. After receiving the packet, due to there is only one fragment, it will be completed, so variable pos will be greater than zero. This variable is used to index the array where the received packet is stored. The information that has been stored is indicated in the example.
Received 50-bytes data packet. Unicast. 64-bit MAC Address Source ID Type { state=xbeeZB.treatData(); // Read a packet when XBee has noticed it to us if( xbeeZB.pos>0 ) { /* Available info: (there are more available information) */ source_address[0]=packet_finished[xbeeZB.pos-1]->macSH[0]; ... source_address[3]=packet_finished[xbeeZB.pos-1]->macSH[3]; } }
Connectivity
packet_finished[xbeeZB.pos-1]->naS : stores the 16-bit network address of the sender. packet_finished[xbeeZB.pos-1]->macSH : stores the 32 upper bits of MAC sender address. packet_finished[xbeeZB.pos-1]->macSL : stores the 32 lower bits of MAC sender address. packet_finished[xbeeZB.pos-1]->macOH : stores the 32 upper bits of MAC origin sender address. packet_finished[xbeeZB.pos-1]->macOL : stores the 32 lower bits of MAC origin sender address. packet_finished[xbeeZB.pos-1]->mode : stores the transmission mode. Unicast in this case. packet_finished[xbeeZB.pos-1]->data : stores the data received. Max size MAX_DATA. packet_finished[xbeeZB.pos-1]->packetID : stores the packet ID of the received message. 0x52 in this case. packet_finished[xbeeZB.pos-1]->typeSourceID : stores the source type ID used in the message. After receiving the packet, due to there is only one fragment, it will be completed, so variable pos will be greater than zero. This variable is used to index the array where the received packet is stored. The information that has been stored is indicated in the example.
Received 50-bytes data packet. Broadcast. Node Identifier Source ID Type { state=xbeeZB.treatData(); // Read a packet when XBee has noticed it to us if( xbeeZB.pos>0 ) { /* Available info: (there are more available information) */ source_address[0]=packet_finished[xbeeZB.pos-1]->macSH[0]; ... source_address[3]=packet_finished[xbeeZB.pos-1]->macSH[3]; } }
Available Information packet_finished[xbeeZB.pos-1]->naS : stores the 16-bit network address of the sender. packet_finished[xbeeZB.pos-1]->macSH : stores the 32 upper bits of MAC sender address. packet_finished[xbeeZB.pos-1]->macSL : stores the 32 lower bits of MAC sender address. packet_finished[xbeeZB.pos-1]->niO : stores 20-byte max string used to Node Identifier of the origin sender packet_finished[xbeeZB.pos-1]->mode : stores the transmission mode. Unicast in this case. packet_finished[xbeeZB.pos-1]->data : stores the data received. Max size MAX_DATA. packet_finished[xbeeZB.pos-1]->packetID : stores the packet ID of the received message. 0x52 in this case. packet_finished[xbeeZB.pos-1]->typeSourceID : stores the source type ID used in the message. After receiving the packet, due to there is only one fragment, it will be completed, so variable pos will be greater than zero. This variable is used to index the array where the received packet is stored. The information that has been stored is indicated in the example.
Received 200-bytes data packet. Unicast. 16-bit NA Source ID Type { state=xbeeZB.treatData(); // Read a packet when XBee has noticed it to us if( xbeeZB.pos>0 ) { /* Available info: (there are more available information) */ network_address[0]=packet_finished[xbeeZB.pos-1]->naS[0]; network_address[1]=packet_finished[xbeeZB.pos-1]->naS[1]; } }
Available Information packet_finished[xbeeZB.pos-1]->naS : stores the 16-bit network address of the sender. packet_finished[xbeeZB.pos-1]->macSH : stores the 32 upper bits of MAC sender address. packet_finished[xbeeZB.pos-1]->macSL : stores the 32 lower bits of MAC sender address. packet_finished[xbeeZB.pos-1]->naO : stores the 16-bit network address of the origin sender. -36v0.5
Connectivity
packet_finished[xbeeZB.pos-1]->mode : stores the transmission mode. Unicast in this case. packet_finished[xbeeZB.pos-1]->data : stores the data received. Max size MAX_DATA. packet_finished[xbeeZB.pos-1]->packetID : stores the packet ID of the received message. 0x52 in this case. packet_finished[xbeeZB.pos-1]->typeSourceID : stores the source type ID used in the message. After receiving the first packet, due to there are three fragments, it will not be completed, so variable pos will be zero. It is recommended to set a delay in the transmitter so as to the receiver doesnt receive more than one packet at once. When the three fragments have been received, variable pos will change its value and the information in the packet_finished array will be available. NOTE: Due to memory restrictions, it is recommended when a pending packet is treated and it is not necessary to store it any more, to release this pointer. If dont, memory may overflow and crash the application. It is not possible to have more than 2700Bytes in a receiver node. It is referred to a single big packet or many smaller packets in parallel.
Received 50-bytes data packet. Application Layer Addressing. 64-bit Source ID Type { state=xbeeZB.treatData(); // Read a packet when XBee has noticed it to us if( xbeeZB.pos>0 ) { /* Available info: (there are more available information) */ source_address[0]=packet_finished[xbeeZB.pos-1]->macSH[0]; ... source_address[3]=packet_finished[xbeeZB.pos-1]->macSH[3]; } }
Available Information packet_finished[xbeeZB.pos-1]->naS : stores the 16-bit network address of the sender. packet_finished[xbeeZB.pos-1]->macSH : stores the 32 upper bits of MAC sender address. packet_finished[xbeeZB.pos-1]->macSL : stores the 32 lower bits of MAC sender address. packet_finished[xbeeZB.pos-1]->macOH : stores the 32 upper bits of MAC origin sender address. packet_finished[xbeeZB.pos-1]->macOL : stores the 32 lower bits of MAC origin sender address. packet_finished[xbeeZB.pos-1]->SD : stores the Source Endpoint of the origin sender packet_finished[xbeeZB.pos-1]->DE : stores the Destination Endpoint packet_finished[xbeeZB.pos-1]->CID : stores the Cluster Identifier packet_finished[xbeeZB.pos-1]->PID : stores the Profile Identifier packet_finished[xbeeZB.pos-1]->mode : stores the transmission mode. Unicast in this case. packet_finished[xbeeZB.pos-1]->data : stores the data received. Max size MAX_DATA. packet_finished[xbeeZB.pos-1]->packetID : stores the packet ID of the received message. 0x52 in this case. packet_finished[xbeeZB.pos-1]->typeSourceID : stores the source type ID used in the message. After receiving the packet, due to there is only one fragment, it will be completed, so variable pos will be greater than zero. This variable is used to index the array where the received packet is stored. The information that has been stored is indicated in the example. When using application layer addressing, a special frame is returned by the module called explicit addressing frame. To allow the module to receive application layer addressing packets, API options should be changed. This explicit addressing frame returns the information related to endpoint, cluster and profile used in the application layer communication.
-37-
v0.5
Starting a Network
8. Starting a Network
8.1. Coordinator Startup
To create a ZigBee network, a coordinator must be started on a channel and PAN ID (64-bit and 16-bit). Once the coordinator has started, routers and end devices can join the network. Some parameters explained in previously chapters as Extended PAN ID, Scan Channels and Scan Duration are used in network startup. To select a correct channel and PAN ID, the coordinator performs an energy scan and PAN scan. Scan Channels and Scan Duration are used to determine the duration and the list of channels to scan. Extended PAN ID is used to select an ID different from zero. After completing the energy and PAN scans, the coordinator uses the results to select the channel with less energy and a PAN ID unused in other PAN. If security should be set at startup, please see chapter 12. After the coordinator has successfully started, it behaves similar to a router - it can allow devices to join the network, and it can transmit, route and receive data. The coordinator saves the selected channel and PAN ID settings into non-volatile memory so this information will persist through power cycles. If a coordinator has successfully started a PAN and other coordinator is powered, there will be two PANs. It will perform the explained scans and will choose a channel and PAN ID to work on. A coordinator cant be part of a network if another coordinator already exists.
-38-
v0.5
Starting a Network
Example of use:
{ xbeeZB.setStackProfile(2); // Set ZigBee stack profile to ZB 2007 xbeeZB.getStackProfile (); // Get ZigBee stack profile }
8.4. Examples
8.4.1. Coordinator Startup Process. Random Extended PAN ID. All channels to scan
{ panid={0,0,0,0,0,0,0,0}; xbeeZB.setPAN(panid); // Set PANID to 0. Coordinator will select a random PAN ID xbeeZB.setScanningChannels(0xFF,0xFF); // Set List of Channels to scan. xbeeZB.setDurationEnergyChannels(3); // Set exponent of scan channel duration xbeeZB.getAssociationIndication(); // Check if creating process success if(!xbeeZB.associationIndication) { /* Association Successful } }
Once these configuration parameters have been set, the Coordinator will scan to select the channel and PAN ID. When the Coordinator finishes the process, associationIndication will change to 0x00.
-39-
v0.5
Starting a Network
Available Information xbeeZB.associationIndication stores the status of the last creating a network process xbeeZB.extendedPAN stores the 64-bit Extended Operating PAN ID xbeeZB.operatingPAN stores the 16-bit Operating PAN ID xbeeZB.channel stores the channel selected
8.4.2. Coordinator Startup Process. Selected Extended PAN ID. Only some channels to scan
{ panid={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08}; xbeeZB.setPAN(panid); // Set PANID to the selected. Coordinator will select this PAN ID xbeeZB.scanChannels(0x00,0xFF); // Set List of Channels to scan. xbeeZB.setDurationEnergyChannels(3); // Set exponent of scan channel duration xbeeZB.getAssociationIndication(); // Check if creating process success if(!xbeeZB.associationIndication) { /* Association Successful } }
Once these configuration parameters have been set, the Coordinator will scan to select the channel and PAN ID. When the Coordinator finishes the process, associationIndication will change to 0x00. Available Information xbeeZB.associationIndication stores the status of the last creating a network process xbeeZB.extendedPAN stores the 64-bit Extended Operating PAN ID xbeeZB.operatingPAN stores the 16-bit Operating PAN ID xbeeZB.channel stores the channel selected
-40-
v0.5
zero, any value will be valid. If not, it will be the same to be a valid value. The discovered device is allowing joins. Parameter Node Join Time has not expired. The discovered device is operating in one of Scan Channels channels. The discovered device is operating with the same ZigBee stack profile. The security police is the same in both devices.
If a device is discovered during the PAN scan and meets all the above requirements, the joining device will send a join request to the device and attempt to join the PAN. If the joining device receives a join response, then the device is considered joined to the PAN. The status of the last PAN scan and join attempt is recorded into the Association Indication parameter.
9.1.1. Example
{ panid={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; xbeeZB.setPAN(panid); // Set PANID to 0. Router will join any PAN ID xbeeZB.setScanningChannels(0xFF,0xFF); // Set List of Channels to scan. All channels scanned xbeeZB.setDurationEnergyChannels(3); // Set exponent of scan channel duration xbeeZB.getAssociationIndication(); // Check if creating process success if(!xbeeZB.associationIndication) { /* Association Successful } }
Once these configuration parameters have been set, Router will start scans to find a valid PAN. Available Information xbeeZB.associationIndication stores the status of the last creating a network process xbeeZB.extendedPAN stores the 64-bit Extended Operating PAN ID xbeeZB.operatingPAN stores the 16-bit Operating PAN ID xbeeZB.channel stores the channel selected
zero, any value will be valid. If not, it will be the same to be a valid value.
-41-
v0.5
9.2.1. Example
{ panid={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08}; xbeeZB.setPAN(panid); // Set PANID. End Device will only join a PAN with that PAN ID. xbeeZB.scanChannels(0x00,0xFF); // Set List of Channels to scan. xbeeZB.setDurationEnergyChannels(3); // Set exponent of scan channel duration xbeeZB.getAssociationIndication(); // Check if creating process success if(!xbeeZB.associationIndication) { /* Association Successful } }
Once these configuration parameters have been set, End Device will start scans to find a valid PAN. Available Information xbeeZB.associationIndication stores the status of the last creating a network process xbeeZB.extendedPAN stores the 64-bit Extended Operating PAN ID xbeeZB.operatingPAN stores the 16-bit Operating PAN ID xbeeZB.channel stores the channel selected
-42-
v0.5
0x00: Successful. Coordinator started or Router/End Device joined with a parent. 0xAB: Attempted to join a device did not respond. 0xAC: Secure join error. Network security key received unsecured. 0xAD: Secure join error. Network security key not received. 0xAF: Secure join error. Joining device does not have the right preconfigured link key. 0x21: Scan found no PANs. 0x22: Scan found no valid PANs based on current Scan Channels and Extended PAN ID. 0x23: Valid Coordinator or Routers found, but they are not allowing joining. 0x27: Node joining attempt failed. 0x2A: Coordinator Start attempt failed. -43v0.5
Example of use:
{ xbeeZB.getAssociationIndication(); // Get Association Indication Status }
-44-
v0.5
Available Information scannedBrothers[totalScannedBrothers-1].MY stores 16-bit NA of each module scannedBrothers[totalScannedBrothers-1].SH stores the 32 upper bits of MAC address scannedBrothers[totalScannedBrothers-1].SL stores the 32 lower bits of MAC address scannedBrothers[totalScannedBrothers-1].NI stores the Node Identifier scannedBrothers[totalScannedBrothers-1].PMY stores the 16-bit NA of its parent scannedBrothers[totalScannedBrothers-1].DT stores the device type(C, R or E) scannedBrothers[totalScannedBrothers-1].ST stores the status. Reserved by module. scannedBrothers[totalScannedBrothers-1].MID stores the 16-bit manufacturer ID scannedBrothers[totalScannedBrothers-1].PID stores the 16-bit Profile ID
Available Information xbeeZB.scanTime stores the time a node will wait for responses.
-45-
v0.5
Available Information xbeeZB.discoveryOptions stores the selected options for ND NOTE: If the Node Discovery Time is a long time, the API function may exit before receiving a response, but the module will wait for it, crashing the code. If this time is too short, it is possible the modules dont answer. After testing several times, the best values are 1-2 seconds for setting the API function properly. When a Node Discovery is performed, due to it is a broadcast message, it will only reach as many hops as the set in Broadcast Max Hops parameter. So, setting that parameter, a Node Discovery may only reach nodes near or may reach the entire network. It is recommended to try on the final scenario to find the best value for this parameter.
-46-
v0.5
Rebooting a Network
-47-
v0.5
Sleep Options
-48-
v0.5
Sleep Options
Example of use:
{ uint8_t asleep[3]={0xAF,0x00,0x00}; xbeeZB.setSleepTime(asleep); // Set Sleep period to 0,32 seconds }
Related Variables xbeeZB.sleepTime stores the sleep period the module will be sleeping
Related Variables xbeeZB.awakeTime stores the time the module remains awake
-49-
v0.5
Sleep Options
-50-
v0.5
When the parent stores a packet addressed to an end device child, it stores the packet for a maximum time set by Sleep Period parameter. The parent is also responsible for performing any route or address discoveries to forward data sent by its end device children
-51-
v0.5
-52-
v0.5
The mode used to encrypt the information is AES-CTR. In this mode all the data is encrypted using the defined 128b key and the AES algorithm. The Frame Counter sets the unique message ID ,and the Key Counter (Key Control subfield) is used by the application layer if the Frame Counter max value is reached.
ZigBee implements two extra security layers on top of the 802.15.4 one: the Network and Application security layers. All the security policies rely on the AES 128b encryption algorithm so the hardware architecture previously deployed for the link level (MAC layer) is still valid. There are three kind of keys: master, link and network.
Master Keys: They are pre-installed in each node. Their function is to keep confidential the Link Keys exchange between Link Keys: They are unique between each pair of nodes. These keys are managed by the Application level. The are used to Network key: It is a unique 128b key shared among all the devices in the network. It is generated by the Trust Center and
encrypt all the information between each two devices, for this reason more memory resources are needed in each device.
regenerated at different intervals. Each node has to get the Network Key in order to join the network. Once the trust center decides to change the Network Key, the new one is spread through the network using the old Network Key. Once this new -53v0.5
Related Variables xbeeZB.linkKey stores the key that has been set in the network
-54-
v0.5
Related Variables xbeeZB.networkKey stores the key that has been set in the network
-55-
v0.5
13.4. Examples
13.4.1. Configuring a network using security without a Trust Center
This is the easiest way to cypher the communications in a PAN. It is needed to set a valid Network Key and the Link Key in the coordinator and the rest of the nodes to zero. In this case, when nodes join the network, coordinator will send Network Key unencrypted and they will store this key to communicate inside the network. Coordinator
{ char* NETKEY=WaspmoteNetwKey!; char* LINKKEY=; xbeeZB.encryptionMode(1); // Enable Encryption xbeeZB.setLinkKey(NETKEY); // Set Network Key xbeeZB.setNetworkKey(LINKKEY); // Set Link Key }
Joining Devices
{ char* LINKKEY=; xbeeZB.encryptionMode (1); // Enable Encryption xbeeZB.setNetworkKey(LINKKEY); // Set Link Key }
13.4.2. Configuring a network using security and the coordinator as a Trust Center
This is the safest way to secure a network. In this case, Network Key unsecured sending is avoided and a secure communication inside the network is assured. When a node is joining the network, the Network Key is sent by the Trust Center encrypted with the Link Key. Coordinator: Network Key and Link Key must be set to the selected ones. Encryption Options must be set to enable Trust Center. Joining Devices: Link Key must be the same as in coordinator and Trust Center must be enabled in Encryption Options. Coordinator
{ char* NETKEY=WaspmoteNetwKey!; char* LINKKEY=WaspmoteLinkKey!; xbeeZB.encryptionMode (1); // Enable Encryption xbeeZB.setEncryptionOptions(0x02); // Enable Trust Center xbeeZB.setLinkKey(NETKEY); // Set Network Key xbeeZB.setNetworkKey(LINKKEY); // Set Link Key }
Joining Devices
{ char* LINKKEY=WaspmoteLinkKey! xbeeZB.encryptionMode (1); // Enable Encryption xbeeZB.setEncryptionOptions(0x02); // Enable Trust Center xbeeZB.setNetworkKey(LINKKEY); // Set Link Key }
-56-
v0.5
-57-
v0.5