element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Essentials
  • Learn
  • Learning Center
  • Essentials
  • More
  • Cancel
Essentials
Documents Essentials of Zigbee
  • Forum
  • Documents
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Essentials to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Engagement
  • Author Author: pchan
  • Date Created: 2 Nov 2022 9:41 PM Date Created
  • Last Updated Last Updated: 28 Jul 2023 8:36 PM
  • Views 113853 views
  • Likes 10 likes
  • Comments 22 comments
Related
Recommended

Essentials of Zigbee

Zigbee is an open communication standard developed to enable low latency, low-power, secure, wireless IoT data networks.

essentials logoWireless Protocol Series - Part 6 - Essentials of Zigbee

Zigbee is a popular communication protocol used in many modern sensor and control networks, including home and industrial automation. Zigbee was developed as an open connectivity standard for wireless IoT networks. Its growing popularity stems from Zigbee’s enabling a variety of useful features, including low latency, support for multiple network topologies, and low power consumption; some Zigbee devices can have battery life lasting several years. Wireless devices that use Zigbee operate in unlicensed radio bands, including 868 MHz, 915 MHz, and 2.4 GHz frequency bands. This learning module is an introduction to the Zigbee protocol, spanning the technology, architecture, applications, and development tools.
Related Components | Test Your Knowledge test link

For more information on Zigbee, take a look at our eBook: Home Automation with the Raspberry Pi.

2. Objectives


Upon completion of this module, you will be able to:

  • Describe Zigbee technology and communication protocols
  • Understand the concepts underlying the technology
  • Discuss various applications of Zigbee
  • Discuss Zigbee development, including hardware and software

3. Basic Concepts

Back to Top

The Zigbee network layer supports star, tree, and mesh topologies. In mesh and tree topologies, the Zigbee coordinator forms the personal area network (PAN) and chooses specific key network parameters, such as assigning addresses. Mesh networks allow full peer-to-peer communication.

figure 1
Figure 1: Zigbee Topology

- Analysis

The Zigbee architecture is a protocol stack with five layers.

  1. Application Layer
  2. Security Layer
  3. Network Layer
  4. Medium Access Control (MAC) Layer
  5. Physical (PHY) Layer
  • Physical (PHY) layer: The PHY layer is the lowest layer and closest to the hardware. This layer directly controls and communicates with the Zigbee radio. The physical layer translates the data packets in over-the-air bits for transmission and vice-versa during reception.
  • Medium Access Control (MAC) layer: The MAC layer works as an interface between the network and physical layer, controlling access and resolving conflict between competing nodes. The MAC layer provides PAN ID and also network discovery via beacon requests.
  • Network Layer: The Network Layer is responsible for routing and establishing the different Zigbee topologies. The network layer acts as an interface between the MAC and application layers.
  • Security Layer: The Security Layer handles encryption; with security enabled, data for Zigbee devices is encrypted with a 128-bit AES (Advanced Encryption Standard) network key.
  • Application Layer: The Application Layer (or Application Framework) is the highest protocol layer in the Zigbee stack. It comprises the Application Support (APS) sub-layer and Zigbee Device Object (ZDO). The Application Layer contains manufacturer-defined applications, and is responsible for the discovery and binding of services.

- Zigbee Networking

The Zigbee networking layer manages the formation of the network, which can be one of two networking topologies: star and peer-to-peer. In the star topology, every device in the network communicates only with the PAN coordinator. Zigbee uses the Ad-hoc On-demand Distance Vector (AODV) routing protocol. Zigbee also supports the tree topology. A Zigbee coordinator (PAN coordinator) establishes the initial network, and Zigbee routers form the branches and relay the messages to devices.

In a peer-to-peer topology, each device can communicate directly with the other devices on the network, as long as the placement of these devices is sufficiently close to establish a successful communication link. Any Fully Functional Device (FFD) in a peer-to-peer network can play the role of the PAN coordinator. A peer-to-peer network can take different shapes by defining restrictions on the devices that can mutually communicate. An unrestricted peer-to-peer network is known as mesh topology.

