Threads in xbee 3

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
manos
Posts: 27
Joined: Mon Sep 28, 2020 9:03 am

Threads in xbee 3

Post by manos » Fri Nov 27, 2020 7:54 am

Hi,

Programming my XBee 3 RF Zigbee module via MicroPython, I have faced some issues that I believe I could overcome by using threads.
So, I would like to ask, how can I program with threads in the MicroPython environment of the XBee3?
Shall I install the Xbee-Python Library (by the command: pip install digi-xbee)?
Any kind of guidance or useful links is more than welcomed!!!

Thanks in advance!

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Threads in xbee 3

Post by pythoncoder » Fri Nov 27, 2020 9:42 am

I would only consider threads after studying uasyncio and having a good reason for rejecting it. This is for reasons discussed here and here.
Peter Hinch
Index to my micropython libraries.

manos
Posts: 27
Joined: Mon Sep 28, 2020 9:03 am

Re: Threads in xbee 3

Post by manos » Fri Nov 27, 2020 12:14 pm

Thanks for your reply!

I will check it, but I am not sure if this module already exists in the MIcroPython environment of the XBee 3...
At least, import uasyncio raises an error: ImportError: no module named 'uasyncio'
Do you know how can I install it?

Thanks again

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Threads in xbee 3

Post by Roberthh » Sat Nov 28, 2020 7:32 pm

There is no thread or uasyncio support in XBEE micropython.

manos
Posts: 27
Joined: Mon Sep 28, 2020 9:03 am

Re: Threads in xbee 3

Post by manos » Sun Nov 29, 2020 9:09 pm

Hey,
Thanks for your answer. Some (3) extra questions:

1) Does that mean that there is no way that I can program in threads???

Moreover, I have noticed that in the xbee-python library (which I still don't know when/where this library shall be used, so maybe it is irrelevant - please let me know if it is so or not) there are some samples of code where there is a module imported named "threading". Is that something that might be useful?
2) So, when is xbee-python library (https://xbplib.readthedocs.io/en/latest ... brary.html)
suggested to be used and can it provide a solution with programming in threads?

Lastly, sorry for persisting but XBee comes with a tranceiver chipset (Silicon Labs EFR32MG SoC) which I guess has various functionalities, so in a way, this kind of problem(not being able to utilize some of the abilities provided by the microprocessor) might occur and therefore is important to me. Is there any way to overcome this type of problems and if so, which are those?
3) Maybe a way would be that I program the microprocessor in "bare metal" (i.e in C) and then use this module to "extend" Micropython environment's ability?

Thanks in advance!

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Threads in xbee 3

Post by Roberthh » Mon Nov 30, 2020 7:17 am

As far as I can tell, there is not way to work with threads or asyncio on the XBEE 3, especially given the small heap size of the MP implementation. The platform for xbee-python library seems to be PC or the like, not the XBEE module itself.
Sorry that I cannot answer the questions under 3.

manos
Posts: 27
Joined: Mon Sep 28, 2020 9:03 am

Re: Threads in xbee 3

Post by manos » Mon Nov 30, 2020 11:03 am

@Roberthh thank you so much!!! Your help is really important to me!

Don't worry about the third question, maybe someone else can lend a hand.
Regarding the xbee-python library, you mean that is a library which is installed in a PC and is simulating the XBee? Although, I don't really understand what that can actually mean...
Lastly, thank you again for your answer and particularly for clearing up the issue with threads or uasyncio and mp's heap.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Threads in xbee 3

Post by Roberthh » Mon Nov 30, 2020 11:43 am

Regarding the xbee-python library, you mean that is a library which is installed in a PC and is simulating the XBee? Although, I don't really understand what that can actually mean...
I had the impression that this library interfaces with the XBEE 3 and uas it for instance as modem for communication. But I may be wrong.

manos
Posts: 27
Joined: Mon Sep 28, 2020 9:03 am

Re: Threads in xbee 3

Post by manos » Mon Nov 30, 2020 12:46 pm

Ok, so in that case you install xbee-python library in the host pc. Then you somehow connect xbee with the host pc and without accessing the MicroPython environment of the xbee, you manage the xbee to work as a modem (in the example you mentioned) from the MicroPython environment of your pc (probably through some serial communication)? Or am I getting it wrong?

Moreover, I would like to ask, if you know whether the xbee offers the ability to use timers and interrupts or it it not feasible, as threading for instance?

Thanks again

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Threads in xbee 3

Post by Roberthh » Mon Nov 30, 2020 3:00 pm

Looking through the classes of the digimesh module I have here and the manual, I see no evidence of timers or interrupts.
In the micropython module there is micropython.schedule(). And in the communication modules for BLE and xbee there are various callbacks. But they cannot be reliably used for some kind of parallel execution.

Post Reply