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 ... 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.
Asynchronous requests
Re: Asynchronous requests
You could try threads.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Asynchronous requests
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.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Asynchronous requests
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.
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
ENOMEM is a memory error. Did you try to increase the stack size for the thread?
Re: Asynchronous requests
Thank you for the info.
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.
I also do not understand why my other network calls are working fine but I'm only having trouble with Google API
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)