Skip to main content
nerves_hub_link is the client library that connects a Nerves device to NervesHub. The device appears in your product the first time it connects.

Requirements

  • A Nerves project. nerves_hub_link 2.13.0 and later need Elixir 1.15 or later.
  • A product in NervesHub. See Products.
  • Each device needs a unique serial number. With a shared secret, NervesHub identifies the device by the serial number its firmware reports. With a certificate, NervesHub identifies the device by the certificate’s common name, so issue each certificate with the device’s serial number as its common name.
1

Add the dependency

Add nerves_hub_link inside the deps function in mix.exs:
Then fetch it:
nerves_hub_link is an OTP application and starts with your firmware. You do not need to add it to a supervision tree. To start it yourself, see Connection lifecycle.
2

Choose how the device authenticates

NervesHubLink picks a configurator in this order:
  1. The module you set as configurator in the :nerves_hub_link config.
  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.
Shared secrets are the quickest way to connect a first device. They only work when the NervesHub instance has them turned on. See Feature prerequisites.
3

Configure the connection

Add the configuration for your method to config/target.exs. Replace the host with your NervesHub device host.
Create a shared secret in Product settings and copy its key and secret. See Shared secret.
System.fetch_env!/1 runs when you build the firmware. Set both variables in the shell or CI job that runs mix firmware.
To stop NervesHubLink from connecting while you run tests, set connect: false:
4

Set up firmware signing

From nerves_hub_link 2.13.0, a device refuses firmware it cannot signature-check. A device with no fwup_public_keys configured asks NervesHub for your organization’s signing keys when it connects. If it has none configured and receives none, it stops taking updates.Register a signing key before you upload firmware. See Firmware signing.
5

Build, burn, and check the connection

Boot the device and open Devices in your product. A connected device shows as Online.If the device does not appear, check:
  • The device has a network connection and can reach the host. NervesHubLink checks that the network is available before its first connection attempt.
  • With a shared secret, the key and secret match an active secret in Product settings, and the device clock is correct. NervesHub accepts a signature for 90 seconds.
  • With a certificate, the signing CA is registered and the device exists or the CA has a just-in-time provisioning profile. See Device certificates.