Enable webrepl daemon with script

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
hell
Posts: 1
Joined: Mon Dec 30, 2019 11:53 am

Enable webrepl daemon with script

Post by hell » Mon Dec 30, 2019 12:53 pm

Currently is possible enable webrepl daemon with CLI (import webrepl_setup -> (E)nable and set pwd), but i want to do this with script.

The basic activities, what i want to do:
1. erase_flash
2. write new fw
3. connect to wifi # done in boot.py
4. if web_repl disabled, enable web_repl and set password
5. webrepl.start()

I'm stuck with the step 4.
Yes, i can do this once and manually, but developing my skills and knowledge would be nice, if i understand how to do it.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Enable webrepl daemon with script

Post by kevinkk525 » Mon Dec 30, 2019 2:23 pm

I do this in my project:

Code: Select all

if config.WEBREPL_ACTIVE:
    try:
        import webrepl_cfg
    except ImportError:
        try:
            with open("webrepl_cfg.py", "w") as f:
                f.write("PASS = %r\n" % config.WEBREPL_PASSWORD)
        except Exception as e:
            _log.critical("Can't start webrepl: {!s}".format(e), local_only=True)
    try:
        import webrepl

        webrepl.start()
    except Exception as e:
        _log.critical("Can't start webrepl: {!s}".format(e))
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Christian Walther
Posts: 169
Joined: Fri Aug 19, 2016 11:55 am

Re: Enable webrepl daemon with script

Post by Christian Walther » Mon Dec 30, 2019 6:08 pm

The easiest way to achieve the same state as if you had configured it manually is to copy the boot.py and webrepl_cfg.py files that are generated by the manual configuration to the board.

Check the source to see what import webrepl_setup does.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Enable webrepl daemon with script

Post by kevinkk525 » Mon Dec 30, 2019 8:36 pm

That is actually not the easiest way because you have to keep different file versions or modify those files.

It's easier to use my approach that will create the webrepl_cfg.py according to how webrepl.py does it (at least as long as it doesn't exist) and starts the webrepl without modifying the boot.py
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode


kr-g
Posts: 48
Joined: Sun Dec 01, 2019 7:52 pm
Contact:

Re: Enable webrepl daemon with script

Post by kr-g » Thu Apr 02, 2020 11:18 am

to whom it may concern (little bit of topic here since the inital post was just regarding web repl)

there is a new version v0.0.4 of mpyconfigbase
- supports now setting time from NTP automatically during startup when wlan is configured and connected

https://github.com/kr-g/mpyconfigbase

Post Reply