main branch differs.
Requirements
Build the VM
The AtomVM build needs up to three changes:
Without the two partitions a device connects and reports its firmware but cannot be updated. Without libsodium a device configured with
firmware_keys reports verification_unavailable and does not install the update.
The agent ships the files for the last two changes in priv/atomvm. After rebar3 compile in your project they are in _build/default/lib/nerves_hub_link_atomvm_esp32/priv/atomvm:
<AtomVM> with your AtomVM checkout and <transport> with your checkout of atomvm_websocket_client.
Use
idf.py set-target, not reconfigure. CMake caches its component list, and a plain idf.py build after adding a component reports success without compiling it.Flash the VM and the application
main.avm partition. Read the offset from the device’s own partition table:
boot.avm. The only symptom is Failed app start: invalid_avm.
The partition table
main.avm and alt.avm must be the same size, because either one has to hold the archive. boot.avm and factory are larger than in stock AtomVM, to fit the Elixir boot archive and libsodium. priv/atomvm/partitions.csv explains each size.
Install
- Erlang
- Elixir
rebar.config
Connect
Set the device clock before you start the agent, for example with SNTP. A shared-secret signature is valid for 90 seconds, and an ESP32 boots with its clock at the epoch.start/1 returns {error, {clock_not_set, Now}} if the clock is not set.
- Erlang
- Elixir
host or url, the agent connects to NervesCloud. Set one of them for another instance. Setting both is an error.
Options
These are the options you are most likely to set. The repository’s README lists all of them.
One of
shared_secret and client_cert is required.
Handle events
The agent sends{nerves_hub, Event} to the process that started it, or to handler.
New events are added between versions. If your handler is a
gen_server, give handle_info/2 a catch-all clause.Updates
Withupdates => auto, the agent downloads the packbeam NervesHub offers into whichever of main.avm and alt.avm the device is not running from. It then arms that partition and sends {update_ready, Slot}. Your application decides when to reboot.
Firmware on trial
After an update, the new firmware is on trial until it joins NervesHub. It has three boots to join, and five minutes on each. If it uses up either, the device points back at the previous firmware and restarts into it. That firmware then reports to NervesHub that an update was reverted. Start the agent early in your application. A firmware that crashes before it callsnerves_hub_link:start/1 is not counted. firmware_trial => off turns the trial off.
Deciding for yourself
Withupdates => manual, the offer arrives as {message, <<"update">>, Payload}. Answer it with one of:
Verifying signatures on the device
Setfirmware_keys to your organization’s fwup public keys. A device with keys refuses any update the keys do not cover, including an unsigned one, before it changes the boot partition. A device with no keys installs what it is sent.
Verification needs AtomVM built with AVM_USE_LIBSODIUM=ON. See AtomVM packbeam archives for how to sign an archive.
Console, scripts and extensions
- Console. AtomVM has no shell, so
console => trueserves a fixed set of commands:help,info,firmware,memory,partitions,net,geo,signature,uptimeandreboot. It does not evaluate Erlang. - Support scripts. A script is a list of console commands, one per line. Blank lines and lines that start with
#are skipped. The first line that is not a command fails the script, so a script written in Elixir for Nerves devices reports a failure.rebootis refused in a script. - Extensions. Version 0.2.0 implements
health,geoandlogging. The product and the device must also have the extension enabled in NervesHub.
What is on main but not in 0.2.0
The main branch has unreleased additions, listed in the repository’s changelog. They include an alarms extension, custom console commands (console_commands), and keep_open_above and before_update for devices with too little memory to hold two TLS sessions during a download.
What the device reports
The device does not send a UUID. NervesHub derives it from the SHA-256, by the same rule it uses at upload, so the device matches the firmware you uploaded only if it runs the same bytes.

