nerves_hub_link v0.8.2 NervesHubLink.ConsoleChannel

Wraps IEx.Server setting this process as the group_leader. This allows tunneling the io_request's over the channel socket.

The remote console ability is disabled by default and requires the remote_iex key to be enabled in the config:

config :nerves_hub_link, remote_iex: true

Once connected, IO requests on the device will be pushed up the socket for the following events:

  • get_line - IO is requesting the next line from user input. Typically just iex () >
  • put_chars - Display the specified characters from the IEx Server for user review

    • This requires an immediate reply of :ok and then IEx will send a :get_line request to await the user input. NervesHubLinkWeb handles immediately replies :ok to these events (see below)
  • init_attempt - Pushed asynchronously after attempting to init an IEx Server. Payload has a success key with a boolean value to specify whether the server process was started successfully or not

The following events are supported from the socket:

  • iex_terminate - Kill any running IEx server in the channel
  • init - The console channel starts without a linked IEx Server by default. This must be called before sending I/O back and forth. Only one IEx Server is initialized for this channel. If IEx Server has already been initialized and is in a good state, then calling init will continue to use the linked session and have no effect.
  • io_reply - Send the reply characters to the IO. Requires specific keys in payload

    • kind - event that you're replying to. Either get_line or put_chars
    • data - characters to be put into the IO. put_chars requires this to be ok or error
  • phx_close or phx_error - This will cause the channel to attempt rejoining every 5 seconds. You can change the rejoin timing in the config
config :nerves_hub_link, rejoin_after: 3_000

For more info, see The Erlang I/O Protocol

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Callback implementation for GenServer.init/1.

Link to this section Functions

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Callback implementation for GenServer.init/1.

Link to this function

start_link(opts)