A PAN coordinator always creates an IEEE 802.15.4 network, regardless of its topology. The PAN coordinator controls the network and performs duties such as allocating a unique address (16-bit or 64-bit) to each device in the network, initiating, terminating, and routing the messages throughout the network and selecting a unique PAN identifier for the network. The unique PAN identifier permits the devices within a network to use the 16-bit short-addressing method and still communicate with other devices across independent networks.

- Zigbee Security

The Zigbee network uses a 128-bit (16 Bytes) AES network key to encrypt all data transmission. Every node must obtain the network key in order to join the network. The network key is regenerated and distributed through the network at different intervals. Zigbee also implements link keys between devices. Link keys are unique keys shared by a pair of nodes, used to encrypt the data transmitted between the two devices. Link keys are generated by the trust center, the device assigned the responsibility of authenticating new nodes and distributing the network key.

- Zigbee Applications

A wide variety of industries and applications can take advantage of Zigbee wireless networking; these include home automation, industrial applications, health care, and inventory tracking.

Home Automation
A home automation network typically does not need high data rates; the standard data rate in home automation is only 10 kbps, well within the Zigbee specification. Home automation applications include security, light control, meter reading, irrigation, and multi-zone HVAC systems.

Industrial Automation
Zigbee mesh networking can support the data transfer required for energy management, livestock tracking, light control, process control, and asset management.

Consumer Electronics
Zigbee finds use in game controllers, wireless remote controls, wireless peripherals for personal computers, and many other applications.

Healthcare
In a system for remote patient monitoring, data from wearables and other sensors connected to patients can be collected wirelessly. Data is encrypted and securely transferred via Zigbee.

- The Zigbee Development Environment

A Zigbee Certified Platform (ZCP) is a platform certified by the Connectivity Standards Alliance (formerly the Zigbee Alliance), and comprises a radio, Zigbee stack, and a microcontroller. Tools are available on PC for building and compiling applications, which are then transferred into target boards for debugging, generally through USB or Ethernet (wireless download is enabled in some platforms).

All vendors of Zigbee radios offer development kits, complete with two or more development boards, a USB, serial or Ethernet connection to the boards, and a debug connection (BDM or JTAG) to download new binary images into the boards and to debug applications. Development kits include all the necessary hardware and software to develop Zigbee, as well as sample applications.

figure 2a
 Digi XBee  3 Zigbee Mesh Kit
figure 2b
 ONsemi Strata enabled Zigbee Green Power Kit
figure 2c
 Digi Xbee  2.4GHz
figure 2d
 OM15080-K32W  USB Dongle
Figure 2: Zigbee Modules

Application Development
This tutorial demonstrates basic application development, using the Raspberry Pi to control Zigbee communication. Special thanks go to Dr. Derek Schuurman, Computer Science Professor at Calvin University, who created pi-home, a home automation project that includes the control of lights, as well as the logging of temperature, humidity, pressure, and water leak sensors. This tutorial will go over pi-lights, a smaller version of pi-home, which focuses on the control of lights.

Light control using Raspberry Pi and Zigbee
Pi-lights enables the automation of lighting in the home, automatically turning on lights at dusk, and turning them off at a preset time. The project also includes the ability to control smart outlets. Configuration and manual operation can be performed via web browser.

The project was written in Python 3, and uses the Zigbee2MQTT library to control Zigbee devices using MQTT (Messaging Queue Telemetry Transport), a lightweight messaging protocol popular in IoT systems. Zigbee2MQTT works with a variety of Zigbee USB adapters and devices. Although the code was developed for a Raspberry Pi with a Zigbee USB adapter, it can be run on other POSIX (Portable Operating System Interface) compliant systems.

Hardware

figure 3
Figure 3: Zigbee USB Adapter

A Zigbee adapter is the interface that enables Zigbee on the computer (or server). Several types of Zigbee adapters are available, include USB, GPIO or remote via WIFI or Ethernet.

figure 4
Figure 4: Raspberry Pi  Server

A computer or server executes the code. Most Raspberry-Pi models are able to support Zigbee. With the proper hardware and software, many other platforms also support Zigbee networks, including Linux, Windows, and macOS.

figure 5
Figure 5: IKEA Light bulb. Image source: IKEA

Finally, choose the Zigbee devices that the system will control, such as the IKEA LED2035G10.

Software
The source code for the project can be downloaded at the pi-lights GitHub. Included in the package are installation instructions, as well as templates for the web interface. The two files containing source code are pi-lights.conf and pi-lights.py.

