mqtt-hs-1.0.1: A MQTT client library.

Maintainerkoomi+mqtt@hackerspace-bamberg.de
Safe HaskellNone

Network.MQTT

Contents

Description

An MQTT client library.

Synopsis

Setup

run :: Config -> IO TerminatedSource

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.

Constructors

ParseFailed [String] String

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

ConnectFailed ConnectError 
UserRequested

disconnect was called

Instances

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) -> ConfigSource

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

data Commands Source

The communication channel used by publish, subscribe, etc.

mkCommands :: IO CommandsSource

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 -> HostNameSource

Hostname of the broker.

cPort :: Config -> PortNumberSource

Port of the broker.

cClean :: Config -> BoolSource

Should the server forget subscriptions and other state on disconnects?

cWill :: Config -> Maybe WillSource

Optional Will message.

cUsername :: Config -> Maybe TextSource

Optional username used for authentication.

cPassword :: Config -> Maybe TextSource

Optional password used for authentication.

cKeepAlive :: Config -> Maybe Word16Source

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

cClientID :: Config -> TextSource

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 -> CommandsSource

The channel used by publish, subscribe, etc.

cInputBufferSize :: Config -> IntSource

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.

Reexports