WebREPL not working with main.py-started app (fixed)

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
yolk
Posts: 5
Joined: Wed Jul 20, 2016 6:47 am

WebREPL not working with main.py-started app (fixed)

Post by yolk » Wed Jul 20, 2016 7:00 am

Hi!

I used WebREPL to interactively play around with my board without any issues. I start WebREPL within boot.py.
After starting another program (after WebREPL in boot.py) however, WebREPL does not properly work any more. When trying to log in, I'm queried for the password, and after that, I don't get any response any more (not even a newline after entering the password).
The other program I launch apparently continues execution without issues. It basically consists of a main loop in the form of " while True: measure something; send to server; delay 60s".
My guess is that the incoming WebREPL connection preempts (?) this main loop, and the connection is handled up to the point that the initial welcome message and the password prompt is sent to the client. Further IO on the WebREPL connection however is not handled as the main loop is not preempted any more. Does this make sense?
How can this be avoided? That is, how can I execute some sort of main loop while remaining responsive to WebREPL? Is there some function I could call within the main loop that triggers the handling of pending connections?


Thanks in advance!

Thanks,

yolk

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

Re: WebREPL not working with main loop

Post by pfalcon » Wed Jul 20, 2016 11:29 am

No, WebREPL just doesn't work how you apparently think it does. ESP8266 is not a gigahertz/gigabyte machine where each opens a new independent session, like telnet/SSH connection to Unix boxes does. ESP8266 is very resource-constrained device, and there's only one session running. You can access that session either via UART or WebREPL. That's it. So, when you connect via WebREPL, you get to your running application. If it doesn't accept any input and doesn't produce any output, it appears to be "hung" for you. Ctrl+C it to get back to the Python interactive prompt if that's what you want.
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/

yolk
Posts: 5
Joined: Wed Jul 20, 2016 6:47 am

Re: WebREPL not working with main loop

Post by yolk » Wed Jul 20, 2016 1:34 pm

Hi!

Thanks for the quick reply!

[quote="pfalcon"]No, WebREPL just doesn't work how you apparently think it does. ESP8266 is not a gigahertz/gigabyte machine where each opens a new independent session, like telnet/SSH connection to Unix boxes does. ESP8266 is very resource-constrained device, and there's only [i]one session[/i] running. You can access that session either via UART or WebREPL. That's it. So, when you connect via WebREPL, you get to your running application. [/quote]
Yes, that's roughly what I assumed.

[quote="pfalcon"] If it doesn't accept any input and doesn't produce any output, it appears to be "hung" for you. Ctrl+C it to get back to the Python interactive prompt if that's what you want.[/quote]
Ctrl+C doesn't have any effect, the application continues executing. Also, I don't get the debug output of the running application.


Thanks,

yolk

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

Re: WebREPL not working with main loop

Post by pfalcon » Wed Jul 20, 2016 2:55 pm

yolk wrote: Ctrl+C doesn't have any effect, the application continues executing. Also, I don't get the debug output of the running application.
A can't reproduce this with a minimal test script. So, feel free to prepare a minimal code snippet to reproduce the issue, and submit a ticket on github with the exact steps to reproduce and related information (see viewtopic.php?f=16&t=1689 for more info).
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/

yolk
Posts: 5
Joined: Wed Jul 20, 2016 6:47 am

Re: WebREPL not working with main loop

Post by yolk » Thu Jul 21, 2016 3:46 pm

Hi!

I just flashed a freshly compiled version (26b7d8a7b) onto my board (NodeMCU V3, the cheap one from China).
My boot.py is

Code: Select all

# This file is executed on every boot (including wake-boot from deepsleep)
import webrepl
webrepl.start()

import testapp
testapp.loop()
and testapp.py is

Code: Select all

import utime as time

def loop():
	while True:
		print(".")
		time.sleep(10)
Apart from setting up the network connection and uploading the scripts above, the board is in vanilla state. As I previously described, WebREPL prompts for the password and then does not show any reaction.

Can someone reproduce this?

Thanks in advance!

Thanks,

yolk

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: WebREPL not working with main loop

Post by pythoncoder » Fri Jul 22, 2016 8:19 am

@yolk I can reproduce this. I must admit it isn't obvious to me why this main.py fails to let me log in:

Code: Select all

import webrepl
import time
webrepl.start()
time.sleep(20) # Allow time for me to log in
import testapp
testapp.loop()
The following, of course, works. main.py

Code: Select all

import webrepl
webrepl.start()
Followed by (at webrepl prompt)

Code: Select all

import testapp
testapp.loop()
It would seem that the firmware needs to get to the Python prompt before webrepl can accept a login and provide a REPL.
Peter Hinch
Index to my micropython libraries.

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

Re: WebREPL not working with main loop

Post by pfalcon » Fri Jul 22, 2016 9:27 am

yolk wrote:Can someone reproduce this?
Thanks, with the details above, I was able to reproduce it. I'm looking into it.
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/

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

Re: WebREPL not working with main loop

Post by pfalcon » Fri Jul 22, 2016 9:07 pm

This was fixed in master.
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/

yolk
Posts: 5
Joined: Wed Jul 20, 2016 6:47 am

Re: WebREPL not working with main loop

Post by yolk » Sat Jul 23, 2016 8:28 am

Hi!
pfalcon wrote:This was fixed in master.
Works like a charm. Thanks!

Maybe that's a good time to emphasize that I'm really excited about the MicroPython project and the immediate help you and others provide!


Thanks,

yolk

Post Reply