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?

thanks..

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 in MicroPython by edunn106 New to the Community (24 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 by mvut Veteran of the Digi Community (13,472 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."

file:///C:/Users/edunn/Desktop/MicroPython_Guide.pdf

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 by TomCollins Veteran of the Digi Community (2,051 points)
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.

code:

----
import sys
import xbee
import time


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

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


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)
    sys.exit(-1)

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?
try:
    # 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)?

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