Get started with MicroPython
MicroPython examples
Digi XBee® 3 802.15.4 RF Module User Guide
42
Open a second instance of XCTU, and configure a different XBee 3 device for MicroPython following
the steps in
Use XCTU to enter the MicroPython environment
.
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
.
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 802.15.4
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:
for node in nodes:
print("\nRadio discovered:")
for key, value in node.items():
print("\t{:<12} : {}".format(key, value))
# Set NO back to the default value
xbee.atcmd("NO", 0)
xbee.atcmd("AC")
This produces the following output from two discovered nodes:
Radio discovered:
rssi
: -63
node_id
: Coordinator