Add NervesHub to your project
Last updated
Was this helpful?
Last updated
Was this helpful?
The first step is to add to your target dependencies in your project's mix.exs
. Since NervesHub uses SSL certificates, the time must be set on the device or certificate validity checks will fail. If you're not already setting the time, add to your dependencies. For example:
Next, update your config.exs
so that the library can help provision devices. Do this by adding provisioning: :nerves_hub_link
to the :nerves, :firmware
option like this:
Adding this library will start a long-lived websocket connection with NervesHub for communicating device updates.
See the section for connection setup if you are using NervesKey
If you aren't using NervesKey, you can also provide your own options to use for the NervesHub socket connection via the :socket
and :ssl
keys, which are forwarded on to slipstream
when creating the socket connection.
Any can go in the :ssl
key.
In some cases you may opt to use your own device signer CA when creating device certificates. If you do, there a few things needed for a successful connection:
Your signer CA must be uploaded to NervesHub. You can do this a couple ways
From the web UI at https://www.nerves-hub.org/settings/{YOUR_ORG}/certificates/new
Via CLI with mix nerves_hub.ca_certificate register /path/to/signer-ca.pem
Some cases require that connection configuration happens at runtime like selectively choosing which cert/key to use based on device, or reading a file stored on device which isn't available during compilation.
For example:
Then you specify which configurator NervesHubLink
should use in config.exs
:
This let's devices hook into the decision making process and monitor the update's progress.
To have NervesHubLink invoke it, add the following to your config.exs
:
Note: The Application config is evaluated at compile time. Extra caution is needed when using file paths in the config as they might be referencing host paths instead of device paths. Another option would be to configure at runtime (see )
The signer CA must be included in the connection request alongside the NervesHub intermediate CAs. If you're using , then this is typically handled for you. If managing certificates more manually, it is usually best to read at runtime and appened to the CA list. Here's a basically example of what that step might look like:
Whatever the reason, NervesHubLink
also supports runtime configuration via the behavior. This is called during application startup to build the configuration that is to be used for the connection. When implementing the behavior, you'll receive the initial default config read in from the application environment and you can modify it however you need.
By default NervesHubLink applies updates as soon as it knows about them from the NervesHubLink server and doesn't give warning before rebooting. Optionally, you can override this behavior if desired by implementing the behaviour.