pi-lights.conf is the file containing the configuration settings used by the source code. This includes connection addresses and ports, as well as preferences such as location (based on city) and brightness range of the light.

pi-lights.py is the main source code written in Python 3. This file contains the functions performing all of the operations in the application.

The following is an analysis of some of the code in pi-lights.py.

turn_on_bulbs (line 55) and turn_off_bulbs (line 67) are the methods that turn the bulb(s) on and off. These methods are located in the State class, which manages device state for the bulbs and outlets.

def turn_on_bulbs(self):
self.lock.acquire()
for bulb in self.bulbs:
(rc, msg_id) = self.client.publish(f'zigbee2mqtt/{bulb}/set/state', 'ON')
if rc != 0:
logging.error(f'MQTT publish return codes: {rc}')
self.light_state = True
self.lock.release()
logging.debug('Lights turned on')

def turn_off_bulbs(self):
self.lock.acquire()
for bulb in self.bulbs:
(rc, msg_id) = self.client.publish(f'zigbee2mqtt/{bulb}/set/state', 'OFF')
if rc != 0:
logging.error(f'MQTT publish return code: {rc}')
self.light_state = False
self.lock.release()
logging.debug('Lights turned off')

Using a for loop, the function sends a command to each bulb via zigbee2mqtt. In the turn_on_bulbs method, that command is:

(rc, msg_id) = self.client.publish(f'zigbee2mqtt/{bulb}/set/state', 'ON')

rc is the return code; this is logged if there is an error.

self.lock.acquire() and self.lock.release() are primitive locks to control access to shared resources. acquire() changes the state of the object to locked, blocking all other calls to it until release() is called, changing it back to the unlocked state. Locking prevents multiple methods from access a shared resource at the same time, potentially resulting in corrupted data.

self.light_state is a variable that is set to remember if the lights are on or off.

Similarly, there are methods to turn smart outlets on and off (lines 79 and 91).

def turn_on_outlets(self):
self.lock.acquire()
for outlet in self.outlets:
(rc, msg_id) = self.client.publish(f'zigbee2mqtt/{outlet}/set/state', 'ON')
if rc != 0:
logging.error(f'MQTT publish return code: {rc}')
self.outlet_state = True
self.lock.release()
logging.debug('Outlets turned on')

def turn_off_outlets(self):
self.lock.acquire()
for outlet in self.outlets:
(rc, msg_id) = self.client.publish(f'zigbee2mqtt/{outlet}/set/state', 'OFF')
if rc != 0:
logging.error(f'MQTT publish return code: {rc}')
self.outlet_state = False
self.lock.release()
logging.debug('Outlets turned off')

set_brightness (line 103) sets the brightness of the bulbs.

def set_brightness(self, value):
self.brightness = value
for bulb in self.bulbs:
(rc, msg_id) = self.client.publish(f'zigbee2mqtt/{bulb}/set/brightness', self.brightness)
if rc != 0:
logging.error(f'MQTT publish return codes: {rc}')
logging.info(f'Brightness set to: {self.brightness}')

At the bottom of pi-lights.py (line 326) is the code that executes when the application is run. First, the settings are imported from pi-light.conf. Next, the connection to the MQTT broker (line 389) is established.

client = mqtt.Client()
ret = client.connect(BROKER_IP, BROKER_PORT, MQTT_KEEPALIVE)
if ret != 0:
logging.error(f'MQTT connect return code: {ret}')
state = State(BULBS, OUTLETS, BRIGHTNESS, client)

In this code, BROKER_IP, BROKER_PORT, and MQTT_KEEPALIVE are connection settings imported from pi-lights.conf. BULBS, OUTLETS, and BRIGHTNESS are also imported from pi-lights.conf, where the different bulbs, outlets, and the brightness range of the bulbs are specified.

Finally, scheduler and light_timer objects are created in order to turn lights and outlets on and off at the correct times. light_timer calls the LightTimer class (line 118), and scheduler calls Python’s scheduler class, a generic interface for scheduling events.

The Flask framework is used to enable the web interface. Flask is configured in the FlaskThread class (line 223).

4. Glossary

