Home/Support/Support Forum/autostart micropython on XBee3

autostart micropython on XBee3

0 votes
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.
asked Sep 16 in XBee3 ZigBee by curryte New to the Community (0 points)

Please log in or register to answer this question.

1 Answer

+1 vote
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 "<stdin>", line 3, in <module>
OSError: [Errno 7107] ENOTCONN

One way to troubleshoot this is to run this at the REPL prompt:
import xbee
xbee.atcmd('FR')

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:
time.sleep(0.1)

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

try:
<code>
except Exception as e:
<log or sys.print_exception(e)>
answered Oct 7 by Janala New to the Community (6 points)
...