Flux MQTT v0.0.4 FluxMQTT View Source

An interface to connect to MQTT broker, sending and handling messages.

Link to this section Summary

Functions

Define a tuple with {Tortoise.Connection, specification} to be used as a child definition to the service supervision tree.

Send a message to the broker using the active MQTT service on the service supersivion tree.

Link to this section Functions

Link to this function

connection(handler, opts \\ [])

View Source (since 0.0.1)
connection(module(), keyword()) :: {Tortoise.Connection, keyword()}

Define a tuple with {Tortoise.Connection, specification} to be used as a child definition to the service supervision tree.

Parameters

Examples

iex> result = FluxMQTT.connection(Tortoise.Handler.Logger)
...> with {Tortoise.Connection, _specification} <- result, do: :passed
:passed
Link to this function

send(payload, topic, client_id, opts \\ [])

View Source (since 0.0.1)
send(String.t(), String.t(), String.t(), keyword()) ::
  :ok | {:ok, reference()} | {:error, :unknown_connection}

Send a message to the broker using the active MQTT service on the service supersivion tree.

Parameters

Examples

iex> opts = [
...>   client: [
...>     auth: [authenticate?: false],
...>     correlation: [create_correlation_id?: false]
...>   ]
...> ]
...> {connection, specification} = FluxMQTT.connection(Tortoise.Handler.Logger, opts)
...> connection.start_link(specification)
...> FluxMQTT.send("Hello, World!", "a/topic", "client")
:ok