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, 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 (13,998 points)
So, everytime I want to read the sensor values on the slave deivce that is on the i2c bus of the XBee router(master).. I would have to
remote_device.set_parameter("AP", bytearray('\x04', 'utf8'))
real quick to grab those values? you think?
is it okay to frequently .set_parameter between API and REPL mode?..
fine to go between those 2 settings often in a program?
Yes. I do.

No, that would be a bad idea. It would be far better to add what functions you want in your Micro Python code and the set it so that when ever you get an A for example function B is run.
why is it a bad idea?

also I don't understand your "A-B" scenario. The only reason I am using micropython is for 2 things..
1.) sending the MAC address of the auto-start device (PS=1) at start-up.
and then
2.) pulling data from various sensors on the i2c port expander.

so like.. before I preform some action in the outside world, I would read the sensors to make sure certain things are in the correct position.

so is that what you mean by "A-B".. when I want to read the values... set AP=4 and then read the values and then set AP=1 again like I said? orr?

also, glad that you think lol
Micro Python can only run when in Micro Python mode (ATAP4). Putting the radio in any other value will turn off Micro Python mode and prevent the application from running.

The functions I am referring to would be more like, Read ADC value from ADC1, Read I2C port, transmit data over RF port, transmit/receive over Micro Python UART.
ok.. are you thinking these functions would be written in Python or in the MicroPython?

Also, what is wrong, in your thoughts, with setting the device to MicroPython mode (ATAP4) whenever you need it to be in MicroPython mode (auto-start stuff, reading i2c sensors) and then going back to API mode.

Don't the devices have to be in API mode in order to have a multi-node network of communications? Wait.. in REPL mode can you do everything that you normally would do in API mode?.. plus micropython?.. and that's why I should just stay in REPL mode?

Im confused.. all my devices will have auto-start firmware flashed on them.. but primarily function through my Python project. The Micropython is mainly for extra IO ports.
Then why are you using an XBee?  Are you just using it for an I2C interface?  If so, why are you not just using an I2C expansion board?
Hm,
I am using the xbee fully.. a a wireless network of 20 routers and 1 coordinator. All pins on each of the xbee router modules are being used. So I needed more I/O.. hence the i2c I/O expander slave device with the xbee as master.

so I have my main python program that has a GUI and GUI buttons so you can turn the xbee pins on/off and whatnot.. but then the i2c io expander will be full of sensors.

the other thing im doing with the micropython is when a router is plugged in, it auto-runs the firmware and sends a message to the coordinator, which then assigns that router a new NI.

so, being able to keep the device in API mode for most of the time... but then read the i2c sensor values whenever you need to(REPL AP = 4 mode?).. would be ideal
So is the other Python application on a processor connected to the Coordinator or are all of the Xbee connected to different processors ?
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, 2020 by TomCollins Veteran of the Digi Community (2,089 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, 2020 by annacarter478 New to the Community (1 point)
...