After the firmware build of the MicroPython firmware for esp8266 in the previous article
MicroPython – MicroPython compiling for ESP8266
we now show how build a module inside the firmware; this option optimizes the module execution and minimizes the size of the same on the device; the module is frozen into the firmware.
With the firmware compiled with the defaults, the following modules are available, listed in the REPL console with the command
1 |
help('modules') |
Now let’s try to compile the firmware with the mqtt modules already inside. For this purpose, the module sources are copied to the umqtt folder under modules
1 2 |
micropython/ports/esp8266/modules/umqtt/simple.py micropython/ports/esp8266/modules/umqtt/robust.py |
We proceed to recompile the firmware. From micropython/ports/esp8266 we run the following commands
1 2 |
make clean make |
We can see from the compilation log, that these modules are placed in the frozen state
After uploading this firmware we obtain the following list of modules inside the firmware
It is also possible to create the firmware with the modules not compiled and optimized, by copying the sources in the scripts folder under esp8266; in the specific case the sources must be placed as shown below
1 2 |
micropython/ports/esp8266/scripts/umqtt/simple.py micropython/ports/esp8266/scripts/umqtt/robust.py |
The modules are always visible in the firmware, but not optimized, so if you need some module it is convenient to copy it on the device during the coding and in the last phase of the project compile the firmware with the frozen modules.