Skip to main content
This quickstart takes a new Nerves project, connects a device to NervesHub with a shared secret, and updates it over the air. At the end you have a device in the web UI, a signing key, an uploaded firmware and a deployment group that delivers it.
Shared secrets suit hobby and R&D projects. For production, use certificates. See Device certificates.

Prerequisites

  • A working Nerves installation, including fwup. The CLI uses fwup to sign firmware.
  • Hardware to run it on, and an SD card. A Raspberry Pi 4 is a good option, and any of the Nerves supported targets works well.
  • An account on NervesCloud or on a self-hosted NervesHub.
  • An instance with shared secret authentication turned on. See Feature prerequisites.
The examples use NervesCloud: manage.nervescloud.com for you and devices.nervescloud.com for devices. Use your own hosts if you self-host.
1

Install the CLI and sign in

Install nh with Homebrew, or see CLI installation for other methods:
If you self-host, point the CLI at your instance first:
Sign in. This opens your browser and shows a code to enter there:
Save your organization as a default so you can leave out --org:
2

Create the project

3

Create a product and a shared secret

In the web UI:
  1. Open your organization. If it has no products yet, enter my_app in the Create your first product form and click Create product. Otherwise click New product, name it my_app, and click Create Product. The CLI refuses to upload firmware built for a different product name.
  2. Open Product settings.
  3. In the Shared secrets card, click Create secret.
  4. Copy the key. The secret is not displayed: click the copy button next to the key, labelled Copy secret, to copy it.
If the card says shared secret authentication has not been turned on for the platform, the instance does not allow it. Use device certificates instead.
4

Create a firmware signing key

This generates a key pair, saves it under ~/.nh/keys/<org>/, and registers the public key with your organization. The private key stays on your machine. You are asked for an optional passphrase to encrypt it.List your keys to get the public key:
Copy the value in the KEY column for my_app_key.
Back up the private key. Devices only accept firmware signed by a key they trust, so losing it means you cannot sign updates for devices that trust only that key.
5

Add and configure NervesHubLink

Add the library inside the deps function in mix.exs:
Configure it in config/target.exs:
fwup_public_keys lists the signing keys the device trusts. The device refuses firmware that is not signed by one of them.
Keep real secrets out of version control. Read them from the environment for anything beyond a quick test.
6

Build and burn

mix firmware builds a .fw file and mix burn writes it to the SD card. Insert the card and power on the device. It boots, joins the network and connects to NervesHub.
7

Confirm the device connected

In the web UI, open the product and go to Devices. A device that connects with a product’s shared secret is created on its first connection, so it appears in the list without being added first.You can also list devices from the CLI. Run it inside the project directory, or pass --product my_app:
Note the device’s identifier. You need it later.
8

Build, sign and upload an update

Make a visible change and raise the version in mix.exs, for example to "0.2.0". Then build, sign and upload:
Inside a Nerves project, nh finds the built image under _build/ and asks you to confirm it. It signs the file with my_app_key, uploads it, and prints the firmware’s version and UUID. Copy the UUID.Add --password <passphrase> if you set a passphrase on the key.
9

Create a deployment group and turn it on

A deployment group says which devices get which firmware. Create one for the firmware you uploaded and turn it on:
This group has no tag or version conditions, so it matches every device in the product that runs the same platform and architecture as the firmware.A new group has delta updates on. This first update still downloads the full firmware. The firmware you burned was never uploaded to NervesHub, so there is nothing to build a delta from.
The web UI calls these deployment groups. The nh CLI and the HTTP API use the name deployment. They are the same thing.
10

Watch the device update

NervesHub places a device in a matching deployment group when the device connects. Your device connected before the group existed, so ask it to reconnect:
The device then:
  1. Receives the update over its WebSocket connection.
  2. Downloads the firmware.
  3. Verifies the signature against fwup_public_keys and applies the update with fwup.
  4. Reboots into the new firmware and reconnects.
Check the device in the web UI, or run nh device show <identifier>, to see the new firmware version.

Ship the next update

Once the group exists, one command signs, uploads and points the group at new firmware:
From this release on, NervesHub holds both firmware files, so it builds a delta from the firmware your device runs. The release waits while the delta builds. If no delta can be built, the device downloads the full firmware. See Delta updates. See CI/CD to do this from a pipeline.

Next steps

Device certificates

Move from a shared secret to X.509 certificates for production.

Applying updates

Decide in your firmware when an update is applied, and report progress.

Deployment groups

Target devices by tag and version, and control how a rollout proceeds.

Remote console

Open an IEx session on a connected device.
For a fuller walk-through, continue with Basic Nerves device setup and Basic fleet operations.