Skip to main content
This guide takes one Nerves device from nothing to a working NervesHub setup. At the end you have a device that:
  • connects to NervesHub and shows as online,
  • trusts your signing key and installs updates sent over the air,
  • has a remote IEx console,
  • reports health, logs and errors, and
  • optionally takes delta updates.

Before you start

You need:
  • Hardware to run it on. A Raspberry Pi 4 is a good option, and any of the Nerves supported targets works well.
  • A Nerves project, my_app, that builds and boots on your target. If you do not have one, create it with the Nerves Getting started guide first. The examples use rpi4. On other hardware, put your target’s name wherever rpi4 appears. nerves_hub_link 2.13.0 and later need Elixir 1.15 or later.
  • An account on a NervesHub instance, in an organization. The examples use acme.
  • The nh CLI, signed in. See CLI installation for other install methods. For a self-hosted instance, point nh at it before you sign in, as described in CLI configuration.
The commands assume you run them from the my_app project directory with MIX_TARGET=rpi4 exported and MIX_ENV left at its default, so every build lands at _build/rpi4_dev/nerves/images/my_app.fw. The guide builds five firmware versions:

The parts

  1. Connect the device
  2. Take a signed update
  3. Report health, logs and errors
  4. Send smaller updates with deltas (optional)
  5. Where you are now: the complete configuration and what to do next

Part 1: Connect the device

Create the product

In the web UI, open the organization’s Products page. If the organization has no products yet, the page shows a Create your first product form: enter the name my_app and click Create product. Every device extension starts on. Otherwise click New product, enter the name my_app, leave the device extensions checked, and click Create Product. The name must match the firmware’s product name and cannot be changed later. See Products. Then save your defaults so you can leave out --org and --product:

Add the dependency

Add nerves_hub_link inside the deps function in mix.exs, then fetch it:
It starts with your firmware. You do not add it to a supervision tree. See Add NervesHubLink to a project.

Choose how the device authenticates

Pick one tab. A shared secret is the quickest. A local certificate is more work, but each device gets its own key, and it is what the complete device guide builds on. Either way, you create the one config :nerves_hub_link block in config/target.exs that the rest of this guide adds to. host is the host name devices connect to, which is usually not the web UI’s host. See Connecting devices.
The instance must have shared secret authentication turned on. See Feature prerequisites.
1

Create the secret

Open Product settings for my_app. In the Shared secrets card, click Create secret. Copy the key, which starts with nhp_. The secret is not displayed. Click the copy button next to the key, labelled Copy secret, to copy it. See Shared secret.
2

Configure the firmware

The values are read when the firmware is built, which keeps them out of version control. Export both variables in every shell you build from.
3

Build, burn and boot

Insert the card and power on the device. It connects with its serial number as its identifier, and NervesHub creates the device in my_app.

Check it works

Open Devices in my_app. The device is listed and shows as Online. From the CLI:
If it is not there, check that the device has a network connection and can reach host. With a shared secret, check that the key is active and the device clock is right. With a certificate, check that the device exists and that the files are at the two paths above. The troubleshooting lists are on Add NervesHubLink to a project and each authentication page. Go deeper: Add NervesHubLink to a project, Connecting devices, Products, Devices, Shared secret, Device certificates, Quickstart.

Part 2: Take a signed update

Create the signing key

Every firmware file is signed with a private key you hold. Firmware signing explains the whole scheme.
nh key create registers the public key with the acme organization and saves both halves under ~/.nh/keys/acme/. It offers an optional passphrase for the private key. Copy the value in the KEY column for my_app_key.
Back up my_app_key.priv. If you lose it, you cannot sign updates for devices that trust only this key.

Add the key and the console to the firmware

Add two keys to the config :nerves_hub_link block in config/target.exs:
Configure the key rather than letting the device request it from NervesHub, because requested keys come from the same server that supplies the firmware. Since nerves_hub_link 2.13.0, a device that holds no public key refuses updates. remote_iex: true lets you open an IEx session on the device from NervesHub. It is off by default. See Remote console.
fwup_public_keys is a list, and a device accepts firmware signed by any key in it. If you plan to sign in CI, CI needs a second key, my_app_ci_key, because a key made with nh key create is stored encrypted and CI needs an unencrypted one. Create that key now, as the first part of Basic fleet operations shows, and put its public half in the list beside my_app_key. Devices then trust CI builds from 1.0.0 on, and you avoid a bridging release later. See Use more than one key.

