Skip to main content
NervesHubLink establishes a long-lived Phoenix WebSocket channel on boot and keeps it open for the lifetime of the device process. Through this connection, NervesHub can push firmware update notifications, stream logs, open a remote IEx console, and receive health metrics — all without polling. This page explains how to point that connection at NervesCloud or your own self-hosted NervesHub instance.
NervesHubLink enforces SSL peer verification on every connection. The server certificate must be valid and trusted by the device’s CA bundle. Connections to hosts with self-signed or untrusted certificates will be rejected unless you configure a custom CA certificate.
NervesCloud is the managed NervesHub service at manage.nervescloud.com. It is the fastest way to connect devices because no infrastructure setup is required. Set your host and credentials in config/target.exs and NervesHubLink handles everything else:
The devices.nervescloud.com endpoint is pre-trusted by the default Nerves CA bundle, so no additional certificate configuration is necessary.

Self-Hosted NervesHub

If you operate your own NervesHub instance, override the device_api_host, device_api_sni, and device_api_port keys to point at your server:
Note that device_api_sni is a charlist (single-quoted), not a binary string. This value is passed directly to the underlying :ssl application for Server Name Indication during the TLS handshake. If your server uses a private CA, provide the CA certificate so the device can verify the server’s identity:

Connection Behavior

NervesHubLink maintains a single persistent WebSocket connection to the NervesHub server. You do not need to manage reconnects in application code — the library handles them automatically:
  • Automatic reconnection — if the connection drops (network outage, server restart), NervesHubLink retries with exponential backoff.
  • No keep-alive tuning required — Phoenix Channels send heartbeat frames; NervesHubLink responds automatically.

Disabling the Connection in Development

When running mix test or developing on a host machine, you do not want NervesHubLink attempting to reach the NervesHub server. Disable the connection entirely with:
With this runtime configuration option set, the WebSocket process will not be started at all when the application boots.

Runtime Configuration with a Configurator

For advanced use cases where credentials are not known at compile time — for example, when device certificates are provisioned during first boot or retrieved from a hardware security module — implement the NervesHubLink.Configurator behaviour:
Register your module in config/target.exs:
NervesHubLink calls build_config/1 at startup before opening the socket, so any credentials returned are used for the initial handshake and all subsequent reconnections.