Flux MQTT
An interface to connect to MQTT broker, sending and handling messages.
It uses Tortoise, check their documentation to understand how this library
perform the configuration, handling, and delivery of MQTT messages.
FluxMQTT describes how to define a connection specification and how to send a message.
FluxMQTT.Handler describes how to handle MQTT messages defined in a connection.
Application Configuration
import Config
# Default values
config :flux_mqtt,
broker: [
host: "emq",
port: 1883
],
client: [
name: "client",
auth: [
authenticate?: true,
username: "client",
password: "password"
],
correlation: [
create_correlation_id?: true,
base: 36,
length: 8,
as: :sufix,
separator: "_"
]
],
initial_state: [],
topics: []
Configuration Options
broker- Set the MQTT broker. Options are:host- The MQTT broker hostname. Defaults toemq.port- The MQTT broker port. Defaults to1883.
client- Set the service settings as a broker client. Options are:name- The name of the client. Defaults toclient. It is suggested to set the name as the name of the service.auth- Set broker authentication settings. Options are:authenticate?- Iftrue, define the connection specification withusernameandpassword(see below). Defaults totrue.username- The username to be used as service authentication. Defaults toclient.password- The username's password. Defaults topassword.
correlation- Set the client correlation settings. Options are:create_correlation_id?- Iftrue, the serviceclient_idwill be defined withclient.nameand a correlation string. Defaults totrue.base- The base to be used when generating a correlation id. Must have a value in the range2..36. Defaults to36.length- How many characters will be defined for the correlation id. Defaults to8.as-:sufixsets the correlation id before the client name.:prefixsets the correlation id after the client name. Defaults to:sufix.separator- The separator between the correlation id and the client name. Defaults to_.
initial_state- A keyword list with data to be set as the handler initial state. Defaults to an empty list.topics- A list of{topic, qos}elements from which the handler will receive messages. Defaults to an empty list.