Main.py vs Boot.py

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
ajocius
Posts: 83
Joined: Mon Feb 19, 2018 6:31 am

Main.py vs Boot.py

Post by ajocius » Sat Jan 19, 2019 5:32 pm

Is there any general logic on what to keep in each file? Both files are executed during startup. I have seen examples where wifi connection is coded in boot.py, but also seen it in main.py, tried both options and it worked fine. Same with MQTT parameters (user name, password, ip address, etc), some place them in boot.py , some in main.py. Is there any benefit of putting into one file vs the other?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Main.py vs Boot.py

Post by dhylands » Sat Jan 19, 2019 7:28 pm

The way that I normally think about this is that boot.py is used to configure your bootup and main.py is my main program.

Some things, like configuring the USB mode, or setting the name of the main script (which defaults to main.py, but can be changed) can only be done in boot.py.

Code which is introduced in boot.py is availaed at the REPL without having to import anything, whereas code from main.py isn't. I think of it as boot.py is sourced where main.py is imported.

Post Reply