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
Define a tuple with {Tortoise.Connection, specification} to be used as a
child definition to the service supervision tree.
Parameters
handler- A module which usesFluxMQTT.Handler(orTortoise.Handler) responsible to handle messages received. Acceptsmodule/0.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. Acceptskeyword/0.
Examples
iex> result = FluxMQTT.connection(Tortoise.Handler.Logger)
...> with {Tortoise.Connection, _specification} <- result, do: :passed
:passed
Send a message to the broker using the active MQTT service on the service supersivion tree.
Parameters
payload- The message. AcceptsString.t/0.topic- The MQTT topic which the message will be sent. AcceptsString.t/0.client_id- The sender client id. AcceptsString.t/0.opts- TheTortoise.publish/4options. Acceptskeyword/0.
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