Meshcore.Commands.Binary (Meshcore v0.1.0)

Copy Markdown View Source

Binary and anonymous requests to remote nodes: status, telemetry, min/max/avg telemetry, ACL, neighbours, regions, owner info and basic info.

Every *_sync function sends the request, waits for the matching response and returns {:ok, data} or {:error, event}; they are serialised through the per-connection mesh request lock (only one request is in flight at a time, as the radio can only handle one anyway).

The *_async variants return as soon as the request is queued (:msg_sent); the response then arrives as an event you can Meshcore.subscribe/3 to or Meshcore.wait_for_event/3 for, filtered by tag: (see the expected_ack in the returned payload).

Common options for all of them: :timeout and :min_timeout in milliseconds (by default derived from the device's suggestion).

Summary

Functions

Fetches the complete neighbour table, issuing several requests when needed.

Requests the access control list. Returns a list of %{key: hex_prefix, perm: integer}.

Requests a node's basic info, i.e. its clock (async variant).

Requests a node's basic info. Returns the :binary_response payload (%{tag:, data: hex}).

Requests min/max/average telemetry between Unix times start_time and end_time. Returns a list of %{channel:, type:, min:, max:, avg:}.

Requests a node's neighbour table and returns once queued.

Requests a node's neighbour table and waits for it. Returns a map with :neighbours_count (total), :results_count (received in this answer) and :neighbours – a list of %{pubkey:, secs_ago:, snr:}. See fetch_all_neighbours/3 to page through large tables.

Requests a node's name and owner info (async variant).

Requests a node's name and owner info. Returns %{name: String.t(), owner: String.t()}.

Requests the regions configured on a node (async variant).

Requests the regions configured on a node. Returns the region string.

Requests the status of a repeater/room (battery, noise floor, airtime, packet counters…). Returns the parsed :status_response payload.

Requests the sensor telemetry of a node. Returns the decoded LPP readings, e.g. [%{channel: 1, type: "temperature", value: 21.5}].

Types

mc()

@type mc() :: GenServer.server()

result()

@type result() :: {:ok, Meshcore.Event.t()} | {:error, Meshcore.Event.t()}

Functions

fetch_all_neighbours(mc, contact, opts \\ [])

@spec fetch_all_neighbours(mc(), Meshcore.Util.destination(), keyword()) ::
  {:ok, map()} | {:error, Meshcore.Event.t()}

Fetches the complete neighbour table, issuing several requests when needed.

If a follow-up page fails twice in a row the partial result is returned – compare :results_count with :neighbours_count.

req_acl(mc, contact, opts \\ [])

@spec req_acl(mc(), Meshcore.Util.destination(), keyword()) ::
  {:ok, list()} | {:error, Meshcore.Event.t()}

Deprecated alias of req_acl_sync/3.

req_acl_sync(mc, contact, opts \\ [])

@spec req_acl_sync(mc(), Meshcore.Util.destination(), keyword()) ::
  {:ok, list()} | {:error, Meshcore.Event.t()}

Requests the access control list. Returns a list of %{key: hex_prefix, perm: integer}.

req_basic_async(mc, contact, opts \\ [])

@spec req_basic_async(mc(), Meshcore.Util.destination(), keyword()) :: result()

Requests a node's basic info, i.e. its clock (async variant).

req_basic_sync(mc, contact, opts \\ [])

@spec req_basic_sync(mc(), Meshcore.Util.destination(), keyword()) ::
  {:ok, map()} | {:error, Meshcore.Event.t()}

Requests a node's basic info. Returns the :binary_response payload (%{tag:, data: hex}).

req_mma_sync(mc, contact, start_time, end_time, opts \\ [])

@spec req_mma_sync(
  mc(),
  Meshcore.Util.destination(),
  non_neg_integer(),
  non_neg_integer(),
  keyword()
) ::
  {:ok, list()} | {:error, Meshcore.Event.t()}

Requests min/max/average telemetry between Unix times start_time and end_time. Returns a list of %{channel:, type:, min:, max:, avg:}.

req_neighbours_async(mc, contact, opts \\ [])

@spec req_neighbours_async(mc(), Meshcore.Util.destination(), keyword()) :: result()

Requests a node's neighbour table and returns once queued.

Options: :count (255), :offset (0), :order_by (0), :pubkey_prefix_length (4).

req_neighbours_sync(mc, contact, opts \\ [])

@spec req_neighbours_sync(mc(), Meshcore.Util.destination(), keyword()) ::
  {:ok, map()} | {:error, Meshcore.Event.t()}

Requests a node's neighbour table and waits for it. Returns a map with :neighbours_count (total), :results_count (received in this answer) and :neighbours – a list of %{pubkey:, secs_ago:, snr:}. See fetch_all_neighbours/3 to page through large tables.

req_owner_async(mc, contact, opts \\ [])

@spec req_owner_async(mc(), Meshcore.Util.destination(), keyword()) :: result()

Requests a node's name and owner info (async variant).

req_owner_sync(mc, contact, opts \\ [])

@spec req_owner_sync(mc(), Meshcore.Util.destination(), keyword()) ::
  {:ok, map()} | {:error, Meshcore.Event.t()}

Requests a node's name and owner info. Returns %{name: String.t(), owner: String.t()}.

req_regions_async(mc, contact, opts \\ [])

@spec req_regions_async(mc(), Meshcore.Util.destination(), keyword()) :: result()

Requests the regions configured on a node (async variant).

req_regions_sync(mc, contact, opts \\ [])

@spec req_regions_sync(mc(), Meshcore.Util.destination(), keyword()) ::
  {:ok, String.t()} | {:error, Meshcore.Event.t()}

Requests the regions configured on a node. Returns the region string.

req_status(mc, contact, opts \\ [])

@spec req_status(mc(), Meshcore.Util.destination(), keyword()) ::
  {:ok, map()} | {:error, Meshcore.Event.t()}

Deprecated alias of req_status_sync/3.

req_status_sync(mc, contact, opts \\ [])

@spec req_status_sync(mc(), Meshcore.Util.destination(), keyword()) ::
  {:ok, map()} | {:error, Meshcore.Event.t()}

Requests the status of a repeater/room (battery, noise floor, airtime, packet counters…). Returns the parsed :status_response payload.

req_telemetry(mc, contact, opts \\ [])

@spec req_telemetry(mc(), Meshcore.Util.destination(), keyword()) ::
  {:ok, list()} | {:error, Meshcore.Event.t()}

Deprecated alias of req_telemetry_sync/3.

req_telemetry_sync(mc, contact, opts \\ [])

@spec req_telemetry_sync(mc(), Meshcore.Util.destination(), keyword()) ::
  {:ok, list()} | {:error, Meshcore.Event.t()}

Requests the sensor telemetry of a node. Returns the decoded LPP readings, e.g. [%{channel: 1, type: "temperature", value: 21.5}].