webrepl problem

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
mmx64
Posts: 10
Joined: Sat Aug 28, 2021 8:24 am

webrepl problem

Post by mmx64 » Wed Sep 15, 2021 8:04 am

Hello, im trying to setup webrepl on my bord, loin32

boot.py

Code: Select all

# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)
import time
import network
yourWifiSSID = "xxx"
yourWifiPassword = "xxx"

def connect():
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.active(True)
        sta_if.connect(yourWifiSSID, yourWifiPassword)
        while not sta_if.isconnected():
            pass

def showip():
    
    sta_if = network.WLAN(network.STA_IF)
    print('network config:', sta_if.ifconfig())

connect()
time.sleep(5)
showip()
import webrepl
webrepl.start()
print("waiting 5s...")
time.sleep(5)
print("boot completed...")
main loop in main.py

Code: Select all

	while True:
        try:
            
            message = CAN.read_message()
            if message:
              
                
                print_frame(message["id"],message["data"])
                if message["id"] not in IDS:
                    IDS.append(message["id"])
                print(message["id"], message["data"])
                print(IDS)
                    
            
           
        except OSError as E:
            print("ERROR_IN_MAIN_LOOP",E)
            machine.reset()
        	

my problem is if i dont start the main looop i can connect via webrepl, asks for password, if i enter enter wrong password im am disconnected, if i enter good password im redirected to repl but i cannot add any input its frozen.

serial repl

Code: Select all

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4
load:0x3fff0034,len:5652
load:0x40078000,len:12696
load:0x40080400,len:4292
entry 0x400806b0
connecting to network...

Brownout detector was triggered

ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4
load:0x3fff0034,len:5652
load:0x40078000,len:12696
load:0x40080400,len:4292
entry 0x400806b0
connecting to network...
network config: ('192.168.1.152', '255.255.255.0', '192.168.1.1', '192.168.1.1')
WebREPL daemon started on ws://192.168.1.152:8266
Started webrepl in normal mode
waiting 5s...
boot completed...
Entering configuration mode...
mode already set
calulating BRP and setting configuration registers 1, 2 and 3
Entering normal mode...
mode sucessfully set
MicroPython v1.17-20-g0a5107372-dirty on 2021-09-11; ESP32 GENERIC-7789 with ESP32
Type "help()" for more information.
>>> 
WebREPL connection from: ('192.168.1.249', 63110)
dupterm: EOF received, deactivating        ------------------>enter wrong password

WebREPL connection from: ('192.168.1.249', 51843) --------------------------->enter correct password

webrepl interface downloaded from github

Code: Select all

Welcome to MicroPython!                                                                                                                               
Password:                                                                                                                                             
Access denied                                                                                                                                         
Disconnected                                                                                                                                          
Welcome to MicroPython!                                                                                                                               
Password:                                                                                                                                             
WebREPL connected                                                                                                                                     
>>>    ------------------->cannot enter any input                                                                                                                                  
           
If i start loop in main.py i cannot connect to webrepl at all.

Any fix for my problem. Thanks!

marcidy
Posts: 133
Joined: Sat Dec 12, 2020 11:07 pm

Re: webrepl problem

Post by marcidy » Fri Sep 17, 2021 3:54 am

You can't both execute your loop in the foreground AND use the repl in the foreground. At a minimum you need to use concurrency of some kind, ie another thread.

For example, this doesn't work over USB, and doesn't work in normal python either.

Code: Select all

>>> def main():
>>>     while True:
>>>         print("haha, im blocking you")
>>> 
>>> main()
won't let you use the repl in python.

You should be able to use ctrl-C to interrupt the processing after connecting to the webrepl ... eventually. You are at the whim of the scheduler to eventually handle the input over the socket. using time.sleep(.01) in your loop will give the scheduler a nice point to handle some input.

Post Reply