Zigbee Module
Zigbee is a self-organizing network communication module launched by M5Stack. The module adopts the CC2630F128 solution, integrates the Zigbee protocol stack internally, and provides an open serial communication interface. It features an external antenna, with a stable single-node communication distance of up to 1 km and supports up to 200 levels of router depth. Through MESH networking, it can significantly extend the range of your IoT applications, offering both ultra-low power consumption and high sensitivity. The Zigbee network can support hundreds of nodes and has enhanced security features, providing a complete and interoperable IoT solution for home and building automation.
Support the following products:
Micropython TX Example:
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from module import ZigbeeModule 9import time 10 11 12label0 = None 13com_zigbee_0 = None 14zigbee_0 = None 15 16 17def setup(): 18 global label0, com_zigbee_0, zigbee_0 19 20 M5.begin() 21 Widgets.fillScreen(0x222222) 22 label0 = Widgets.Label("label0", 32, 35, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 23 24 com_zigbee_0 = ZigbeeModule(2, 17, 18, verbose=True) 25 com_zigbee_0.set_module_param( 26 ZigbeeModule.DEVICE_TYPE_COORDINATOR, 27 0x1620, 28 11, 29 ZigbeeModule.TRANSFER_MODE_PASS_THROUGH, 30 0x6677, 31 ) 32 label0.setText(str("start")) 33 34 35def loop(): 36 global label0, com_zigbee_0, zigbee_0 37 M5.update() 38 com_zigbee_0.p2p_transmission(0x0066, "p2p") 39 time.sleep(3) 40 com_zigbee_0.broadcast("broadcast") 41 time.sleep(3) 42 43 44if __name__ == "__main__": 45 try: 46 setup() 47 while True: 48 loop() 49 except (Exception, KeyboardInterrupt) as e: 50 try: 51 com_zigbee_0.stop_receive() 52 from utility import print_error_msg 53 54 print_error_msg(e) 55 except ImportError: 56 print("please update to latest firmware")
Micropython RX Example:
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from module import ZigbeeModule 9 10 11label0 = None 12com_zigbee_0 = None 13 14 15zigbee_str_data = None 16zigbee_dest_address = None 17zigbee_src_address = None 18 19 20def com_zigbee_0_receive_event(dest_address, src_address, received_data): 21 global label0, com_zigbee_0, zigbee_str_data, zigbee_dest_address, zigbee_src_address 22 zigbee_dest_address = dest_address 23 zigbee_src_address = src_address 24 try: 25 zigbee_str_data = received_data.decode() 26 except: 27 zigbee_str_data = str(received_data) 28 label0.setText(str(zigbee_str_data)) 29 30 31def setup(): 32 global label0, com_zigbee_0, zigbee_str_data, zigbee_dest_address, zigbee_src_address 33 34 M5.begin() 35 Widgets.fillScreen(0x222222) 36 label0 = Widgets.Label("label0", 50, 34, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 37 38 com_zigbee_0 = ZigbeeModule(2, 14, 13, verbose=True) 39 com_zigbee_0.set_module_param( 40 ZigbeeModule.DEVICE_TYPE_ROUTER, 41 0x1620, 42 11, 43 ZigbeeModule.TRANSFER_MODE_PASS_THROUGH, 44 0x0066, 45 ) 46 while not (com_zigbee_0.isconnected()): 47 pass 48 label0.setText(str(com_zigbee_0.get_custom_address())) 49 com_zigbee_0.receive_none_block(com_zigbee_0_receive_event) 50 51 52def loop(): 53 global label0, com_zigbee_0, zigbee_str_data, zigbee_dest_address, zigbee_src_address 54 M5.update() 55 56 57if __name__ == "__main__": 58 try: 59 setup() 60 while True: 61 loop() 62 except (Exception, KeyboardInterrupt) as e: 63 try: 64 com_zigbee_0.stop_receive() 65 from utility import print_error_msg 66 67 print_error_msg(e) 68 except ImportError: 69 print("please update to latest firmware")
UIFLOW2 TX Example:
UIFLOW2 RX Example:
stickc_plus2_zigbee_rx_example.m5f2
class ZigbeeModule
Constructors
Methods
- ZigbeeModule.set_module_param(device_type: int, pan_id: int, channel: int, transfer_mode: int, custom_address: int, ant_type: int, encryption_enable=ENCRYPTION_ENABLE, encryption_key=b'\x11\x12\x13\x14', node_type=DEVICE_TYPE_ROUTER, node_ant_type=ANT_TYPRE_ON_BOARD, node_transfer_mode=TRANSFER_MODE_PASS_THROUGH, node_custom_address=0x0066)
- Parameters:
device_type (int) – The device type of the Zigbee module.
pan_id (int) – The PAN ID of the Zigbee module. The PAN ID is a 16-bit value that is used to identify the network.
channel (int) – The channel of the Zigbee module. The channel range is from 11 to 26
transfer_mode (int) – The transfer mode of the Zigbee module.
custom_address (int) – The custom address of the Zigbee module.
ant_type (int) – The antenna type of the Zigbee module.
encryption_enable (int) – The encryption status of the Zigbee module.
encryption_key (bytes) – The encryption key of the Zigbee module.
node_type (int) – The node type of the Zigbee module.
node_ant_type (int) – The antenna type of the Zigbee node.
node_transfer_mode (int) – The transfer mode of the Zigbee node.
node_custom_address (int) – The custom address of the Zigbee node.
Set the parameters of the Zigbee module.
UIFLOW2:
- ZigbeeModule.set_device_type(device_type: int)
- Parameters:
device_type (int) – The device type of the Zigbee module.
Set the device type of the Zigbee module.
UIFLOW2:
- ZigbeeModule.set_pan_id(pan_id: int)
- Parameters:
pan_id (int) – The PAN ID of the Zigbee module.
Set the PAN ID of the Zigbee module.
UIFLOW2:
- ZigbeeModule.set_channel(channel: int)
- Parameters:
channel (int) – The channel of the Zigbee module.
Set the channel of the Zigbee module.
UIFLOW2:
- ZigbeeModule.set_transfer_mode(transfer_mode: int)
- Parameters:
transfer_mode (int) – The transfer mode of the Zigbee module.
Set the transfer mode of the Zigbee module.
UIFLOW2:
- ZigbeeModule.get_custom_address() int
Get the custom address of the Zigbee module.
- Returns:
The custom address of the Zigbee module.
UIFLOW2:
- ZigbeeModule.set_custom_address(custom_address: int)
- Parameters:
custom_address (int) – The custom address of the Zigbee module.
Set the custom address of the Zigbee module.
UIFLOW2:
- ZigbeeModule.set_ant_type(ant_type: int)
- Parameters:
ant_type (int) – The antenna type of the Zigbee module.
Set the antenna type of the Zigbee module.
UIFLOW2:
- ZigbeeModule.get_short_address() int
Get the short address of the Zigbee module.
- Returns:
The short address of the Zigbee module.
UIFLOW2:
- ZigbeeModule.isconnected() bool
Check whether the Zigbee module is connected to the Zigbee network.
- Returns:
True if the Zigbee module is connected to the Zigbee network, False otherwise.
UIFLOW2:
- ZigbeeModule.receive_none_block(receive_callback)
- Parameters:
receive_callback – The callback function that is called when the Zigbee module receives data.
Receive data from the Zigbee module.
UIFLOW2:
- ZigbeeModule.stop_receive()
Stop receiving data from the Zigbee module.
UIFLOW2: