esp8266 async sockets

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
amwales
Posts: 2
Joined: Wed Jun 08, 2016 1:46 pm

esp8266 async sockets

Post by amwales » Wed Jun 08, 2016 1:51 pm

I would like to process UDP and TCP data in an async manner.
What is the recommended approach with in micropython for esp8266.
I was unable to import select/poll and I didn't see SO_NONBLOCK so dont think I can
just poll the sockets myself in a non blocking way. Ideas?


markxr
Posts: 62
Joined: Wed Jun 01, 2016 3:41 pm

Re: esp8266 async sockets

Post by markxr » Wed Jun 08, 2016 5:49 pm

The microcontroller does not have a multitasking operating system, so it's ok to enter a busy-waiting loop checking the sockets and anything else that needs checking.

You can do that under an OS (e.g. Linux) too, but it uses CPU time that other tasks could use, which is why it's generally discouraged. Also for a large number of sockets it can be inefficient.

On the ESP neither of these things matter, because you can't have many sockets anyway, and there are no other tasks.

---

Actually there's another method entirely which the webrepl.py uses - setsockopt(socket.SOL_SOCKET, 20, handler) - but this is undocumented so I guess it might go away if webrepl stopped using it.

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: esp8266 async sockets

Post by pfalcon » Thu Jun 09, 2016 3:05 pm

select.poll isn't yet implemented for esp8266.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Post Reply