Zigbee Module Examples

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros
example_simple_application_router_afzdo.c File Reference
Simple Applications

Resets Module, configures this device to be a Zigbee Router, joins a network, then sends a message to the coordinator periodically with information from the peripherals. More...

`#include "../HAL/hal.h"`
`#include "../ZM/module.h"`
`#include "../ZM/application_configuration.h"`
`#include "../ZM/af.h"`
`#include "../ZM/zdo.h"`
`#include "../ZM/module_errors.h"`
`#include "../ZM/module_utilities.h"`
`#include "../ZM/zm_phy.h"`
`#include "../Common/utilities.h"`
`#include "Messages/infoMessage.h"`
`#include "Messages/kvp.h"`
`#include "Messages/oids.h"`
`#include "module_example_utils.h"`
`#include <stdint.h>`
`#include <string.h>`

## Macros
#define | MODULE_START_DELAY_IF_FAIL_MS 5000
#define | RESTART_DELAY_IF_MESSAGE_FAIL_MS 5000
#define | STATE_FLAG_SEND_INFO_MESSAGE 0x01
#define | NWK_OFFLINE 0
#define | NWK_ONLINE 1
enum | STATE { STATE_IDLE, STATE_INIT, STATE_MODULE_STARTUP, STATE_GET_DEVICE_TYPE, STATE_DISPLAY_NETWORK_INFORMATION, STATE_SEND_MESSAGE_VIA_LONG_ADDRESS, STATE_SEND_MESSAGE_VIA_SHORT_ADDRESS, STATE_VALID_SHORT_ADDRESS_ENTERED, STATE_VALID_LONG_ADDRESS_ENTERED, STATE_FIND_VIA_SHORT_ADDRESS, STATE_FIND_VIA_LONG_ADDRESS, STATE_IDLE, STATE_MODULE_STARTUP, STATE_DISPLAY_NETWORK_INFORMATION, STATE_IDLE, STATE_MODULE_STARTUP, STATE_SEND_INFO_MESSAGE, STATE_DISPLAY_NETWORK_INFORMATION, STATE_IDLE, STATE_MODULE_STARTUP, STATE_SEND_INFO_MESSAGE, STATE_DISPLAY_NETWORK_INFORMATION }
uint8_t | zmBuf [ZIGBEE_MODULE_BUFFER_SIZE]
uint16_t | sequenceNumber = 0
void(* | timerIsr )(void)
enum STATE | state = STATE_MODULE_STARTUP
uint16_t | stateFlags = 0
uint8_t | zigbeeNetworkStatus = NWK_OFFLINE
struct header | hdr
void | stateMachine ()
void | handleTimer ()
int | main (void)

## Detailed Description

Resets Module, configures this device to be a Zigbee Router, joins a network, then sends a message to the coordinator periodically with information from the peripherals.

Demonstrates using a state machine with the Module, and sending sensor values as key-value pairs. If you would like to add your own sensor data to the messages, it's very easy:

- First, determine the name of your object identifier (e.g. OID_HUMIDITY_PERCENT) and also what the value represents. Since the value field is just a 16bit integer, sometimes it is best to send the actual value / 100 or something similar. For example, when we send temperature we send it as centidegrees which allows us 0.01C accuracy. To keep your sanity I recommend including the units in the OID name.
- Add your new OID to the files Messages/oids.c and Messages/oids.h
- Write the sensor driver code. I like to actually create a small example that just reads the sensor and displays it to the screen (like the examples included in this code package). This can be very helpful when all hell breaks loose; you can go back to your simple example and verify that the driver and sensor are all working correctly.
- Decide whether the sensor will be mains powered or battery powered. If mains powered then make it a router so that it can route other messages. If battery powered then it must be an End Device
- Add your sensor to the appropriate place in getSensorValues() in module_example_utils.c or you can also just add it into this file.
- Don't change the coordinator until you get the Router or End Device code working that reads the sensor and sends the value. The Simple Application - Coordinator example is useful for debugging in this phase, since it will display any OIDs that are received as well as the name of the OID.
- Once you get the Router or End Device sending the sensor data properly then work on the other end, for example the Coordinator. Often you either want to parse the data and display it, or store it in a database table. Both are fairly easy. Most errors are caused by not using consistent units in the various places - for example, you might send over the air deciVolts but the database schema was created assuming this value is Volts.
- If you need assistance we're here to help; see below for support options. Tesla has extensive experience with sensor-to-server applications and everything inbetween.

Note:
  This matches example_simple_application_coordinator.c
  stack size increased to be able to do TMP006 calculations - see project settings

Rev:
  1642

Author:
  dsmith

Date:
  2012-10-31 11:17:04 -0700 (Wed, 31 Oct 2012)

# Support

Please refer to the wiki at www.anaren.com/air-wiki-zigbee for more information. Additional support is available via email at the following addresses:

- Questions on how to use the product: AIR@a.nosp@m.nare.nosp@m.n.com
- Feature requests, comments, and improvements: featu.nosp@m.rere.nosp@m.quest.nosp@m.s@te.nosp@m.slaco.nosp@m.ntro.nosp@m.ls.co.nosp@m.m
- Consulting engagements: sales.nosp@m.@tes.nosp@m.lacon.nosp@m.trol.nosp@m.s.com

# License

Copyright (c) 2012 Tesla Controls. All rights reserved. This Software may only be used with an Anaren A2530E24AZ1, A2530E24CZ1, A2530R24AZ1, or A2530R24CZ1 module. Redistribution and use in source and binary forms, with or without modification, are subject to the Software License Agreement in the file "anaren_eula.txt"

YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL ANAREN MICROWAVE OR TESLA CONTROLS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSE INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.

## Enumeration Type Documentation

enum STATE

STATES for state machine

## Function Documentation

void handleTimer | ( |  | ) |

Handles timer interrupt

void stateMachine | ( |  | ) |

The main application state machine

## Variable Documentation

enum STATE state = STATE_MODULE_STARTUP

    This is the current state of the application.

Gets changed by other states, or based on messages that arrive.

uint16_t stateFlags = 0

Various flags between states

void(* timerIsr)(void)

function pointer (in hal file) for the function that gets called when the timer generates an int

Function pointer for the ISR called when a timer generates an interrupt

uint8_t zigbeeNetworkStatus = NWK_OFFLINE

Whether the zigbee network has been started, etc.

uint8_t zmBuf[ZIGBEE_MODULE_BUFFER_SIZE]

    This buffer will hold the transmitted messages and received SRSP Payload after sendMessage() was

called. If fragmentation support is not required then this can be smaller, e.g. 100B.