micropython+ESP8266直接做些小玩具是很简单的。但是如果每次都要上传mian.py就很不理想了
而不是编译出一个通用的玩意,而是一个直接启动功能的固件,需要自行编译micropython,然后改改mian.c
main.py is a proper place to put your start code in. That resides in the flash file system. If you prefer to have it in the scripts folder, which moves into the frozen files space, then you have to change esp8266/main.c and rebuild.
But bothing prevents you from putting your startup code in _boot.py. If you look into main.c, you'll see:
CODE: SELECT ALL
#if MICROPY_MODULE_FROZEN
pyexec_frozen_module("_boot.py");
pyexec_file("boot.py");
pyexec_file("main.py");
#endif
which means, that _boot.py, boot.py and main.py are simply executed one after another.
B.T.W.: I'm not sure whether boot.py and main.py should only be execute whan MICROPY_MODULE_FROZEN is set. Maybe that's just a leftover from an earlier development phase.
If you are compiling your own firmware this was the solution offered to me and I think the most useable at the moment.
https://forum.micropython.org/viewtopic.php?f=15&t=2114&e=1&view=unread#unread
Basically you just put the code you want executed into the scripts/ folder and edit main.c to add:
pyexec_frozen_module("myscript.py");
或者改 _boot.py
Thanks for that, which pointed me to this solution. I modified the _boot.py in my project's frozen directory to read
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()
Erase the flash before installing the firmware.
再或者给bin加一段。。。
You can also drop a dos-fs image (must have a sector size=4096) at offset 561152. This image can contain boot.py and whatever other Python or data files you need.
That's what I'm doing.
But this is really not well documented, and I suspect that this offset may be subject to future change.
本文介绍如何通过修改MicroPython源代码,尤其是ESP8266平台的main.c文件,来定制启动行为,实现将特定的Python脚本作为固件启动时直接运行的功能,避免反复上传main.py。
7885

被折叠的 条评论
为什么被折叠?



