https://github.com/shawwwn/micropython-ainput
Asynchronous user input libraries using the MicroPython uasyncio
https://github.com/shawwwn/micropython-ainput
input micropython repl telnet uasyncio
Last synced: about 2 months ago
JSON representation
Asynchronous user input libraries using the MicroPython uasyncio
- Host: GitHub
- URL: https://github.com/shawwwn/micropython-ainput
- Owner: shawwwn
- License: mit
- Created: 2018-02-01T01:15:18.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-22T07:45:22.000Z (over 7 years ago)
- Last Synced: 2025-07-03T19:06:42.510Z (12 months ago)
- Topics: input, micropython, repl, telnet, uasyncio
- Language: Python
- Homepage:
- Size: 17.6 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# micropython-ainput
Asynchronous user input libraries using MicroPython [uasyncio](https://github.com/micropython/micropython-lib/tree/master/uasyncio) library
## uaioinput
Library for for getting user input inside uasyncio event-loop
NOTE(**\***):\
For this to work on esp32, you need to use [my fork of micropython](https://github.com/shawwwn/micropython) which incorperates a hack on the UART console.
#### Usage
```python
import uasyncio
from uaioinput import ainput
s = await ainput(prompt="User Input: ", password=False)
print(s)
```
To prevent two `ainput()` being called at the same time, a global **lock** is
implemented at the module level.\
To check **lock** status,
```python
import uaioinput
print(uaioinput.input_lock.locked)
```
#### Dependencies
* [micropython-uasyncio.synchro](https://github.com/micropython/micropython-lib/tree/master/uasyncio.synchro)
## uaiorepl
A simple(dumb) REPL console that runs inside uasyncio event-loop.\
Features are severely limited comparing to the standard REPL,
only basic operations are supported.
NOTE(**\***):\
`ctrl+b` for manual linebreak\
For this to work on esp32, you need to use [my fork of micropython](https://github.com/shawwwn/micropython) which incorperates a hack on the UART console.
#### Usage
```python
import uasyncio
import uaiorepl
loop = uasyncio.get_event_loop()
loop.call_soon(uaiorepl.start())
loop.run_forever()
```
## uaiotelnet
Modified telnet server that runs inside uasyncio event-loop.\
Adapted from **cpopp**'s [MicroTelnetServer](https://github.com/cpopp/MicroTelnetServer)
NOTE(**\***):\
Must run concurrently with a `uaiorepl` or `uaioinput` otherwise user input will still be blocked.
NOTE:\
If you are using Putty in windows as your telnet client, then you must set the following parameters:\
* Terminal - Local echo - force off
* Terminal - Local line editing - force off
* Connection - Telnet - [UNCHECK] Return key sends Telnet New Line instead of ^M
#### Usage
```python
import uasyncio, uaiotelnet, uaiorepl
loop = uasyncio.get_event_loop()
loop.call_soon(uaiotelnet.start(ip="0.0.0.0", port=23))
loop.call_soon(uaiorepl.start()) # uasyncio repl will process telnet input
loop.run_forever()
```
## uaiowebrepl
The offical implementation of WebREPL relies on socket interrupt and can be horribly slow.
This modified WebREPL runs inside uasyncio event-loop and is way faster than the official one.\
Adapted from [the offical WebREPL for ESP8266](https://github.com/micropython/micropython/blob/master/ports/esp8266/modules/webrepl.py)
NOTE:\
Must run concurrently with `uaiorepl` or `uaioinput` otherwise user input will still be blocked.
#### Usage
```python
import uasyncio, uaiowebrepl, uaiorepl
loop = uasyncio.get_event_loop()
loop.call_soon(uaiowebrepl.start(ip="0.0.0.0", port=8266, password=123))
loop.call_soon(uaiorepl.start()) # uasyncio repl will process webrepl input
loop.run_forever()
```