Back to Top

  • AES (Advanced Encryption Standard): a specification for the encryption of data. AES was established by NIST (National Institute of Standards and Technology) in 2001.
  • Connectivity Standards Alliance (formerly the Zigbee Alliance): a group of companies that maintains and publishes the Zigbee standard. The group contains over 500 members.
  • IEEE 802.15.4: a standard that defines the specifications for low data rate wireless personal area networks. Zigbee is an enhancement to the IEEE 802.15.4 standard.
  • Internet-of-Things (IoT): a network of connected electronic devices, where devices can communicate with each other and the cloud.
  • Medium Access Control (MAC) layer: the layer that works as an interface between the network and the physical layer. The MAC layer controls access, performs error correction, and resolves conflicts between competing nodes. The MAC layer also performs activities such as framing and addressing.
  • Mesh Topology: a network topology where all computers and network devices are interconnected and communicate directly with one another.
  • MQTT (Messaging Queue Telemetry Transport): a lightweight and efficient messaging transport protocol with small code footprint and minimal network bandwidth requirements.
  • Physical (PHY) layer: the layer that is lowest and closest to the hardware, interacting with the hardware to perform basic network functionality, such as transmitting and receiving.
  • Star Topology: a network topology where every computer or network device is connected directly to a central device, such as a hub or router.
  • Tree Topology: a network topology where multiple networks of star topology are connected via busses, similar to the branches on a tree.
*Trademark. element14 is a trademark of Premier Farnell. Other logos, product and/or company names may be trademarks of their respective owners.
Profile image

Wireless connectivity via Zigbee is growing in popularity, especially for industrial and home automation applications. There are a variety of hardware components and software now available to help with Zigbee development.

Product Image
Zigbee Module
MGM12P32F1024GE-V4
Buy Now  
MGM12P22F1024GA-V4
Buy Now
Product Image
PTM535BZ Transmitter Module
Buy Now
Product Image
XB3-24Z8ST Zigbee Module
Buy Now
Product Image
SLWSTK6102A Wireless Starter Kit
Buy Now
Product Image
1323XNSK-BDM Dev Board
Buy Now
Product Image
EM34X-VRDK Dev Kit
Buy Now
For more Zigbee products Shop Now

Test Your Knowledge

Back to Top

Wireless Protocol 6

Wireless Protocol 6

Complete our Essentials: Wireless Protocol 6 course, take the quiz, and leave your feedback to earn this badge.

Are you ready to demonstrate your Zigbee knowledge? Then take this 10-question quiz. To earn the Wireless Protocol VI Badge, read through the module, attain 100% in the quiz, and leave us some feedback in the comments section.

For more wireless protocol modules click on the next button.

  • iiot
  • mqtt
  • python
  • home automation
  • smart devices
  • low power
  • industrial automation
  • iot
  • wireless
  • connectivity
  • network topologies
  • zigbee
  • wireless protocol
  • ess_module
  • Share
  • History
  • More
  • Cancel
  • Sign in to reply

Top Comments

  • robogary
    robogary over 2 years ago +1
    Learned something new again. And Zigbee rhymes with Frisbee
  • Former Member
    Former Member 8 months ago

    Interesting quiz

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • koudelad
    koudelad over 2 years ago

    Good ZigBee introduction.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • VaishabhJalmi
    VaishabhJalmi over 2 years ago

    Interesting knowledge to explore zigbee technologies like it. Thank you Thumbsup

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • bbredenkamp
    bbredenkamp over 2 years ago

    Nixe Review, what I learned before

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mp2100
    mp2100 over 2 years ago

    It's baaa ack, Zero wrong answers, "you didn't get 100%".

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • kmikemoo
    kmikemoo over 2 years ago

    I haven't played with this protocol yet.  Maybe someday.  I still haven't done much with the LoRa nodes I bought.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • phoenixcomm
    phoenixcomm over 2 years ago in reply to flyingbean

    Tell me about it.... LOL

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • will06
    will06 over 2 years ago

    Interesting, but like a few other users I also needed to clear my cookies and history before I could score 100%.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • phoenixcomm
    phoenixcomm over 2 years ago

    Nice little quiz. I have used Zigbee for a number of years, Nailed it with out guessing. :)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • maxpowerr
    maxpowerr over 2 years ago

    Interesting quiz

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube