ESP32 Debouncing Switches & Relays: IRQ Timer vs Simple Code vs ASYNC

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
pythoncoder
Posts: 3244
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ESP32 Debouncing Switches & Relays: IRQ Timer vs Simple Code vs ASYNC

Post by pythoncoder » Wed Feb 13, 2019 12:22 pm

You need to read up on Python packages. The server example I gave you is organised as a package, and the import is from __init__.py. However I wouldn't spend time trying to follow the application code.

I suggest you look at the _send and _read methods as examples of how to write to and to read from nonblocking sockets. The key point is that an operation on a nonblocking socket returns immediately whether or not it has completed the job it was given. A read may return partial data or none, and a write may not write everything. So your code has to handle those conditions as well as coping with errors.

The other part which might be of interest is the _run method which performs the initial connection to one or more clients.
Peter Hinch

User avatar
iotman
Posts: 16
Joined: Sat Feb 02, 2019 4:06 pm
Location: Nanoose Bay
Contact:

Re: ESP32 Debouncing Switches & Relays: IRQ Timer vs Simple Code vs ASYNC

Post by iotman » Wed Feb 13, 2019 5:42 pm

Hi Peter, thank you very much for your reply; it is very much appreciated.

I will follow your advice and study the Python syntax. My main problem was the de-bouncing, and that async approach of yours works like a charm.

Best Regards, AB

Post Reply