Requirements
nerves_hub_link2.13.0 or later. It reports device API version 2.4.0, which is what NervesHub checks.- NervesHub 2.5.0 or later.
- NervesHub 2.5.1 or later for the product settings that grant the permission to new or all devices.
- No instance prerequisite.
Update modes
Every device has an update mode. The mode is stored in NervesHub, not on the device, so it survives a reboot and an operator can see and change it.
In every mode:
- A device-managed device stays in its group and is only left out of pushes.
- A manual push always lands. Sending firmware by hand to an
automaticdevice also sets it tooff, so the group does not overwrite what you sent. Other modes are left as they are. - A device may only fetch firmware its deployment group would send it. A device in a workflow step that has not started is refused whatever its mode.
Enable it
1
Ship firmware that asks for its own updates
Update Add the module to your application’s supervision tree. No
nerves_hub_link to 2.13.0 or later and add code that checks for and starts updates. This example checks every 30 minutes and updates only when your application says it is safe:config :nerves_hub_link key is needed.2
Roll that firmware out
Release the firmware through the device’s deployment group while the device is still in
automatic mode. Wait until the devices you plan to switch are running it.3
Set the mode
- You set it
- The device sets it
Open the device. In the page header, select the update mode and choose Device managed.From the CLI:Through the API, set
update_mode to device_managed in a device update.Setting these device fields through the API or nh needs NervesHub 2.5.3 or later.An operator can always set any mode. The permission below is not needed.Check that it works
- The device page header shows Device managed as the update mode.
- On the device,
NervesHubLink.update_mode()returns:device_managed. - Create a release in the device’s group. The device is not sent it.
NervesHubLink.check_for_update()returns{:ok, %{available?: true, firmware_meta: meta}}, andNervesHubLink.start_update()returns:okand the update starts. - Each mode change is recorded in the audit log. When the device asked for the change, the device is recorded as the actor.
updates = "device-managed" or updates = "automatic" in the device list’s advanced query. See Finding devices.
Ask for an update from firmware
Checking and updating are separate calls.check_for_update/1 is allowed in every mode, including :off. It is read-only and returns firmware metadata without a download URL. A device with updates off can still tell its user that an update exists.
start_update/1 fetches the firmware URL and applies the update. It returns :ok once NervesHub has sent the update. From there the update runs exactly like one the deployment group pushed and reports through your NervesHubLink.Client. See Applying updates.
Firmware URLs are signed and time limited, so the URL is fetched when the device is about to use it, not when it checks.
Pacing
NervesHub does not pace device requests. A device that asks for its update gets it whenever its deployment group has firmware for it, and the group’s rollout controls do not apply to the request. NervesHub refuses a request only when the device is in no deployment group, when there is no update for it, or when it already has an update in progress. Theupdate_rejected event carries the reason.
nerves_hub_link still returns {:error, {:busy, minutes}} when a server answers with the reason busy. Handle it as “not now”, and ask again after minutes.
Let the device choose its mode
A device may move itself between:automatic and :device_managed, and only when an operator has allowed it.
NervesHubLink.set_update_mode/2 returns:
The change is not queued while the device is offline. To keep a user-facing switch and NervesHub in step, set the mode again each time the device connects:
NervesHubLink.update_mode/1 returns nil until NervesHub reports the mode. A NervesHub too old to know about update modes never reports it, and the device keeps taking updates as before. Treat nil as “not device managed”, not as an error.
Grant the permission to many devices
The permission is themanaged_updates_allowed field on a device. A new device starts with its product’s default, which is off.
- New devices: in Product settings, in the Device-managed updates card, switch on Let new devices choose their update mode. From the CLI, run
nh product update <name> --default-managed-updates-allowed. This applies to devices created from then on and does not change existing devices. - Existing devices: in the same card, the Existing devices row has Allow on all and Revoke on all.
- One device through the API: set
managed_updates_allowedwhen you create or update the device.
device_managed mode. Set its mode back to automatic yourself if you want it to receive pushes again.
Each change to the permission is recorded in the audit log per device.
Firmware too old to manage itself
A device indevice_managed mode that connects reporting a device API version below 2.4.0 is returned to automatic. NervesHub records the change in the audit log with the device as the actor.
Otherwise the device would be stranded: the deployment group does not push to it, and its firmware cannot ask. This matters most after a firmware auto-revert, where a failed update drops a device back onto an image that predates the feature.
Nothing reverses this automatically. Once the device runs firmware that supports device-managed updates, set its mode again.
Limits
- A device cannot set
off, and cannot take itself out ofoff. Only an operator can. updates_enabledis deprecated. The API still returns it, derived asupdate_mode != off.- In the device list’s advanced query,
updates = "enabled"andupdates = "disabled"keep their earlier meanings.

