Skip to content

Commit

Permalink
add NervesHubLink.reconnect/0
Browse files Browse the repository at this point in the history
  • Loading branch information
jjcarstens committed Aug 19, 2021
1 parent 63fad58 commit bd530d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions lib/nerves_hub_link.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
defmodule NervesHubLink do
alias NervesHubLink.Supervisor, as: NHLSupervisor
alias NervesHubLink.{ConsoleChannel, DeviceChannel, Socket}

@doc """
Checks if the device is connected to the NervesHub channel.
"""
Expand All @@ -18,4 +21,22 @@ defmodule NervesHubLink do
"""
@spec status :: NervesHubLinkCommon.UpdateManager.State.status()
defdelegate status(), to: NervesHubLinkCommon.UpdateManager

@doc """
Restart the socket and device channel
"""
@spec reconnect() :: :ok
def reconnect() do
# Stop the socket last
_ = Supervisor.terminate_child(NHLSupervisor, ConsoleChannel)
_ = Supervisor.terminate_child(NHLSupervisor, DeviceChannel)
_ = Supervisor.terminate_child(NHLSupervisor, Socket)

# Start the socket first
_ = Supervisor.restart_child(NHLSupervisor, Socket)
_ = Supervisor.restart_child(NHLSupervisor, ConsoleChannel)
_ = Supervisor.restart_child(NHLSupervisor, DeviceChannel)

:ok
end
end
2 changes: 1 addition & 1 deletion lib/nerves_hub_link/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule NervesHubLink.Application do
[
{UpdateManager, fwup_config},
Connection,
{PhoenixClient.Socket, {config.socket, [name: Socket]}},
{PhoenixClient.Socket, {config.socket, [id: Socket, name: Socket]}},
{DeviceChannel, [socket: Socket, params: config.params]}
]
|> add_console_child(config)
Expand Down

0 comments on commit bd530d4

Please sign in to comment.