Arduino Router Bridge

Originally developed for the Arduino Uno Q, this library is an Elixir interface for communicating with the Arduino Router

The library communicates via the router's Unix socket. It exposes a GenServer-based ArduinoRouter.Bridge module that enables callers to make RPC calls (and notifications). It also allows Elixir code to register RPC methods and respond to them from Elixir.

The actual transport mechanism used by the bridge is pluggable (primarily to faciliate unit testing in the library). The ArduinoRouter.Socket module conforms to the transport behaviour and handles some details of working with the android-router's Unix socket.

Features

Usage

Start the bridge:

{:ok, _pid} = ArduinoRouter.Bridge.start_link()

Use a custom transport (used for tests or perhaps alternative transports):

{:ok, _pid} = ArduinoRouter.Bridge.start_link(transport: {MyTransport, [opt: value]})

Register a handler for incoming RPC requests:

ArduinoRouter.Bridge.provide("get_current_weather", WeatherProvider, :get_current_forecast)

Synchronous call (blocks until a response or timeout):

ArduinoRouter.Bridge.call("get_sensor_reading", [])
# => {:ok, result} | {:error, reason}

Asynchronous call. Returns :ok immediately and sends a message to the process that called call_async when a response is received:

ArduinoRouter.Bridge.call_async("long_running", [1, 2])

Send a notification (fire-and-forget):

ArduinoRouter.Bridge.notify("log_message", ["Hello from Elixir"])

[!TIP] If you alias the ArduinoRouter.Bridge module then ArduinoRouter.Bridge.call>(...) becomes Bridge.call(...) which makes the code look very similar to the same code in a Sketch, or through the Python interface.

License

This project is licensed under the MIT License — see the LICENSE file for details. SPDX identifier: MIT.

Contributing

Bug reports and pull requests are welcome. Fixes will be made as time permists

Authors

This project was created by Scott Thompson