MicroPython XBee3: transmit data example

Ok so I have a python program that has a callback function that runs when the coordinator receives data from my MicroPython upload on the router device. The PS is enabled on the router device (autorun flashed firmware upon start-up).

I’m using an imported transmit micropython example through my Pycharm plugin.

So when I run my python program and then run the micropython program, the message from the micropython on the router module successfully sends a message to the coordinator, as confirmed by printing out the message on my python program’s Run window. So that is good!

I see this in my REPL with the first successful upload/run of the flashed firmware program:

soft reboot

Loading /flash/main.mpy…
Running bytecode…
Sending data to COORD
Data sent successfully

MicroPython v1.11-1443-g5fad4cf on 2020-04-16; XBee3 Zigbee with EFR32MG
Type “help()” for more information.

the problem is that once I do this… and then press the reset button on my flash uploaded router module, instead of a successful auto-run-upon-start-up transmission I get this in my REPL:

Loading /flash/main.mpy…
Running bytecode…
Traceback (most recent call last):
File “/flash/main.py”, line 48, in
File “/flash/main.py”, line 41, in find_device
OSError: [Errno 7107] ENOTCONN

MicroPython v1.11-1443-g5fad4cf on 2020-04-16; XBee3 Zigbee with EFR32MG
Type “help()” for more information.

I was hoping to instead witness a successful “micropython autoruns on start-up” type of scenario… even when I unplug the device and plug it back in it doesn’t seem to auto-run the program.

Again, the first micropython upload/run was successful. But after that when I unplug and plug back in I don’t get another successful transmission, thereby failing to autorun upon start-up.

What am I not understanding here?


You need to give the module time to get onto a network.

Maybe call atcmd(‘AI’) (in your MicroPython code) every second until it returns 0, and then try to send your data.

import time, xbee
# wait for XBee to join network
while xbee.atcmd('AI') != 0:
# continue with previous code...

ooo ok interesting. How to call an atcmd(‘AI’) in Python programming? EDIT* I see the “get_parameter(String)” method might be what you are talking about, at least in the Python XBee Library documentation. or wait, do you mean to call this in my MicroPython program instead?

I’m talking about MicroPython. The atcmd() method is in the xbee module. I’ve updated my answer with a snippet of code that should work.