In this section, we discuss the usage of so called Frozen code. This is only useful when you build the firmware from source.
Frozen
What we call Frozen code, relates to a principle in MicroPython where you can include specific code blocks or python module inside the firmware, such that you do not have to manually upload them. This can be very useful if you have a specific section of code you want to include on all your devices, without manually uploading it every time and risk losing it when formatting the file system.
It is only possible to include python files in the frozen section. Other filetypes (like .json or .cert) will not be added in the final binaries
.json
.cert
pycom-micropython-sigfox/esp32/frozen
frozen
sqnsupgrade.py
OTA.py
_main.py
_boot.py
frozen/Base/
main.py
boot.py
If you plan to make changes in the _boot.py, keep the code already in the file, as that enables the output to REPL.
# _main.py print("Hello from _main.py")
When building firmware with VARIANT=PYBYTES, you need to use the _main.py and _boot.py files in the frozen/Pybytes folder. The files in frozen/Base will NOT be used. Moreover, if you then enable the pybytes_on_boot(True), the _pybytes_main.py will be used instead of the _main.py, as that contains the Ctrl activation code.
VARIANT=PYBYTES
frozen/Pybytes
frozen/Base
pybytes_on_boot(True)
_pybytes_main.py
Custom
Block.py
# block.py def Block(): print("My Frozen codeblock")
>>> from block import Block >>> Block() My Frozen codeblock
This works similar to import machine and the other built-in modules. This concludes the section about Frozen code. You should now be able to include Frozen python code inside the firmware.
import machine