Burn 1.0.0

Set the version in mix.exs to 1.0.0. Then build and write the SD card:
Boot the device from the card.
Local certificate only. Burning the card invalidates the application data partition, and the device formats it on first boot. The cert.pem and key.pem you copied in part 1 are gone, and the device cannot connect. Copy the same two files to /data/nerves-hub again with the sftp commands from part 1, then restart the device. Do not generate a new certificate: the files are still under ~/.nh/certificates/acme/. Updates sent over the air leave /data alone, so this is the last time you copy them.
Wait until the device shows as Online under Devices, and note its identifier:

Upload 1.1.0

Set the version in mix.exs to 1.1.0. Build, then sign and upload:
nh shows the firmware’s metadata, signs a copy and uploads it. Add --password <passphrase> if you set one. Copy the UUID it prints. Firmware covers the other ways to supply the key.

Create the bench group

A deployment group connects firmware to the devices that should run it. Create one group, bench, that you use for the rest of this guide. It has no tag or version conditions, so it matches your device whatever its tags, and it is created turned on:
A device only joins a group when it connects. Yours connected before the group existed, so make it reconnect:
The device is offered the update, downloads it, verifies the signature against fwup_public_keys, installs it and reboots. With no client module, it applies every update it is offered. How firmware updates work describes each step, and Applying updates shows how to control them.

Check it works

1

The version changed

Wait for the device to reboot and come back online, then run:
It reports firmware version 1.1.0. The device page in the web UI shows the same.
2

The console opens

Open the device in the web UI and select the Console tab. An IEx prompt appears.
Go deeper: Firmware signing, Firmware, Deployment groups, Remote console, How firmware updates work, Applying updates.

Part 3: Report health, logs and errors

Extensions are what a device sends to NervesHub besides taking firmware. This part sets up three of them: Health for metrics and alarms, Logging for the device’s Logger output, and Error reports for crashes. An extension runs only when the firmware includes it, the product has it on, and the device has it on.
Logging and Error reports need ClickHouse on the NervesHub instance. Health reports without it, but metric history charts and health profiles need it. See Feature prerequisites.

Add the extensions to the firmware

Health is in the default extension list. Logging and Error reports are not, so you name them. Add two keys to the config :nerves_hub_link block in config/target.exs:
extension_modules replaces the default list. The list above keeps the three defaults (Health, Geo, Network identity) and adds the two new ones. It leaves out NervesHubLink.Extensions.LocalShell, the optional system shell. It is mostly for devices that are not Nerves devices.
level: :info sends :info and above, which is also the default. Change it to :warning if the device is on a metered connection. See Choose what is sent. Set the version in mix.exs to 1.2.0, build, and release it to bench. --deploy creates a release on the group as soon as the upload succeeds:

Turn the extensions on for the product

1

Check the product switches

Open Product settings for my_app and find the Device extensions card on the General tab. Make sure Health, Logging and Error reports are switched on.A product created in the web UI, as in part 1, starts with every extension on. A product created with nh or the API starts with every extension off, and the device sends nothing until you switch them on. See Device extensions.
2

Leave the device switches on

On the device’s Settings tab, the Extensions card has a switch for each extension. They are on by default, so there is nothing to change.
3

Reconnect the device

NervesHub decides which extensions a device may use when the device connects. If you switched an extension on while the device was connected, reconnect it:
A device that updated to 1.2.0 after you set the switches has already reconnected.

Check it works

Confirm the device runs 1.2.0. Then open the remote console and check which extensions NervesHub has attached:
Each one you turned on shows attached?: true. Send a test error from the same console:
Allow about a minute, because logs and error reports are sent in batches. Then look at the device page: Without ClickHouse, health status is also judged against fixed thresholds, not your health profile. ClickHouse for a self-hosted instance lists everything that is missing. Go deeper: Extensions overview, Health extension, Logging extension, Error reports extension, Health monitoring, Feature prerequisites, ClickHouse.

Part 4: Send smaller updates with deltas (optional)

