Digi XBee 3 ZigBee User Manual page 35

Rf module
Table of Contents

Advertisement

Get started with MicroPython
def format_packet(p):
type = 'Broadcast' if p['broadcast'] else 'Unicast'
print("%s message from EUI-64 %s (network 0x%04X)" %
print("from EP 0x%02X to EP 0x%02X, Cluster 0x%04X, Profile 0x%04X:" %
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
In Command mode using the ATFS FORMAT confirm command—see
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")
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
Digi XBee® 3 Zigbee® RF Module
(type, format_eui64(p['sender_eui64']), p['sender_nwk']))
(p['source_ep'], p['dest_ep'], p['cluster'], p['profile']))
File System
Manager.
# Apply changes
MicroPython networking and communication examples
FS (File
System).
35

Advertisement

Table of Contents
loading
Need help?

Need help?

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

Table of Contents