rockwood / exbee

Communicate with XBee wireless radios in Elixir
https://hex.pm/packages/exbee
Other
6 stars 4 forks source link

Exbee

Communicate with XBee wireless radios in Elixir.

Installation

Add exbee to your list of dependencies in mix.exs:

def deps do
  [{:exbee, "~> 0.1.0"}]
end

Usage

Exbee assumes that XBee modules are set to API mode. In API mode, XBee modules send and receive commands via encoded frames.

Discover attached serial ports

iex> Exbee.serial_ports()
%{
  "COM1" => %{description: "USB Serial", manufacturer: "FTDI", product_id: 1, vendor_id: 2},
  "COM2" => %{...},
  "COM3" => %{...}
}

Start an Exbee process

Frames are sent via the Exbee.send_frame/2 function. Frames received on the serial port are reported as messages to the current process. The messages have the form: {:exbee, frame}

This example starts an Exbee process and sends an Exbee.ATCommandFrame to change the value of the NJ parameter. Upon receiving the command, the XBee module will return an Exbee.ATCommandResultFrame indicating the status of the request.

iex> {:ok, pid} = Exbee.start_link(serial_port: "COM1", speed: 9600)
iex> Exbee.send_frame(pid, %Exbee.ATCommandFrame{command: "NJ", value: 1})
:ok

iex> flush()
{:exbee, %Exbee.ATCommandResultFrame{command: "NJ", status: :ok, value: ...}}

Configuration

Exbee options can either be passed directly to Exbee.start_link/1, or they'll be read from :exbee config values. For example, to default to a specific serial port, add this to the project's config.exs file.

config :exbee,
  serial_port: "COM1"

The following options are available:

Mix Tasks

License

This software is licensed under the Apache 2 License.