Resilient aysnchronous MQTT optimim use

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Resilient aysnchronous MQTT optimim use

Post by kevinkk525 » Tue Jul 30, 2019 5:00 pm

Sorry but with this code I'm starting to doubt your experience (at least in regards of python). You should be able to find the mistakes yourself but I'll give you a hint anyways as you might have misunderstood some underlying concepts (which are the same as in python..):

The queue will always be empty because you don't add anything to it.
Uasyncio and mqtt_as don't access your queue in any way.

If you just want to print the length of the Uasyncio queue use this:

loop=asyncio.get_event_loop()
print(len(loop.waitq))

Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

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

Re: Resilient aysnchronous MQTT optimim use

Post by pythoncoder » Wed Jul 31, 2019 5:36 am

Quite.
Peter Hinch
Index to my micropython libraries.

RobinMosedale
Posts: 40
Joined: Fri Jul 26, 2019 9:40 pm

Re: Resilient aysnchronous MQTT optimim use

Post by RobinMosedale » Wed Jul 31, 2019 11:51 am

Quite right. Asyncio is new to me. Not at all familiar with it and learning

Thanks

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

Re: Resilient aysnchronous MQTT optimim use

Post by pythoncoder » Wed Jul 31, 2019 5:11 pm

kevinkk525 wrote:
Tue Jul 30, 2019 5:00 pm
If you just want to print the length of the Uasyncio queue use this:

loop=asyncio.get_event_loop()
print(len(loop.waitq))
In the general case it's not as simple as that because there are two queues: there is also .runq.

.waitq holds tasks which are suspended pending a time delay whereas .runq holds tasks which are ready to run. If a task yields with

Code: Select all

await asyncio.sleep(0)
it goes straight onto .runq where it may compete for round-robin execution with other similar tasks. Likewise a task on .waitq moves to .runq when its execution time arrives.
Peter Hinch
Index to my micropython libraries.

RobinMosedale
Posts: 40
Joined: Fri Jul 26, 2019 9:40 pm

Re: Resilient aysnchronous MQTT optimim use

Post by RobinMosedale » Wed Jul 31, 2019 6:17 pm

Thank you Peter, that's kind.

I really don't wish to use this thread as a vehicle for me to learn (u)asyncio and bother you two kind and generous people. Just point me to a module/object/function spec.

This really is a diverting branch to facilitating a comms method for what I'm doing elsewhere, and grateful that I can use and monitor this resilient function with some degree of competence. It's an enabler. Once I'm confident that I'm employing the features with reasonable competence, then I'll be off to the main task.

Robin

Post Reply