autostart micropython on XBee3

We cannot get our XBee3 micropython code to start automatically without using MicroPython REPL. We set the AT PS 1 command to autostart but it will not run at startup. I know the code runs manually because we can start it with XCTU. We can go to “MicroPython Terminal” and open the connection. Then we do a “soft reset” and the code starts running in the terminal. I am using XB3-24, XBee3 Zigbee3, 1007 firmware.

I suspect your code is actually starting but crashing immediately after startup. One possible reason is that it makes calls to xbee before xbee has connected to the ZigBee network and this triggers exception and exits to the REPL prompt with this error if you don’t catch the exception:

Traceback (most recent call last):
File “”, line 3, in
OSError: [Errno 7107] ENOTCONN

One way to troubleshoot this is to run this at the REPL prompt:
import xbee

This performs a hard reset but leaves you connected to watch what happens as it boots. If it’s crashing, you should see it.

To wait for it to connect to the Zigbee network, you can use this code:

while xbee.atcmd(“AI”) != 0:

And in general, you should surround all code with try/except blocks to avoid crashing to the REPL prompt:


except Exception as e: