Skip to main content
NervesHubLink opens a WebSocket connection to NervesHub when the device boots and keeps it open. NervesHub uses that connection to tell the device about firmware updates, run the remote console, and receive extension data. For how the device authenticates, see the pages under device authentication, starting with Shared secret.

Set the host

Set host to the host name devices connect to. This is the device endpoint, which is usually a different host from the web UI.
host takes a host name, or a full URL when you need a port:
When host has no scheme, NervesHubLink uses wss://. If the TLS server name differs from the host you connect to, set sni:
device_api_host, device_api_port and device_api_sni are deprecated. NervesHubLink logs a warning when you set them. Use host and sni.

Trust the server certificate

NervesHubLink verifies the server certificate on every connection. It chooses the CA certificates to trust in this order:
  1. cacerts in the ssl option.
  2. The module set as ca_store. It must export ca_certs/0 and return a list of DER-encoded certificates.
  3. The CAStore package, if it is in your project.
  4. The CA certificates installed on the device.
If your instance uses a certificate from a private CA, set the certificates yourself:
Or pass DER-encoded certificates directly:
Any Erlang :ssl client option can go in ssl. TLS 1.3, session resumption, HTTP proxies and Msgpack are covered in Transport.

Devices configured with the web host

A NervesHub instance can redirect devices that connect to the web host to the device host. nerves_hub_link 2.10.0 and later follow the redirect. NervesHub also posts a product notification that names the device and the host it should use. The redirect is an instance setting. See Feature prerequisites.

Reconnection

NervesHubLink reconnects on its own when the connection drops. The delay starts at one second and doubles up to 60 seconds, with up to 50% added as jitter. To change it, or to control when the connection starts, see Connection lifecycle.

Turn the connection off

With connect: false, the application starts no connection processes.

Build the configuration at runtime

When credentials are not known at build time, implement the NervesHubLink.Configurator behaviour. build/1 receives the configuration read from the application environment and returns the configuration to use.
Setting configurator replaces the built-in choice between NervesKey, TPM and shared secret. See Connection lifecycle.