akrv
akrv

Reputation: 55

Precompile main.py with the micropython binary image for esp8266

There is boot.py available by default in the micropython image.

I have tested a code, in the python module main.py. I would like to do the following

  1. I would like to compile a image, so it makes it easier to flash it to more than 10 devices and I do not have to start webrepl.

  2. is there a way to stop boot messages that says micropython version number etc.?

I tried the following: apparently they are already activated: https://forum.micropython.org/viewtopic.php?t=2334

I successfully compiled an image using the following: https://cdn-learn.adafruit.com/downloads/pdf/building-and-running-micropython-on-the-esp8266.pdf

Question:

how to create an image with main.py, where should this file go in this folder /home/vagrant/micropython/esp8266 ?

Upvotes: 0

Views: 1919

Answers (2)

Sirius
Sirius

Reputation: 58

You need to change micropython\esp8266\modules\inisetup.py. In this file, a block of code writes boot.py file at micropython start-up. Like below

    with open("boot.py", "w") as f:
        f.write("""\
# This file is executed on every boot (including wake-boot from deepsleep)    
#import esp
#esp.osdebug(None)
import gc
#import webrepl
#webrepl.start()
gc.collect()
import mymain
""")

Notice last line import mymain. Copy your mymain.py file to the micropython\esp8266\modules directory.

mymain.py file should not have if __name__ == '__main__' block, so that it is executed at import. All other files that mymain is importing should also be in the modules directory. After building the code, all required files will get included with the binary.

Upvotes: 1

akrv
akrv

Reputation: 55

1) boot.py is generated by the following script:

/home/vagrant/micropython/esp8266/script/inisetup.py

the function: setup() writes boot.py to the filesystem at every start up. this would be the place to add main.py also writing it in the file. or to add it in scripts and start it with boot.py

2) stop boot messages: "performing initial checks" is on inisetup.py. some are on port_diag.py in the scripts folder.

Upvotes: 0

Related Questions