net-mqtt-0.5.0.1: An MQTT Protocol Implementation.

Copyright(c) Dustin Sallings 2019
LicenseBSD3
Maintainerdustin@spy.net
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Network.MQTT.Client

Contents

Description

An MQTT protocol client

Both MQTT 3.1.1 and MQTT 5.0 are supported.

Synopsis

Configuring the client.

data MQTTConfig Source #

Configuration for setting up an MQTT client.

Constructors

MQTTConfig 

Fields

data MQTTClient Source #

The MQTT client. A client may be built using either runClient or runClientTLS. For example:

  mc <- runClient mqttConfig{}
  publish mc "some/topic" "some message" False

data QoS Source #

QoS values for publishing and subscribing.

Constructors

QoS0 
QoS1 
QoS2 
Instances
Bounded QoS Source # 
Instance details

Defined in Network.MQTT.Types

Methods

minBound :: QoS #

maxBound :: QoS #

Enum QoS Source # 
Instance details

Defined in Network.MQTT.Types

Methods

succ :: QoS -> QoS #

pred :: QoS -> QoS #

toEnum :: Int -> QoS #

fromEnum :: QoS -> Int #

enumFrom :: QoS -> [QoS] #

enumFromThen :: QoS -> QoS -> [QoS] #

enumFromTo :: QoS -> QoS -> [QoS] #

enumFromThenTo :: QoS -> QoS -> QoS -> [QoS] #

Eq QoS Source # 
Instance details

Defined in Network.MQTT.Types

Methods

(==) :: QoS -> QoS -> Bool #

(/=) :: QoS -> QoS -> Bool #

Show QoS Source # 
Instance details

Defined in Network.MQTT.Types

Methods

showsPrec :: Int -> QoS -> ShowS #

show :: QoS -> String #

showList :: [QoS] -> ShowS #

type Topic = Text Source #

An MQTT topic.

mqttConfig :: MQTTConfig Source #

A default MQTTConfig. A _connID should be provided by the client in the returned config, but the defaults should work for testing. In MQTTv5, an empty connection ID may be sent and the server may assign an identifier for you and return it in the PropAssignedClientIdentifier property.

mkLWT :: Topic -> ByteString -> Bool -> LastWill Source #

A convenience method for creating a LastWill.

data LastWill Source #

An MQTT Will message.

Instances
Eq LastWill Source # 
Instance details

Defined in Network.MQTT.Types

Show LastWill Source # 
Instance details

Defined in Network.MQTT.Types

data SubOptions Source #

Options used at subscribe time to define how to handle incoming messages.

Constructors

SubOptions 

Fields

subOptions :: SubOptions Source #

Reasonable subscription option defaults at QoS0.

Running and waiting for the client.

runClient :: MQTTConfig -> IO MQTTClient Source #

Set up and run a client from the given config.

runClientTLS :: MQTTConfig -> IO MQTTClient Source #

Set up and run a client connected via TLS.

waitForClient :: MQTTClient -> IO (Either SomeException ()) Source #

Wait for a client to terminate its connection.

connectURI :: MQTTConfig -> URI -> IO MQTTClient Source #

Connect to an MQTT server by URI. Currently only mqtt and mqtts URLs are supported. The host, port, username, and password will be derived from the URI and the values supplied in the config will be ignored.

disconnect :: MQTTClient -> DiscoReason -> [Property] -> IO () Source #

Disconnect from the MQTT server.

normalDisconnect :: MQTTClient -> IO () Source #

Disconnect with DiscoNormalDisconnection and no properties.

General client interactions.

subscribe :: MQTTClient -> [(Filter, SubOptions)] -> IO ([Either SubErr QoS], [Property]) Source #

Subscribe to a list of topic filters with their respective QoSes. The accepted QoSes are returned in the same order as requested.

unsubscribe :: MQTTClient -> [Filter] -> [Property] -> IO () Source #

Unsubscribe from a list of topic filters.

publish Source #

Arguments

:: MQTTClient 
-> Topic

Topic

-> ByteString

Message body

-> Bool

Retain flag

-> IO () 

Publish a message (QoS 0).

publishq Source #

Arguments

:: MQTTClient 
-> Topic

Topic

-> ByteString

Message body

-> Bool

Retain flag

-> QoS

QoS

-> [Property]

Properties

-> IO () 

Publish a message with the specified QoS and Properties list.

pubAliased Source #

Arguments

:: MQTTClient 
-> Topic

Topic

-> ByteString

Message body

-> Bool

Retain flag

-> QoS

QoS

-> [Property]

Properties

-> IO () 

Publish a message with the specified QoS and Properties list. If possible, use an alias to shorten the message length. The alias list is managed by the client in a first-come, first-served basis, so if you use this with more properties than the broker allows, only the first N (up to TopicAliasMaximum, as specified by the broker at connect time) will be aliased.

This is safe to use as a general publish mechanism, as it will default to not aliasing whenver there's not already an alias and we can't create any more.

svrProps :: MQTTClient -> IO [Property] Source #

Get the list of properties that were sent from the broker at connect time.