| title | Quickstart: your first OTA update |
|---|---|
| sidebarTitle | Quickstart |
| description | Connect a new Nerves project to NervesHub with a shared secret and send it a signed firmware update over the air. |
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](/auth/device-certificates).- A working Nerves installation, including
fwup. The CLI usesfwupto 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.
```bash
brew install nerves-hub/tap/nh-cli
```
If you self-host, point the CLI at your instance first:
```bash
nh config set uri https://your.nerveshub.host
```
Sign in. This opens your browser and shows a code to enter there:
```bash
nh user login
```
Save your organization as a default so you can leave out `--org`:
```bash
nh config set org my-org
```
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](/auth/device-certificates) instead.
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:
```bash
nh key list
```
Copy the value in the `KEY` column for `my_app_key`.
<Warning>
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.
</Warning>
```elixir
defp deps do
[
# ... existing deps ...
{:nerves_hub_link, "~> 2.14", targets: @all_targets}
]
end
```
Configure it in `config/target.exs`:
```elixir
config :nerves_hub_link,
host: "devices.nervescloud.com",
fwup_public_keys: ["<public key from nh key list>"],
shared_secret: [
product_key: "<product_key>",
product_secret: "<product_secret>"
]
```
`fwup_public_keys` lists the signing keys the device trusts. The device refuses firmware that is not signed by one of them.
<Tip>
Keep real secrets out of version control. Read them from the environment for anything beyond a quick test.
</Tip>
`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.
You can also list devices from the CLI. Run it inside the project directory, or pass `--product my_app`:
```bash
nh device list
```
Note the device's identifier. You need it later.
```bash
mix firmware
nh firmware upload --key my_app_key
```
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.
```bash
nh deployment create my-group --firmware <uuid> --state 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](/management/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.
<Note>
The web UI calls these **deployment groups**. The `nh` CLI and the HTTP API use the name `deployment`. They are the same thing.
</Note>
```bash
nh device reconnect <identifier>
```
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.
Once the group exists, one command signs, uploads and points the group at new firmware:
mix firmware
nh firmware upload --key my_app_key --deploy my-groupFrom 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.
Move from a shared secret to X.509 certificates for production. Decide in your firmware when an update is applied, and report progress. Target devices by tag and version, and control how a rollout proceeds. Open an IEx session on a connected device.For a fuller walk-through, continue with Basic Nerves device setup and Basic fleet operations.