Micropython: webrepl crash - ESP8266

Created on 16 Feb 2018  路  3Comments  路  Source: micropython/micropython

Hello,

Board: ESP8266 NodeMcu v3

wanna run the webrepl, but it crash if I open the URL with Bowser.

WebREPL daemon started on ws://0.0.0.0:8266
Started webrepl in normal mode
connecting to network...
Network configuration: ('192.168.1.246', '255.255.255.0', '192.168.1.1', '1.2.3.4')
WebREPL daemon started on ws://192.168.1.246:8266
Started webrepl in normal mode

MicroPython v1.9.3-8-g63826ac5c on 2017-11-01; ESP module with ESP8266
Type "help()" for more information.
>>> 
WebREPL connection from: ('192.168.1.114', 58848)
Traceback (most recent call last):
  File "webrepl.py", line 42, in accept_conn
  File "websocket_helper.py", line 34, in server_handshake
OSError: Not a websocket request

Here is the code: **

import machine
import socket
import webrepl

def do_connect():
    import network

    SSID = 'MyWIFI'
    PASSWORD = 'MyWiFIPassword'

    sta_if = network.WLAN(network.STA_IF)
    ap_if = network.WLAN(network.AP_IF)
    if ap_if.active():
        ap_if.active(False)
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.active(True)
        sta_if.connect(SSID, PASSWORD)
        while not sta_if.isconnected():
            pass
    print('Network configuration:', sta_if.ifconfig())

do_connect()

webrepl.start()
sudo ampy --port /dev/ttyUSB0 ls
boot.py
webrepl_cfg.py
main.py  ** there is the CODE

sudo ampy --port /dev/ttyUSB0 get webrepl_cfg.py

show the password I set with: import webrepl_setup

What did I wrong ?

Thanks

port-esp8266

Most helpful comment

Strikes me that you might be typing...

http://192.168.1.246:8266

...into your browser

Rather you should load the WebRepl webpage from http://micropython.org/webrepl/ then either...

  • switch your desktop's wifi to the ESP8266 Access point (password is micropythoN) and click on the Connect button to trigger the connection from within the page (the default of ws://192.168.4.1:8266/ should work)

...or...

  • paste in a URL matching the ESP8266's DHCP-assigned IP into the field next to the Connect button before triggering connection (for a module which has negotiated an IP address on your home network)

I think this second case is the configuration you have - hence the console message suggesting you connect to ws://192.168.1.246:8266/ instead of the default.

The WebREPL page is typically served from a different machine altogether, not on port 8266 of the device. Port 8266 is reserved for a websocket connection triggered by Javascript from within the WebREPL page.

For those who can't get their ESP8266 to negotiating an address on their LAN network and are therefore irritated by switching between AP and internet to be able to load/reload the WebREPL page they can have their own copy of the WebREPL locally on their desktop ( see https://github.com/micropython/webrepl ).

If for some reason you need the WebREPL to be actually hosted by the ESP8266 because there is no LAN this is feasible, but non-standard ( see https://github.com/micropython/micropython/issues/2299#issuecomment-264750573 ).

Out of interest, does the fact there are two reports of WebREPL starting within your console log mean that it is actually started twice (perhaps in boot.py as well as later in your main.py script). Not sure what this would mean for stability.

All 3 comments

Which browser/OS are you using? You can try a different one to see if that is the issue.

Manjaro Linux, Firefox 58.0.2

Strikes me that you might be typing...

http://192.168.1.246:8266

...into your browser

Rather you should load the WebRepl webpage from http://micropython.org/webrepl/ then either...

  • switch your desktop's wifi to the ESP8266 Access point (password is micropythoN) and click on the Connect button to trigger the connection from within the page (the default of ws://192.168.4.1:8266/ should work)

...or...

  • paste in a URL matching the ESP8266's DHCP-assigned IP into the field next to the Connect button before triggering connection (for a module which has negotiated an IP address on your home network)

I think this second case is the configuration you have - hence the console message suggesting you connect to ws://192.168.1.246:8266/ instead of the default.

The WebREPL page is typically served from a different machine altogether, not on port 8266 of the device. Port 8266 is reserved for a websocket connection triggered by Javascript from within the WebREPL page.

For those who can't get their ESP8266 to negotiating an address on their LAN network and are therefore irritated by switching between AP and internet to be able to load/reload the WebREPL page they can have their own copy of the WebREPL locally on their desktop ( see https://github.com/micropython/webrepl ).

If for some reason you need the WebREPL to be actually hosted by the ESP8266 because there is no LAN this is feasible, but non-standard ( see https://github.com/micropython/micropython/issues/2299#issuecomment-264750573 ).

Out of interest, does the fact there are two reports of WebREPL starting within your console log mean that it is actually started twice (perhaps in boot.py as well as later in your main.py script). Not sure what this would mean for stability.

Was this page helpful?
0 / 5 - 0 ratings