- authenticates with its own certificate, signed by a CA you control,
- decides when to apply an update, downloads it in verified parts, and validates the new firmware,
- reports its own location, metrics, alarms and network identities, and
- uses the connection options and extras that fit your product.
Before you start
You need the basic guide’s end state:- The
my_appproduct in theacmeorganization, and a device that connects with a shared secret or a local certificate. - The
config :nerves_hub_linkblock from the basic guide’s closing section inconfig/target.exs, withfwup_public_keys,remote_iex: trueand five extensions. - The signing key
my_app_key. - The
benchdeployment group, turned on, with your device in it. This guide releases throughbench. If you have already replaced it with the groups from Basic fleet operations, useqawherever this guide saysbench.
1.4.0, and each part here ships one version, 1.5.0 to 1.8.0. If you skipped the delta part of the basic guide your device is on a lower version, and these numbers still work.
Build and release every version the same way, from the project directory with MIX_TARGET=rpi4 exported. The examples keep using a Raspberry Pi 4; any of the Nerves supported targets works, with its name in place of rpi4:
config :nerves_hub_link block in config/target.exs. The closing section shows the whole block.
The parts
- Move to certificate authentication
- Control when and how updates are applied
- Turn on the rest of the extensions
- Tune the connection and add the extras
- Where you are now: the complete configuration and what to do next
Part 1: Move to certificate authentication
A product’s shared secret is compiled into every firmware image, and whoever holds it can connect as any device in the product. For production, give each device its own X.509 certificate. Security: PKI and the chain of trust explains the model. You sign device certificates with a certificate authority (CA) that you control and register with theacme organization. A just-in-time provisioning profile on the CA lets new devices create themselves in my_app, tagged prod, the first time they connect. Registering a CA needs the manage role or higher.
If you chose the Local certificate tab in the basic guide, your firmware already uses LocalCertKey with a self-signed certificate. Do the first three steps of the Local certificate tab below to replace that certificate with one your CA signed. You have no shared secret to retire.
Choose where the device keeps its private key.
- Local certificate
- NervesKey
The certificate and key are files on the device. See Device certificates.This writes the CA key and certificate to The
1
Create and register the CA
~/.nh/ca/acme/, named by the generation time, for example 2026-06-11-16-41-10-cert.pem. That timestamp is the CA’s name in the next step. Only the certificate is uploaded. Keep the key secret.To bring a CA you already have:--jitp-* flags give the CA its JITP profile, and need NervesHub 2.5.0 or later. nh sets the profile only when it registers the CA. To add or change it later, open the organization’s Certificates page, click the certificate authority, and click Edit. Check Enable Just In Time Provisioning, choose my_app as the JITP Product, enter prod in JITP Tags, and click Update Certificate.2
Sign a device certificate
The certificate’s common name must be the device identifier, which is the device’s serial number.The key and certificate are written to
~/.nh/certificates/acme/ as <identifier>-<timestamp>-key.pem and <identifier>-<timestamp>-cert.pem.3
Put the files on the device
The files go to
/data/nerves-hub/cert.pem and /data/nerves-hub/key.pem. How you get them there depends on where the device is:-
A device on your bench with SSH access. Use
sftp, as in part 1 of the basic guide. -
A device in the field that is connected to NervesHub. Write the files from the remote console, which needs no network path to the device:
4
Switch the firmware to LocalCertKey
In the
config :nerves_hub_link block, replace the shared_secret option with the configurator:LocalCertKey is never chosen automatically. For other file paths, see Configure NervesHubLink.Release 1.5.0
Set the version to1.5.0, then build and release it to bench.
The shared secret and certificates work side by side, so you move devices that are already in the field with this ordinary update:
- Leave the product key active.
- Make sure each device has its certificate before it updates. A device running the new firmware has no other way to connect.
- Release the firmware. Each device reconnects with its certificate after it updates. Devices still on the old firmware keep connecting with the shared secret.
Retire the shared secret
When every device has a certificate on file, open Product settings, and in the Shared secrets card click Deactivate next to the key, then Deactivate secret to confirm. New connections that use the key are refused. Connections that are already open stay open until the device reconnects. See Deactivate a key.Check it works
-
Run
nh ca show <serial>, with the serial fromnh ca list. It prints the JITP productmy_appand the tagprod. The organization’s Certificates page lists the CA with Adds new devices to my_app. -
Wait for your device to update to
1.5.0. It comes back Online. A device NervesHub has not seen before, booted with this firmware and a certificate from the CA, appears under Devices inmy_appwith the tagprod. -
Confirm the certificate is on file. It is also listed in the Certificates card on the device’s Settings tab. See Devices.
-
After you deactivate the product key, force a fresh connection. The device comes back Online.
Part 2: Control when and how updates are applied
Add the client module
NervesHubLink.Client is the behaviour through which nerves_hub_link asks your application what to do with an update. Create lib/my_app/nerves_hub_link_client.ex:
MyApp.busy?/0, MyApp.Display and MyApp.shutdown_gracefully/0 stand for your own code.
{:reschedule, 15, reason}turns the update down for now and reports the reason. NervesHub offers the update again after 15 minutes. The other return values are in Applying updates.reboot/0must end in a reboot, or the new firmware never runs.nerves_hub_linkreports whether the running firmware is validated, but it does not validate it. Your application has to, and a device that reports unvalidated firmware is not offered updates by its deployment group. Theconnected/0callback is one reasonable place to validate, and Applying updates covers the alternatives. If your application already validates somewhere else, leaveconnected/0out. A project generated bymix nerves.newcan already do so through thenerves_runtimestartup guard: checkconfig/target.exsforconfig :nerves_runtime, startup_guard_enabled: true.
Select the client and the download strategy
Add two keys to theconfig :nerves_hub_link block:
PartsUpdater downloads the firmware in parts and verifies each one. It keeps the parts in /data/nerves_hub_link/firmware, so the device needs room for the firmware file there. It needs NervesHub 2.5.0 or later. The other strategies and the retry settings are in Download strategies.
Set the version to 1.6.0, then build and release it to bench.
Optional: let the device ask for its updates
With the client module, NervesHub still picks the moment to offer an update and your code answers. For a device whose owner or state decides the moment, use device-managed updates: the deployment group stops pushing, and the device fetches the group’s firmware when it chooses.1
Ship the three calls
Call this from your own code, for example when the owner presses “Update now” or a machine cycle ends:
update_now/0 returns :ok once NervesHub has sent the update, and the error when it is refused. The reasons are listed in Ask for an update from firmware.An update started this way still goes through MyApp.NervesHubLinkClient, so update_available/1 can still turn it down.2
Roll that firmware out
Include the module in
1.6.0. Release it through bench while the device is still in automatic mode, and wait until the device runs it.3
Grant the permission and set the mode
An operator has to allow a device to choose its mode. On the device’s Settings tab, in the Firmware updates card, switch on Let the device choose its update mode, or run:Then call
MyApp.Updates.take_control() on the device. To skip the grant, set the mode yourself with nh device update <identifier> --update-mode device_managed, or in the device page header, select the update mode and choose Device managed.NervesHub does not pace device-requested updates. The group’s rollout controls do not apply to them, so if many devices could ask at the same moment, spread the requests in your firmware.
Check it works
-
The device takes
1.6.0at once, because the firmware it was running had no client module. The client andPartsUpdateract from the next update on. -
In the remote console on the updated device:
The last line applies only if you set up device-managed updates. Otherwise it returns
:automatic. -
Part 3 releases
1.7.0, the first update the client decides on. WhileMyApp.busy?/0returnstrue, the device stays on1.6.0. When it returnsfalseand the update is offered again, the device’s Details tab shows download and install progress, and the device reboots into1.7.0. If you set up device-managed updates, the group offers nothing: callMyApp.Updates.update_now()on the device instead.
Part 3: Turn on the rest of the extensions
Each section is independent, so skip what your device does not need. The config for all of them is in one snippet, in Configure the extensions. Every extension also has to be on for the product, in Product settings on the General tab, in the Device extensions card. A product created through the API ornh starts with them all off. See the extensions overview.
Report your own location
Skip this unless the device has a better location source than its public IP address, such as GPS or a modem. If it does, write a resolver module. Use your own resolver has a complete one, which the config below namesMyApp.GPSGeoResolver.
Return errors from it as {:error, code, description}. That three-element shape is the one the extension matches on.
Add your own metrics and metadata
A metric set is a module with one callback that returns a map of names to numbers. See Health.:defaults, which keeps the default metric sets. Metadata is a map of strings beside the metrics, set under metadata in the same config.
Raise alarms
Alarms have no extension of their own innerves_hub_link. The Health report carries every alarm currently raised, so NervesHub learns of a change at the next report. An alarm raised and cleared between two reports is never seen.
Add alarmist, which the nerves_hub_link guide recommends, and the report reads alarms from it:
:alarm_handler:
Add context to error reports
Pointcontext at a function that returns a map, and every error report carries it:
Report network identities
If the device is on iroh, NetBird, Tailscale or WireGuard, the Network identity extension shows its key on the device page. The extension has been in your firmware since the basic guide, but it reports nothing without a provider. Write one provider module per network. Enable it has a complete NetBird provider, which the config below namesMyApp.NetBirdIdentity.
Never put a secret in a provider’s details. Anyone who can view the device can read it.
Configure the extensions
In theconfig :nerves_hub_link block, replace extension_modules and logging from the basic guide with these keys. Drop the lines for any section you skipped.
extension_modules replaces the default list, so it names all five from the basic guide. Set the version to 1.7.0, then build and release it to bench.
Set a health profile
Custom metrics are charted, but they only affect a device’s health status once they are in a health profile. Profiles need ClickHouse on the instance. See Feature prerequisites. Open Product settings and select the Device health tab. Pick Default under Profiles, use Add a metric… to addbattery_percent, and set Warning at and Unhealthy at. The metric is listed once a device has reported it. Click the ≥ button to flip it to ≤, because a low battery is the problem. Click the star in the Featured column to give the metric a tile on the device page, then click Save profile. Edit a profile covers each control, and How a threshold engages explains how to choose the period.
Check it works
On the device, after it has updated to1.7.0 and reconnected:
attached?: true, the health report holds battery_percent, and your provider returns an identity.
On the device page in NervesHub:
- Details tab: the Location card names your source (the card needs a map token on the instance), the Health card has a Battery percent tile and an Alarms row, and the Network identities card lists the NetBird key. The Metadata list has a Placement row. Without a map token it also has a Location row, which shows the coordinates and the source.
Optional: add a system shell
The Local shell extension openssh on the device’s operating system. It is optional, and mostly recommended for devices that are not Nerves devices, such as ones running the Linux agent.
To add it, add the expty library:
extension_modules:
NervesHub also has standalone Metrics and Alarms extensions.
nerves_hub_link 2.14.0 implements neither, so turning them on for the product does nothing for a Nerves device. See Metrics and Alarms extensions.Part 4: Tune the connection and add the extras
Nothing in this part is required. Each section says who it is for, so skip what does not apply. The first four change firmware, which you release as1.8.0. Support scripts and connecting code need no firmware change.
TLS 1.3 session resumption
For devices on slow or metered links, such as LTE-M. A reconnect resumes the TLS session instead of repeating the full handshake, so it sends and verifies no certificates. The instance must accept TLS 1.3 on its device endpoint, which is off by default. See Feature prerequisites. You need NervesHub 2.5.0 or later, and OTP 25.1 or later on the device. Addssl to the config :nerves_hub_link block:
:"tlsv1.2" in the list so the device still connects to a server without TLS 1.3. If you already set ssl: for certificate file paths, add these two keys to that list. Tickets, firmware downloads and the server side are covered in Connection transport.
Msgpack
For the same metered or low bandwidth devices. Msgpack encodes the device’s messages in fewer bytes than JSON. It needsnerves_hub_link 2.13.0 or later and NervesHub 2.5.0 or later.
Add the dependency to mix.exs, then serializer to the config :nerves_hub_link block:
HTTP proxy
For devices that can only reach NervesHub through an HTTP proxy. You configure the proxy twice, once for the WebSocket and once for the firmware downloader. The snippet is in HTTP proxy.Archives
For data that changes on a different schedule from firmware, such as calibration data or a model. An archive is a signed fwup file that travels with a release.nerves_hub_link downloads and verifies it, then hands your code the path.
The default client ignores archives. Add both callbacks to MyApp.NervesHubLinkClient:
MyApp.Archives stands for your own code. It must remember the UUID, because NervesHub offers the archive again on every connect.
Archives are verified with the keys in archive_public_keys. When that is not set, the device uses fwup_public_keys, which your firmware already has, so there is nothing to add. Build the archive as Set it up shows, sign and upload it with the key you use for firmware, and attach it to the group once the device runs firmware with the callbacks:
nh firmware upload --deploy has no archive, so attach the archive again after your next firmware release if devices still need it.
Support scripts and connecting code
For anyone who supports devices in the field. A support script is Elixir saved on the product that you run on one online device, with the output returned to you. It does not needremote_iex. Managing scripts with nh needs NervesHub 2.5.0 or later.
bench group, open the group, select the Settings tab, type the code into the Connecting code card and select Save.
Devices that sleep
For battery devices that wake, connect, work and sleep again. A device that says it is going to sleep shows as asleep with a wake time instead of offline, and the sleep does not count as a disconnect.This feature is on the main branch of
nerves_hub_link and NervesHub but is in no tagged release as of nerves_hub_link 2.14.0 and NervesHub 2.5.4. You need a build from main of both to use it.NervesHubLink.reconnect() when it wakes. See Devices that sleep and, for reconnecting in general, Connection lifecycle.
Check it works
1
Release 1.8.0 to a device you can reach
Set the version to
1.8.0, then build and release it to bench only, so the first device to take it is one you can reach physically. A transport setting the server does not accept leaves a device unable to connect, and so unable to take a fix.2
Confirm it connects
using JSON instead. That line means the setting was not applied.3
Run the support script
Run
nh device run-script <identifier> "Memory" for that device. Output coming back shows the device is connected and can run scripts.4
Trigger the connecting code
Run
nh device reconnect <identifier>. If the code fails, NervesHub raises a product notification.Where you are now
Your device runs1.8.0.
The complete configuration
This block holds everything from the basic guide’s block, withshared_secret replaced by certificate authentication in part 1, and everything this guide added. Lines for sections you skipped are not in yours.
mix.exs: nerves_key (NervesKey tab only), alarmist and msgpax, plus expty if you added the optional system shell.
Where to go next
Keep thebench group. Basic fleet operations uses it for one last release, then deletes it.
- Basic fleet operations: firmware built and signed in CI,
qaandproductiongroups, and Slack notifications. - Complete fleet operations: a pipeline that rolls out through canaries with approval, webhooks into your own backend, and rollout guardrails.
- How firmware updates work for every update tool, format and setting.
- Extensions overview for what each extension reports and needs.
- Fleet overview for managing devices once they are deployed.
- Integrations overview for device clients other than
nerves_hub_link.

