mqtt-hs-1.0.2: A MQTT client library.

CopyrightLukas Braun 2014-2016
Safe HaskellNone




An MQTT client library.



run :: Config -> IO Terminated Source #

Connect to the configured broker, write received Publish messages to the cPublished channel and handle commands from the cCommands channel.

Exceptions are propagated.

data Terminated Source #

Reasons for why the connection was terminated.


ParseFailed [String] String

at the context in [String] with the given message.

ConnectFailed ConnectError 

disconnect was called

Show Terminated Source # 
Instance details

Defined in Network.MQTT.Internal

disconnect :: Config -> IO () Source #

Close the connection after sending a Disconnect message.

See also: Will

data Config Source #

The various options when establishing a connection. See below for available accessors.

defaultConfig :: Commands -> TChan (Message PUBLISH) -> Config Source #

Defaults for Config, connects to a server running on localhost.

data Commands Source #

The communication channel used by publish, subscribe, etc.

mkCommands :: IO Commands Source #

Create a new Commands channel.

There should be one channel per MQTT connection. It might be reused by subsequent connections, but never by multiple connections concurrently.

Config accessors

cHost :: Config -> HostName Source #

Hostname of the broker.

cPort :: Config -> PortNumber Source #

Port of the broker.

cClean :: Config -> Bool Source #

Should the server forget subscriptions and other state on disconnects?

cWill :: Config -> Maybe Will Source #

Optional Will message.

cUsername :: Config -> Maybe Text Source #

Optional username used for authentication.

cPassword :: Config -> Maybe Text Source #

Optional password used for authentication.

cKeepAlive :: Config -> Maybe Word16 Source #

Time (in seconds) after which a PingReq is sent to the broker if no regular message was sent. Nothing means no limit.

cClientID :: Config -> Text Source #

Client ID used by the server to identify clients.

cLogDebug :: Config -> String -> IO () Source #

Function for debug-level logging.

cPublished :: Config -> TChan (Message PUBLISH) Source #

The channel received Publish messages are written to.

cCommands :: Config -> Commands Source #

The channel used by publish, subscribe, etc.

cInputBufferSize :: Config -> Int Source #

Maximum number of bytes read from the network at once.

Subscribing and publishing

subscribe :: Config -> [(Topic, QoS)] -> IO [QoS] Source #

Subscribe to the Topics with the corresponding QoS. Returns the QoS that were granted (lower or equal to the ones requested) in the same order.

The Topics may contain wildcards.

unsubscribe :: Config -> [Topic] -> IO () Source #

Unsubscribe from the given Topics.

publish :: Config -> QoS -> Bool -> Topic -> ByteString -> IO () Source #

Publish a message to the given Topic at the requested QoS level. The payload can be any sequence of bytes, including none at all. True means the server should retain the message for future subscribers to the topic.

The Topic must not contain wildcards.