A delta update sends a device the difference between the firmware it runs and the new firmware, instead of the whole .fw file. It is worth setting up when download size costs you something, such as on cellular or metered links. On a fast, unmetered network, skip it. The instance needs xdelta3 on the server. See Feature prerequisites.

Check your system’s fwup.conf

NervesHub can build a delta only if the upgrade tasks in your Nerves system’s fwup.conf say where the old copy of a resource is. Official Nerves systems, nerves_system_rpi4 included, already declare delta sources. With rpi4 you have nothing to change here. To check another system, copy its fwup.conf out and look. The copy option needs nerves 1.15.0 or later:
If grep prints lines, delete the copy and move on. If it prints nothing, add a delta source for rootfs.img to the upgrade.a and upgrade.b tasks of the copy, as shown in Enable delta updates. Then point the build at the copy, in config/config.exs:
If you maintain a custom system, make the change in the system instead.

Build for smaller deltas

This step is optional. A compressed root filesystem changes throughout when a few files change, so deltas of it save little. Turn squashfs compression off and fix the build date in config/config.exs:
Add mksquashfs_flags to the config :nerves, :firmware entry you already have. Keep your own rootfs_overlay value, and fwup_conf if you added it. A project generated by mix nerves.new already sets source_date_epoch. Keep its value. The trade-off is a larger root filesystem on the device and a larger full download. If the build stops with fwup: file size assertion failed on ... combined.squashfs, the uncompressed root filesystem no longer fits your system’s root filesystem partition. Remove mksquashfs_flags again and rebuild.

Check fwup on the device

fwup on the device applies the delta, and it comes from the Nerves system. A raw delta needs fwup 1.6.0 or later. A system that also declares FAT delta sources, as nerves_system_rpi4 does, needs 1.10.0. Check from the remote console:
A device with an older fwup is sent the full firmware.

Send 1.3.0 in full, then turn deltas on

A change to fwup.conf has to reach a device as a full update before the device can take patches. The build settings work the same way, because a delta is computed against the firmware the device already runs.
1

Release 1.3.0 with delta updates off

Turn delta updates off for bench, so the device downloads the full file:
Set the version to 1.3.0, build, and release it:
Wait until the device runs 1.3.0. If you changed neither fwup.conf nor the build settings, you can skip this step and the next. Your delta is then built from 1.2.0, and the last step’s release is your 1.3.0.
2

Turn delta updates on for bench

Open the bench group, go to the Settings tab, switch Delta updates on, and click Save. Or run:
3

Release 1.4.0

Make a small change, set the version to 1.4.0, and build and release it with the same two commands. NervesHub builds a delta from 1.3.0 and holds the release until it is ready.
A release waits while a delta is Building. After a delta has Failed or Timed out, the devices that need it download the full firmware. To build the delta again, click Retry next to the delta on the group’s Releases tab. See Releases wait for their deltas.

Check it works

  1. Open 1.4.0 from the product’s Firmware page. Delta updates to must not read “This firmware can’t be delta updated, so devices always download the full file.”
  2. On the bench group’s Releases tab, expand the release. Delta updates lists a delta from 1.3.0 that moves from Building to Ready. A small delta can be Ready within seconds.
  3. After the device updates, the group’s Stats tab shows Delta in the Download column for 1.3.0.
Go deeper: Delta updates for FAT and encrypted deltas, failure causes and limits; Deployment groups; Releases; Feature prerequisites.

Where you are now

Your device runs 1.4.0, or 1.2.0 if you skipped part 4.

The complete configuration

Part 4 changed config :nerves in config/config.exs, not this block.

What to do with the bench group

A device belongs to at most one deployment group, and changing a device’s tags never takes it out of the group it is in. Keep bench for now, whichever guide you read next:
  • Basic fleet operations uses bench for one last release from your machine, then deletes it when it creates the tagged qa and production groups. Your device can only join one of those once it has left bench.
  • The complete device guide releases its firmware through bench.

Where to go next

  • Complete Nerves device setup continues from here: per-device certificates from your own CA, control over when updates are applied, the remaining extensions, and connection tuning.
  • Basic fleet operations moves from one bench device to a fleet: firmware built and signed in CI, qa and production groups, and Slack notifications.