Skip to main content
NervesHubLink is the client for devices running Nerves. It is an Elixir library that you add to your firmware. It is the reference implementation of the device protocol, and the one the server is developed against. It keeps the WebSocket connection to NervesHub, reports the firmware the device is running, downloads updates and applies them with fwup, serves the remote console and support scripts, and runs the extensions. This page describes NervesHubLink 2.14.0.

Add it to your project

mix.exs
A minimal configuration with a shared secret:
config/target.exs
Replace host with your own instance’s device endpoint if you do not use NervesCloud. Shared secrets must be enabled on the instance. See feature prerequisites. Add to project and Connecting walk through the full setup, and the device authentication pages cover certificates, NervesKey and TPM.

How it picks an authentication method

NervesHubLink builds its connection settings with a configurator module. It picks one in this order:
  1. The module in config :nerves_hub_link, configurator: MyConfigurator, if set.
  2. NervesHubLink.Configurator.NervesKey, if the nerves_key library is in your project.
  3. NervesHubLink.Configurator.TPM, if the tpm library is in your project.
  4. NervesHubLink.Configurator.SharedSecret.
See Connection lifecycle for writing your own configurator.

Configuration keys

Set these under config :nerves_hub_link. Defaults are from NervesHubLink.Configurator.Config.

Connection

The socket reconnects with a delay that starts at 1 second and doubles up to 60 seconds, with up to 50% jitter. Override it with reconnect_after_msec in socket. device_api_host, device_api_port and device_api_sni are deprecated. Use host and sni. See Transport and Connection lifecycle.

Authentication

Updates

From 2.13.0, firmware and archives that cannot be signature verified are refused. A device with no keys configured that receives none from NervesHub stops taking updates.

Console and extensions

extension_modules replaces the default list. Name every extension you want, not only the one you are adding.

Client identification

From 2.14.0, NervesHubLink sends NHL/<version> as the User-Agent of its WebSocket connection, as it already did for firmware downloads. NervesHub 2.5.2 and later record it for each connection. A User-Agent you set in the socket headers is kept. See Choosing a device client.

Library documentation

The library’s own documentation is on HexDocs and matches the version you install.

nerves_hub_link on HexDocs

The guides and the module reference.
The Devices That Sleep guide describes a feature that is on the main branch but in no tagged release as of nerves_hub_link 2.14.0 and NervesHub 2.5.4. See Sleeping devices.

Not running Nerves?

See Choosing a device client for Linux without Nerves, AtomVM, and ESP-IDF.