Home/Support/Support Forum/Error with the .mpy file uploaded on the xbee module

Error with the .mpy file uploaded on the xbee module

0 votes
I'm using micropython on an XBee3. After testing the program with the Python's IDLE terminal:

from digi.xbee.devices import XBeeDevice
import time, sys

while True:
time.sleep(1)
print("Start\r\n")

I cross-compile to generate .mpy files:

python -m mpy_cross -mno-unicode -msmall-int-bits=31 main.py

It generates main.mpy, which I then upload with the file manager in XCTU.

When starting on the xbee module, the program generates an error message:

Loading /flash/main.mpy...
Running bytecode...
Traceback (most recent call last):
File "main.py", line 1, in <module>
ImportError: no module named 'digi'

It seems that despite the cross-compile, it does not find the import path...

has anyone ever solved the problem ?

Thank you
asked Jun 5 in MicroPython by popo New to the Community (0 points)
recategorized Jun 24 by TomCollins

Please log in or register to answer this question.

2 Answers

0 votes
The cross-compile will only compile that .py file. If you're using modules outside of the embedded modules on the XBee 3 firmware, you need to upload them as well.

That said, you probably won't be able to use the XBeeDevice class from digi.xbee.devices. Look at the MicroPython support documentation for the XBee3 or this repository of sample modules and programs:
https://github.com/digidotcom/xbee-micropython

Digi has also released a PyCharm plugin for working with MicroPython on the XBee3 products:
https://www.digi.com/support/productdetail?pid=5674
answered Jun 24 by TomCollins Veteran of the Digi Community (1,457 points)
0 votes
MicroPython does not contain all the same modules you're used to in CPython. Your error means there is no digi module.

You can get a list of modules by running (this is in firmware 1008):
>>> help('modules')
__main__ io time uos
array json ubinascii ustruct
binascii machine uerrno utime
builtins micropython uhashlib xbee
errno os uio
gc struct ujson
hashlib sys umachine


You see no "digi" listed but there is "xbee". You can see what xbee contains using this command:

>>> import xbee
>>> help(xbee)
object <module 'xbee'> is of type module
__name__ -- xbee
XBee -- <class 'XBee'>
atcmd -- <function>
relay -- <module 'relay'>
discover -- <function>
receive -- <function>
transmit -- <function>
ADDR_BROADCAST -- b'\x00\x00\x00\x00\x00\x00\xff\xff'
ENDPOINT_DIGI_DATA -- 232
CLUSTER_DIGI_SERIAL_DATA -- 17
PROFILE_DIGI_XBEE -- 49413
ADDR_COORDINATOR -- b'\x00\x00\x00\x00\x00\x00\x00\x00'
PIN_WAKE -- 1
RTC_WAKE -- 2

The MicroPython xbee module is far more limited than the CPython xbee module. You can find documentation by searching the web for "MicroPython programming guide 90002219" then check the "XBee module" section. I recommend reading through a lot of the guide for basic information.
answered Oct 24 by Janala New to the Community (7 points)
...