2.7 KiB
title
| title |
|---|
| Frozen |
In this section, we discuss the usage of so called Frozen code. This is only useful when you build the firmware from source.
What we call Frozen code, relates to a principle in MicroPython where you can include specific codeblocks 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
.jsonor.cert) will not be added in the final binaries
How To use the Frozen section
-
Download the (latest) source code from our Github Repository and extract the archive, or use the GitHub desktop tool. If you have never build firmware from the sourcecode before, you can find the setup guide on GitHub as well.
-
Inside the folder
pycom-micropython-sigfox/esp32/frozenyou will find thefrozensection. We already have frozen some of the python modules into the firmware, such assqnsupgrade.pyandOTA.py. -
You can find the
_main.pyand_boot.pyfiles in thefrozen/Base/folder. These are similar tomain.pyandboot.pyfiles you can build into the source code, with the exception that_boot.pywill also run in safeboot mode. Moreover can only change the behaviour by rebuilding and reflashing the firmware.If you plan to make changes in the
_boot.py, keep the code already in the file, as that enables the output to REPL. -
For example, add to the
_main.py:# _main.py print("Hello from _main.py")When building firmware with
VARIANT=PYBYTES, you need to use the_main.pyand_boot.pyfiles in thefrozen/Pybytesfolder. The files infrozen/Basewill NOT be used. Moreover, if you then enable thepybytes_on_boot(True), the_pybytes_main.pywill be used instead of the_main.py, as that contains the pybytes activation code. -
Now rebuild and reflash the firmware. After reboot, the line will be printed in the REPL.
-
You can also add files to the
Customfolder, in this example, we make aBlock.pywith the following code:# block.py def Block(): print("My Frozen codeblock") -
After rebuilding and reflashing, you are able to:
>>> 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.