Atomvm_mqtt_client no init: Failed to load port "atomvm_mqtt_client"

This is dockerfile


# Use the Ubuntu base image
FROM ubuntu:22.04 as build

# Actualizar la lista de paquetes
RUN apt-get update && \
    apt-get install -y -q \
	    git cmake gperf \
            doxygen erlang-base erlang-dialyzer \
            libglib2.0-0 libpixman-1-0 \
            gcc g++ zlib1g-dev libsdl2-2.0-0 libslirp0 libmbedtls-dev

# Create a directory to mount the volume
RUN mkdir /myvolume

# Set the working directory
WORKDIR /myvolume

# Start a bash shell by default
CMD ["bash"]

after running these commands >

git clone -b v5.1.2 --recursive https://github.com/espressif/esp-idf.git esp-idf-v5.1.2
cd esp-idf-v5.1.2/
. ./install.sh
. ./export.sh
cd ~
git clone https://github.com/atomvm/AtomVM.git
cd /AtomVM/src/platforms/esp32/components
git clone https://github.com/atomvm/atomvm_mqtt_client.git
cd ..
idf.py set-target esp32
idf.py reconfigure
idf.py build
./build/mkimage.sh

Then I erase the memory and then program the esp32

esptool.py --chip auto --port /dev/tty.usbserial-0001 --baud 921600 erase_flash

esptool.py --chip auto --port /dev/tty.usbserial-0001 --baud 115200 --before default_reset --after hard_reset write_flash -u --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 Users/joserodriguez/atomvm/AtomVM/src/platforms/esp32/build/atomvm-esp32.img

That is just the steps to flash the VM to run your application, which I confirmed previously look good.:+1: But the next step is to flash your application. This should be done from your application directory with the command:

rebar3 atomvm esp32_flash

You might consult the AtomVM Tooling section of the docs.

There is another script created in the esp32/build directory that will ensure the VM is flashed to the correct bootloader offset for the target device the build was configured for called flashimage.sh that can be used after ./build/mkimage.sh, this is just a convenience so that you donā€™t need to type the full esptool command.

You might also read the atomvm_rebar3_plugin documentation if you have not yet.

I already know where the problem is, esp32boot.avm is not compiling for some reason, or I donā€™t know if I have to generate it separately. But when it creates the image it does not succeed and that is why it does not generate it correctly.

./build/mkimage.sh
Writing output to /Users/joserodriguez/atomvm/atomvm-v0.6.0/src/platforms/esp32/build/atomvm-esp32.img
=============================================
Wrote bootloader (26720 bytes) at offset 0x1000 (4096)
Padding 1952 bytes
Wrote partition-table (3072 bytes) at offset 0x8000 (32768)
Padding 29696 bytes
Wrote AtomVM Virtual Machine (1486224 bytes) at offset 0x10000 (65536)
Padding 348784 bytes
Stacktrace: [{erl_eval,do_apply,7,[{file,"erl_eval.erl"},{line,742}]},
             {lists,foldl_1,3,[{file,"lists.erl"},{line,1355}]},
             {erl_eval,local_func,8,[{file,"erl_eval.erl"},{line,644}]},
             {erl_eval,exprs,6,[{file,"erl_eval.erl"},{line,136}]},
             {erl_eval,try_clauses,10,[{file,"erl_eval.erl"},{line,987}]},
             {erl_eval,local_func,8,[{file,"erl_eval.erl"},{line,644}]},
             {erl_eval,expr_list,7,[{file,"erl_eval.erl"},{line,961}]},
             {erl_eval,expr,6,[{file,"erl_eval.erl"},{line,454}]}]
%%
%% Failed to read file [[["/Users/joserodriguez/atomvm/atomvm-v0.6.0/src/platforms/esp32/build/../../../../build/libs/esp32boot/esp32boot.avm"]]]  Reason: not_found.  Note that a full build is required before running this command.
%%
Syntax:
    escript mkimage.erl <options>

The following options are supported:
    * --root_dir <path>    Path to the root directory of the AtomVM git checkout
    * --build_dir <path>   Path to the AtomVM build directory (defaults to root_dir/build, if unspecifeid)
    * --out <path>         Output path for AtomVM image file
    * --config <path>      Path to mkimage configuration file
    * --help               Print this help
=============================================

AtomVM esp32 version  image written to:
/Users/joserodriguez/atomvm/atomvm-v0.6.0/src/platforms/esp32/build/atomvm-esp32.img

Ok, now I see where you might be running into troubleā€¦ if you check the Build Instructions chapter I posted links to previously, you will see you need to do a generic_unix build firstā€¦ in the top level AtomVM/build directory, this will build the BEAM libraries and some extra tools, along with the generic_unix executable. Then you can cd into src/platforms/esp32 and after idf.py build, ./build/mkimage.sh should succeed.

1 Like

It works now, thank you. I was just going straight to ESP32 to execute the steps. Now it makes sense. :rofl:

1 Like

Excellent!!! I think we should add a check and a warning in the esp32 cmake files, this could have saved you a lost week, sorry about that!

I will look into fixing that, or possibly reworking the cmake configuration to build the libraries in the esp32/build directory if they donā€™t already exist in the top level AtomVM/build. Thank you for reaching out, and bringing this stumbling block to our attention.

I really should have thought to ask you if you did the generic_unix build first, this is a common mistake, especially if people just read the README.ESP32.Md and donā€™t read the full documentation.

Donā€™t hesitate to open issues on GitHub (and or bring it up here) if you encounter any more problems. Please do keep us informed of your progress, and anything missing or that needs clarification in our documentation.