Home/Support/Support Forum/Does XBee3 device need to be in REPL (AP=4) mode to transmit / receive stuffs

Does XBee3 device need to be in REPL (AP=4) mode to transmit / receive stuffs

0 votes
If I have a bunch of sensors on an i2c slave device (I/o expander) which is attached to my XBee3 acting as a master... if I want to request sensor data from the slave device via my python program (from so a communication between firmware(micropython) and software(my main python program)… does the XBee3 need to be in REPL mode (AP = 4) in order for the firmware to continually run upon start-up AND constantly while the device is powered?


because when I simulate a power cycle and REPL mode is selected, my router device successfully sends a message from the MicroPython to the coordinator into the Python file. But when I take the router device and set it's AP = 1 (API mode) then when I turn the device on and off I don't see the confirmation that the firmware (MicroPython) runs on auto-start.

thanks again!

asked Aug 3, 2020 in MicroPython by edunn106 New to the Community (25 points)

Please log in or register to answer this question.

3 Answers

0 votes
Yes, to use the I2C interface on the XBee, you do need to be in Micro Python mode and have the proper coded loaded on the module. Even if you plan on using an external device running a Python application.
answered Aug 3, 2020 by mvut Veteran of the Digi Community (15,409 points)
coordinator is connected to processor. that's it. coordinator then tells the routers what to do.

than each router was going to have micropython running on it as well. for the start-up message, and then the i2c sensors on each router.
That why are you changing the API mode on the routers? It should just be left at AP4.

Your Python app just needs to know how to send/receive data and understand what that data needs to look like.  It also just needs to do a few other basic functions like Node Discovery.

Your Micro Python app on the routers needs to do the bulk of the understanding on the IO pins, I2C and knowing what to do and when or where to send it to.
hmm. but this would mean the python program runs the GUI tkinter stuff.. when you click a button, python transmits to micropython which manipulates the pins?
Yes that is correct.
hey mvut, I finally found in the micropython documentation where it mentions what modes micropython will run in. just wanted to update you on the matter.

from the micropython programming guide PDF:

"When you are done coding, exit MicroPython by closing the MicroPython terminal. Any code that has been executed will continue to run, even if the XBee device is set to Transparent or API mode."


page 15
0 votes
MicroPython code runs at startup if ATPS=1, regardless of the value of ATAP. If that code crashes for some reason, it won't restart automatically. You might need to wrap your code in a try/except, and possibly log the exception to the file system (for debugging purposes) before retrying/restarting the code you're trying to execute.

When ATAP != 4, everything you print from MicroPython will disappear. But your code is still running. As noted in previous questions, you can use User Data Relay frames to send data between the host (with ATAP=1) and your MicroPython program.
answered Aug 4, 2020 by TomCollins Veteran of the Digi Community (2,382 points)
this is awesome if true. thank you for the info.

however I do not see this in practice. right now I have a micropython script uploaded onto my router device such that when you power cycle, ps=1 and the router immediately sends it's MAC address to the coordinator.. then the router gets assigned a new NI and populates a dictionary.
so when I put the device in API mode (AP=1) and power cycle.. I see nothing happen.. my python print statements telling me that the device was assigned an NI and put in the dictionary doesn't print out... then when I switch the device back to REPL (AP=4) and powercycle… my python print statements work accordingly... confirming the message was sent from firmware upon start-up, the device assigned an NI, and stored in a dictionary.

so from this little trial... the code does not auto-run when PS=1 & AP=1....

I hope I'm wrong though because what you initially said would be super great news for what I'm trying to accomplish.. what do you think?
As mentioned in my answer, you will not see the output of MicroPython print statements when ATAP!=4.  The code is still running.

If your code is changing NI, you can enter command mode and type ATNI to see that it's using the new value.

Also make sure that the XBee has joined the network before you try sending a message to the coordinator.  You can check xbee.atcmd('AI') in your MicroPython program and wait until it's 0 before trying to send.

As a test, write a simple program to flash an LED on and off and you'll see that it's running at startup.
I will give it a try.

However, all the micropython uploaded on the device does is send a message to the coordinator. then python program receives this message and reassigns an NI and prints things into the python window...
when in ATAP=4, upon power-on the device runs the micropython and I get what I want in my python program.. once I set the ATAP=1, I dod not see the python print statements, nor does the device get a new NI...

but you seem sure It should run just fine (minus printing to repl console etc.)
ok I believe you, uploaded a simple led flashing micropython code to the device.. went into xctu and wrote ATAP=1 to the device, upon restarting the device the LED flashed! great. So, hopefully, must be a problem with my other code. maybe it runs too quickly, sends a message before the coordinator is ready to receive and do python things..
I was thinking that might be it.  To test that theory, you could just `import time` at the start of your MicroPython program, and have a `time.sleep(3)` to sleep for 3 seconds before sending your message.  Also note that you could enable "join notifications" on the coordinator, and it will generate an API frame automatically when the node joins, so it doesn't need to send a message from MicroPython.  Check the XBee3 Zigbee documentation for details on how that feature works.
ok. thank you.

I have a
while xbee.atcmd("AI") != 0:
at the top of the firmware file already...
ok... so
I upload the firmware code in ATAP=4. Consistently, when I press reset on the device... it auto-runs, sends to coordinator into python, I see what I expect. it works!

then I go in xctu, switch it to ATAP=1 (API mode). press reset on the device. nothing.. no new NI, no python print outs. nothing.

then I go back into xctu, set back to REPL (ATAP=4). press reset on the device. works great again (I see whati want in the python print outs and the NI gets reassigned).

here is the code (micropython sample import.. almost no changes) again, works in clearly does what I want it to in ATAP=4, then doesn't cooperate once I switch ATAP=1.. then back to working when I set ATAP back to 4.


import sys
import xbee
import time

# TODO: replace with the node identifier of your target device.
filler = "don't mind me"

while xbee.atcmd("AI") != 0:

def find_device(node_id):
    Finds the XBee device with the given node identifier in the network and
    returns it.

    :param node_id: Node identifier of the XBee device to find.

    :return: The XBee device with the given node identifier or ``None`` if it
        could not be found.
    for dev in xbee.discover():
        if dev['node_id'] == node_id:
            return dev
    return None

# Find the device with the configure node identifier.
device = find_device(TARGET_NODE_ID)
if not device:
    print("Could not find the device with node identifier '%s'" % TARGET_NODE_ID)

addr16 = device['sender_nwk']
addr64 = device['sender_eui64']

print("Sending data to %s" % TARGET_NODE_ID)
# micropython.mem_info([verbose])... SUPPOSE TO PRINT OUT how much memory is being used or something?
    # Some protocols do not have 16-bit address. In those cases, use the 64-bit one.
    xbee.transmit(addr16 if addr16 else addr64, filler)
    print("Data sent successfully")
except Exception as e:
    print("Transmit failure: %s" % str(e))

when you said "Also note that you could enable "join notifications" on the coordinator," .. the join notification sends a broadcast notification when from a node that just powered on / joined.. so if I set that on the coordinator.. maybe you meant to set that on the routers instead, yeah?

I want the router, once plugged in, to somehow get its MAC address to the coordinator/python program so that that router may be assigned a particular NI, depending on where you plugged it in physically.
but anyways, one problem at a time lol. as long as this router, in API mode, sends a message to the coordinator upon start-up.. big success there. Again, works in ATAP=4, doesn't work when change to ATAP=1, change back to ATAP=4 - works.
yeah I've sat here for the last 30 minutes...
python/micropython IDE(s) open, xctu open.. start in ATAP=4 - press reset, message sends as confirmed in python console. click in xctu, ATAP set to = 1 - press reset on device.. nothing.. reset ATAP=4 - press reset on device, confirms to work as seen in python console... over back to xctu ATAP=4, then again ATAP=1, over and over for 30 minutes. doesn't seem to work in ATAP=1 lol

but also I believe you so what am I doing wrong lol
so in xctu in the info drop down of the AP setting it says:

"The API mode setting. RF Packets received can be formatted into API frames to be sent out the serial port. When API is enabled the serial data must be formatted as API frames as transparent mode is disabled."

could this be the problem?.. that the micropython code that I posted in a previous comment maybe doesn't send the data in proper format (as API frames)?

0 votes
First commment is very helpful.
answered Aug 13, 2020 by annacarter478 New to the Community (1 point)