Page 1 of 1

Asynchronous requests

Posted: Sat Aug 10, 2019 5:02 pm
by Oct_opus
Hello everyone,

I have recently started making a smart watch project using the ESP32 board with OLED using Micropython.
https://github.com/Oct-opus/Ayon

When adding GET requests to fetch from Google Drive, I found out about network requests blocking the OLED from updating.
I was happy to change my code and use the uasyncio lib and call it a day :lol: ... but sadly it seems that uasyncio still uses blocking requests.

I've looked into peterhinch/micropython-mqtt and his implementation of non-blocking sockets but it seems to be turned around connecting to a server and not make REST calls.
In the uasyncion repo, they talk about making non-blocking socket calls and share this and example.
https://github.com/peterhinch/micropyth ... onblock.py

I don't know how I could use the concept in a rewrite of the urequeust module.
Would you happen to know of a solution or what I could implement?

Thank you.

Re: Asynchronous requests

Posted: Sat Aug 10, 2019 7:41 pm
by Roberthh
You could try threads.

Re: Asynchronous requests

Posted: Sun Aug 11, 2019 6:43 am
by pythoncoder
The is this approach which devolves the networking code to a more capable device such as a Raspberry Pi on the wired network. Communication between the Pi and your watch is by an asynchronous socket-like exchange of messages.

Re: Asynchronous requests

Posted: Sun Aug 11, 2019 3:54 pm
by Oct_opus
Thank you for your responses.

I'm not really looking into using another device alongside the smart watch project as it would only add complexity.
Currently I can turn my phone into a wifi hotspot and use it as is.
I could maybe in a second time add bluetooth to the project and the make a mobile native app to communicate with.

I have tried to uses treads but I get a [Errno 12] ENOMEM from the network request.
Weirdly it only happens when I call the google API and not the weather or clock one. It might be the duration of POST call witch causes it.

Re: Asynchronous requests

Posted: Sun Aug 11, 2019 7:04 pm
by Roberthh
ENOMEM is a memory error. Did you try to increase the stack size for the thread?

Re: Asynchronous requests

Posted: Mon Aug 12, 2019 12:48 pm
by Oct_opus
Thank you for the info.
Roberthh wrote:
Sun Aug 11, 2019 7:04 pm
ENOMEM is a memory error. Did you try to increase the stack size for the thread?
I tried the _thread.stack_size method but I still get the same error.
It's weird because even if I only put a useless function like this inside a thread and everything outside of it the network call still doesn't work.

Code: Select all

def test():
	while True:
		print("Alive")
		utime.sleep(1)
I also do not understand why my other network calls are working fine but I'm only having trouble with Google API :(