Copyright | (c) Dustin Sallings 2019 |
---|---|
License | BSD3 |
Maintainer | dustin@spy.net |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
An MQTT protocol client
Both MQTT 3.1.1 and MQTT 5.0 are supported.
Synopsis
- data MQTTConfig = MQTTConfig {}
- data MQTTClient
- data QoS
- type Topic = Text
- mqttConfig :: MQTTConfig
- mkLWT :: Topic -> ByteString -> Bool -> LastWill
- data LastWill = LastWill {
- _willRetain :: Bool
- _willQoS :: QoS
- _willTopic :: ByteString
- _willMsg :: ByteString
- _willProps :: [Property]
- data ProtocolLevel
- data Property
- = PropPayloadFormatIndicator Word8
- | PropMessageExpiryInterval Word32
- | PropContentType ByteString
- | PropResponseTopic ByteString
- | PropCorrelationData ByteString
- | PropSubscriptionIdentifier Int
- | PropSessionExpiryInterval Word32
- | PropAssignedClientIdentifier ByteString
- | PropServerKeepAlive Word16
- | PropAuthenticationMethod ByteString
- | PropAuthenticationData ByteString
- | PropRequestProblemInformation Word8
- | PropWillDelayInterval Word32
- | PropRequestResponseInformation Word8
- | PropResponseInformation ByteString
- | PropServerReference ByteString
- | PropReasonString ByteString
- | PropReceiveMaximum Word16
- | PropTopicAliasMaximum Word16
- | PropTopicAlias Word16
- | PropMaximumQoS Word8
- | PropRetainAvailable Word8
- | PropUserProperty ByteString ByteString
- | PropMaximumPacketSize Word32
- | PropWildcardSubscriptionAvailable Word8
- | PropSubscriptionIdentifierAvailable Word8
- | PropSharedSubscriptionAvailable Word8
- data SubOptions = SubOptions {}
- subOptions :: SubOptions
- runClient :: MQTTConfig -> IO MQTTClient
- runClientTLS :: MQTTConfig -> IO MQTTClient
- waitForClient :: MQTTClient -> IO (Either SomeException ())
- connectURI :: MQTTConfig -> URI -> IO MQTTClient
- disconnect :: MQTTClient -> DiscoReason -> [Property] -> IO ()
- normalDisconnect :: MQTTClient -> IO ()
- subscribe :: MQTTClient -> [(Filter, SubOptions)] -> IO ([Either SubErr QoS], [Property])
- unsubscribe :: MQTTClient -> [Filter] -> [Property] -> IO ()
- publish :: MQTTClient -> Topic -> ByteString -> Bool -> IO ()
- publishq :: MQTTClient -> Topic -> ByteString -> Bool -> QoS -> [Property] -> IO ()
- pubAliased :: MQTTClient -> Topic -> ByteString -> Bool -> QoS -> [Property] -> IO ()
- svrProps :: MQTTClient -> IO [Property]
Configuring the client.
data MQTTConfig Source #
Configuration for setting up an MQTT client.
MQTTConfig | |
|
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
QoS values for publishing and subscribing.
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.
An MQTT Will message.
LastWill | |
|
data ProtocolLevel Source #
MQTT Protocol Levels
Protocol311 | MQTT 3.1.1 |
Protocol50 | MQTT 5.0 |
Instances
Instances
Eq Property Source # | |
Show Property Source # | |
ByteMe Property Source # | |
Defined in Network.MQTT.Types toBytes :: ProtocolLevel -> Property -> [Word8] toByteString :: ProtocolLevel -> Property -> ByteString Source # |
data SubOptions Source #
Options used at subscribe time to define how to handle incoming messages.
SubOptions | |
|
Instances
Eq SubOptions Source # | |
Defined in Network.MQTT.Types (==) :: SubOptions -> SubOptions -> Bool # (/=) :: SubOptions -> SubOptions -> Bool # | |
Show SubOptions Source # | |
Defined in Network.MQTT.Types showsPrec :: Int -> SubOptions -> ShowS # show :: SubOptions -> String # showList :: [SubOptions] -> ShowS # | |
ByteMe SubOptions Source # | |
Defined in Network.MQTT.Types toBytes :: ProtocolLevel -> SubOptions -> [Word8] toByteString :: ProtocolLevel -> SubOptions -> ByteString Source # |
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.
:: MQTTClient | |
-> Topic | Topic |
-> ByteString | Message body |
-> Bool | Retain flag |
-> IO () |
Publish a message (QoS 0).
:: MQTTClient | |
-> Topic | Topic |
-> ByteString | Message body |
-> Bool | Retain flag |
-> QoS | QoS |
-> [Property] | Properties |
-> IO () |
Publish a message with the specified QoS and Properties list.
:: 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.