If I run a uasyncio task, while the task is running, the WebREPL prompt seems totally frozen.
Here is a demo code (tested on esp32):
boot.py:
Code: Select all
import network
ap = network.WLAN(network.AP_IF) # create access-point interface
ap.config(essid='ESPTEST')
ap.config(authmode=3, password='testitbaby') # set the SSID of the access point
ap.active(True)
import webrepl
webrepl.start()
Code: Select all
import uasyncio
import time
class Context:
WATCHDOG_TIMEOUT = 3
watchdog_last_feed_epoch = 0
def webrepl_active():
prev = uos.dupterm(None)
uos.dupterm(prev)
if prev:
return True
return False
async def periodical_tasks(context):
while True:
print('current time is:', time.time())
print('watchdog_last_feed_epoch:', context.watchdog_last_feed_epoch)
if webrepl_active():
context.watchdog_last_feed_epoch = time.time()
print('webrepl is active!')
if time.time() - context.watchdog_last_feed_epoch > context.WATCHDOG_TIMEOUT:
print ('prepare_for_deepsleep')
gc.collect()
await uasyncio.sleep(context.WATCHDOG_TIMEOUT)
async def main(context):
uasyncio.create_task(periodical_tasks(context))
await uasyncio.sleep(20)
context = Context()
# uasyncio.run(main(context))
While the async task is running (20 sec), I can not type anything into the command line.
However I can upload files, and disconnect and (re)connect to the board, and I can even enter the password.
But the command line is frozen.
My goal is to go to deepsleep via a background service after 20 sec inactivity (button input or lack of webrepl connection). And wakeup after 10 minutes or button input (irq). And be *able* to use webrepl.
The board is on a battery, and it runs out of juice after about 4 hours without deepsleep. For developing, I just want to leave it on, and connect it whenever necessary.
Any idea how to launch webrepl so it stays responsible, while there is an uasyncio background task scheduled/running?