Get started with MicroPython MicroPython networking and communication examples
Digi XBee® 3 Zigbee® RF Module
31
# Query AI until it reports success
print("Connecting to network, please wait...")
while xbee.atcmd("AI") != 0:
time.sleep(0.1)
print("Connected to Network")
operating_network = ["OI", "OP", "CH"]
print("Operating network parameters:")
for cmd in operating_network:
print("{}: {}".format(cmd, xbee.atcmd(cmd)))
After the code has been executed on both radios, the radio reports the operating network
parameters. Make sure both radios report the same values to ensure they are on the same network.
Example: network Discovery using MicroPython
The xbee.discover() method returns an iterator that blocks while waiting for results, similar to
executing an ND request. For more information, see ND (Network Discovery).
Each result is a dictionary with fields based on an ND response:
n sender_nwk: 16-bit network address.
n sender_eui64: 8-byte bytes object with EUI-64 address.
n parent_nwk: Set to 0xFFFE on the coordinator and routers; otherwise, this is set to the
network address of the end device's parent.
n node_id: The device's NI value (a string of up to 20 characters, also referred to as Node
Identification).
n node_type: Value of 0, 1 or 2 for coordinator, router, or end device.
n device_type: The device's 32-bit DD value, also referred to as Digi Device Type; this is used to
identify different types of devices or hardware.
n rssi: Relative signal strength indicator (in dBm) of the node discovery request packet received
by the sending node.
Note When printing the dictionary, fields for device_type, sender_nwk and parent_nwk appear in
decimal form. You can use the MicroPython hex() method to print an integer in hexadecimal. Check
the function code for format_eui64 from the Example: communication between two XBee 3 Zigbee
modules topic for code to convert the sender_eui64 field into a hexadecimal string with a colon
between each byte value.
Use the following example code to perform a network discovery:
import xbee, time
# Set the network discovery options to include self
xbee.atcmd("NO", 2)
xbee.atcmd("AC")
time.sleep(.5)
# Perform Network Discovery and print out the results
print ("Network Discovery in process...")
nodes = list(xbee.discover())
if nodes: