Flux MQTT v0.0.1 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(atom(), keyword()) :: {Tortoise.Connection, keyword()}

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

Parameters

  • handler - A module which uses FluxMQTT.Handler (or Tortoise.Handler) responsible to handle messages received.

  • opts - A keyword list with connection settings. Definition is the same as application configuration and the opts defined here are merged with the application configuration. Can be blank.

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(binary(), binary(), binary(), keyword()) ::
  :ok | {:ok, reference()} | {:error, :unknown_connection}

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

Parameters

  • payload - The message string.

  • topic - The MQTT topic which the message will be sent.

  • client_id - The sender client id.

  • opts - The Tortoise.publish/4 options.

Examples

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