MeshtasticClient (meshtastic_client v0.1.0)

A client for interacting with Meshtastic devices using Protocol Buffers.

This client provides functionality to:

  • Connect to Meshtastic devices via TCP, Serial, or BLE
  • Encode and decode Meshtastic protobuf messages
  • Send and receive mesh packets
  • Manage device configuration

Summary

Functions

Waits for and collects incoming messages for a specified timeout.

Connects to a Meshtastic device.

Disconnects from a Meshtastic device.

Requests the device configuration.

Gets information about the local node.

Sends a position update.

Sends a text message to a specific node or broadcast.

Subscribes to incoming messages from the device.

Types

connection()

@type connection() :: MeshtasticClient.Connection.t()

error()

@type error() :: {:error, term()}

Functions

collect_messages(opts \\ [])

@spec collect_messages(keyword()) :: [term()]

Waits for and collects incoming messages for a specified timeout.

Options

  • :timeout - Timeout in milliseconds (default: 5000)
  • :count - Number of messages to collect (default: 10)

Example

MeshtasticClient.subscribe(conn)
messages = MeshtasticClient.collect_messages(timeout: 3000)

connect(opts \\ [])

@spec connect(keyword()) :: {:ok, connection()} | error()

Connects to a Meshtastic device.

Options

  • :type - Connection type: :tcp, :serial, or :ble (default: :tcp)
  • :host - Host address for TCP connections (default: "meshtastic.local")
  • :port - Port for TCP connections (default: 4403)
  • :device - Device path for serial connections (e.g., "/dev/ttyUSB0")
  • :baud_rate - Baud rate for serial connections (default: 115200)

Examples

# Connect via TCP
{:ok, conn} = MeshtasticClient.connect(type: :tcp, host: "192.168.1.100", port: 4403)

# Connect via Serial
{:ok, conn} = MeshtasticClient.connect(type: :serial, device: "/dev/ttyUSB0")

disconnect(conn)

@spec disconnect(connection()) :: :ok | error()

Disconnects from a Meshtastic device.

get_config(conn)

@spec get_config(connection()) :: {:ok, map()} | error()

Requests the device configuration.

get_node_info(conn)

@spec get_node_info(connection()) :: {:ok, map()} | error()

Gets information about the local node.

This function requests configuration and then listens for responses. You should subscribe first to receive the responses asynchronously.

Example

MeshtasticClient.subscribe(conn)

# Then receive messages
receive do
  {:meshtastic_message, msg} -> IO.inspect(msg)
after
  5000 -> :timeout
end

send_position(conn, opts \\ [])

@spec send_position(
  connection(),
  keyword()
) :: :ok | error()

Sends a position update.

Options

  • :latitude - Latitude in degrees
  • :longitude - Longitude in degrees
  • :altitude - Altitude in meters
  • :to - Destination node ID (default: broadcast)
  • :channel - Channel index (default: 0)

send_text(conn, text, opts \\ [])

@spec send_text(connection(), String.t(), keyword()) :: :ok | error()

Sends a text message to a specific node or broadcast.

Options

  • :to - Destination node ID (default: 0xFFFFFFFF for broadcast)
  • :channel - Channel index (default: 0)
  • :want_ack - Request acknowledgment (default: false)

Examples

MeshtasticClient.send_text(conn, "Hello, mesh!", to: 0x12345678)
MeshtasticClient.send_text(conn, "Broadcast message")

subscribe(conn)

@spec subscribe(connection()) :: Enumerable.t()

Subscribes to incoming messages from the device.

Returns a stream of messages that can be consumed.