Packages
nerves_hub_link
2.7.3
2.12.0
2.11.1
2.11.0
retired
2.10.2
2.10.1
2.10.0
2.9.0
2.9.0-rc.3
2.9.0-rc.2
2.9.0-rc.1
2.8.1
2.8.0
2.7.3
2.7.2
2.7.0
retired
2.6.0
2.5.2
2.5.1
2.5.0
2.4.0
2.3.0
2.2.1
2.2.0
2.1.1
2.1.0
2.0.0
1.4.1
1.4.0
1.3.0
1.2.0
1.1.0
1.0.1
1.0.0
0.13.1
0.13.0
0.12.1
0.12.0
0.11.0
0.10.2
0.10.1
retired
0.10.0
retired
0.10.0-rc.0
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.2
0.8.1
0.8.0
0.7.6
Manage your Nerves fleet by connecting it to NervesHub
Current section
Files
Jump to
Current section
Files
lib/nerves_hub_link.ex
# SPDX-FileCopyrightText: 2019 Jon Carstens
# SPDX-FileCopyrightText: 2020 Justin Schneck
# SPDX-FileCopyrightText: 2023 Eric Oestrich
# SPDX-FileCopyrightText: 2023 Frank Hunleth
# SPDX-FileCopyrightText: 2024 Lars Wikman
# SPDX-FileCopyrightText: 2025 Josh Kalderimis
#
# SPDX-License-Identifier: Apache-2.0
#
defmodule NervesHubLink do
@moduledoc """
The Device-side client for NervesHub.
The `:nerves_hub_link` Erlang application will start by default if installed
as a dependency and use provided configuration to connect to a NervesHub
server.
This module primarily provides utility functions for checking the status of
the connection and performing some operations such as reconnecting, sending
a file to a connected console and more.
"""
alias NervesHubLink.Socket
@doc """
Checks if the device is connected to the NervesHub device channel.
"""
@spec connected?() :: boolean()
def connected?() do
Socket.check_connection(:device)
end
@doc """
Checks if the device is connected to the NervesHub console channel.
"""
@spec console_connected?() :: boolean()
def console_connected?() do
Socket.check_connection(:console)
end
@doc """
Checks if the device is connected to the NervesHub extensions channel.
"""
@spec extensions_connected?() :: boolean()
def extensions_connected?() do
Socket.check_connection(:extensions)
end
@doc """
Checks if the device has a socket connection with NervesHub
"""
@spec socket_connected?() :: boolean()
def socket_connected?() do
Socket.check_connection(:socket)
end
@doc """
Return whether there's currently an active console session
"""
@spec console_active?() :: boolean()
defdelegate console_active?, to: Socket
@doc """
Current status of the update manager
"""
@spec status :: NervesHubLink.UpdateManager.status()
defdelegate status(), to: NervesHubLink.UpdateManager
@doc """
Restart the socket and device channel
"""
@spec reconnect() :: :ok
defdelegate reconnect(), to: Socket
@doc """
Send update progress percentage for display in web
"""
@spec send_update_progress(non_neg_integer()) :: :ok
defdelegate send_update_progress(progress), to: Socket
@doc """
Send an update status to web
"""
@spec send_update_status(String.t() | atom()) :: :ok
defdelegate send_update_status(status), to: Socket
@doc """
Send a file to the connected console
"""
@spec send_file(Path.t()) :: :ok | {:error, :too_large | File.posix()}
defdelegate send_file(file_path), to: Socket
end