Is it possible to produce a build of firmware which runs user code at startup? I am nearly there: my modules are frozen as bytecode but in order for it to run on power-up I have to copy the one-line main.py to the filesystem. Freezing main.py as bytecode or as a frozen script produces an ENOENT error.
I'd like a build which simply needs to be flashed to the ESP8266. I can't help thinking I'm missing something obvious here...
Firmware build with auto-run of Python module?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Firmware build with auto-run of Python module?
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Firmware build with auto-run of Python module?
There is _boot.py in modules, which is the first script executed at startup. Maybe you can start you code from there.
The related section in main.c reads as:
Or you change the calls for boot.py or main.py in main.c into pyexec_frozen_module().
The related section in main.c reads as:
Code: Select all
pyexec_frozen_module("_boot.py");
pyexec_file("boot.py");
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
pyexec_file("main.py");
}
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Firmware build with auto-run of Python module?
Thanks for that, which pointed me to this solution. I modified the _boot.py in my project's frozen directory to read
Erase the flash before installing the firmware.
Code: Select all
# Existing code omitted up to here:
inisetup.setup()
try:
uos.stat('/main.py')
except OSError:
with open("/main.py", "w") as f:
f.write("""\
import mqtt
""")
gc.collect()
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Firmware build with auto-run of Python module?
The docs is the best place to look for answers, current or future, novice or experienced user. http://docs.micropython.org/en/latest/e ... ot-processpythoncoder wrote: I can't help thinking I'm missing something obvious here...
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/
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/
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Firmware build with auto-run of Python module?
Thanks for that.pfalcon wrote:The docs is the best place to look for answers, current or future, novice or experienced user. http://docs.micropython.org/en/latest/e ... ot-process
Given that _boot.py is frozen bytecode why does the boot process ignore a frozen main.py file? Fixing this would simplify issuing binary builds.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.