EasyManuals Logo

Digi XBee 3 ZigBee User Manual

Digi XBee 3 ZigBee
347 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #35 background imageLoading...
Page #35 background image
Get started with MicroPython MicroPython networking and communication examples
Digi XBe 3 Zigbe RF Module
35
def format_packet(p):
type = 'Broadcast' if p['broadcast'] else 'Unicast'
print("%s message from EUI-64 %s (network 0x%04X)" %
(type, format_eui64(p['sender_eui64']), p['sender_nwk']))
print("from EP 0x%02X to EP 0x%02X, Cluster 0x%04X, Profile 0x%04X:" %
(p['source_ep'], p['dest_ep'], p['cluster'], p['profile']))
print(p['payload'],"\n")
def network_status():
# If the value of AI is non zero, the module is not connected to a network
return xbee.atcmd("AI")
4. At the MicroPython 1^^^ prompt, right-click and select the Paste option.
5. Press Ctrl+D to finish. The code is uploaded to the flash memory and then compiled. At the
"Automatically run this code at startup" [Y/N]?" prompt, select Y.
6. Press Ctrl+R to run the compiled code; this provides access to these utility functions for the
next examples.
WARNING! MicroPython code stored in flash is saved in the file system as main.py. If the
file system has not been formatted, then the following error is generated:
OSError: [Errno 7019] ENODEV
The file system can be formatted in one of three ways:
In XCTU by using the File System Manager.
In Command mode using the ATFS FORMAT confirm commandsee FS (File System).
In MicroPython by issuing the following code:
import os
os.format()
Example code on the coordinator module
The following example code forms a Zigbee network as a coordinator, performs a network discovery
to find the remote node, and continuously prints out any incoming data.
1. Access the MicroPython environment.
2. Copy the following sample code:
print("Forming a new Zigbee network as a coordinator...")
xbee.atcmd("NI", "Coordinator")
network_settings = {"CE": 1, "ID": 0x3332, "EE": 0, "NJ": 0xFF}
for command, value in network_settings.items():
xbee.atcmd(command, value)
xbee.atcmd("AC") # Apply changes
time.sleep(1)
while network_status() != 0:
time.sleep(0.1)
print("Network Established\n")
print("Waiting for a remote node to join...")
node_list = []
while len(node_list) == 0:
# Perform a network discovery until the router joins

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Digi XBee 3 ZigBee and is the answer not in the manual?

Digi XBee 3 ZigBee Specifications

General IconGeneral
BrandDigi
ModelXBee 3 ZigBee
CategoryControl Unit
LanguageEnglish

Related product manuals