-
Notifications
You must be signed in to change notification settings - Fork 422
CocoaMQTT5
MQTT Client
public class CocoaMQTT5: NSObject, CocoaMQTT5Client
CocoaMQTT5Client
, CocoaMQTTDeliverProtocol
, CocoaMQTTReaderDelegate
, CocoaMQTTSocketDelegate
, NSObject
Initial client object
public init(clientID: String, host: String = "localhost", port: UInt16 = 1883, socket: CocoaMQTTSocketProtocol = CocoaMQTTSocket())
- clientID: Client Identifier
- host: The MQTT broker host domain or IP address. Default is "localhost"
- port: The MQTT service port of host. Default is 1883
public weak var delegate: CocoaMQTT5Delegate?
public var host = "localhost"
public var port: UInt16 = 1883
public var clientID: String
public var username: String?
public var password: String?
Clean Session flag. Default is true
public var cleanSession = true
Setup a Last Will Message to client before connecting to broker
public var willMessage: CocoaMQTT5Message?
Enable backgounding socket if running on iOS platform. Default is true
public var backgroundOnSocket: Bool
Delegate Executed queue. Default is DispatchQueue.main
public var delegateQueue = DispatchQueue.main
The delegate/closure callback function will be committed asynchronously to it
public var connState = CocoaMQTTConnState.disconnected
Re-deliver the un-acked messages
public var deliverTimeout: Double
Message queue size. default 1000
public var messageQueueSize: UInt
The new publishing messages of Qos1/Qos2 will be drop, if the queue is full
In-flight window size. default 10
public var inflightWindowSize: UInt
Keep alive time interval
public var keepAlive: UInt16 = 60
Enable auto-reconnect mechanism
public var autoReconnect = false
Reconnect time interval
public var autoReconnectTimeInterval: UInt16 = 1
Maximum auto reconnect time interval
public var maxAutoReconnectTimeInterval: UInt16 = 128
The timer starts from autoReconnectTimeInterval
second and grows exponentially until this value
After that, it uses this value for subsequent requests.
3.1.2.11 CONNECT Properties
public var connectProperties: MqttConnectProperties?
3.15.2.2 AUTH Properties
public var authProperties: MqttAuthProperties?
Console log level
public var logLevel: CocoaMQTTLoggerLevel
Enable SSL connection
public var enableSSL: Bool
public var sslSettings: [String: NSObject]?
Allow self-signed ca certificate.
public var allowUntrustCACertificate: Bool
Default is false
The subscribed topics in current communication
public var subscriptions: [String: CocoaMQTTQoS] = [:]
public var didConnectAck: (CocoaMQTT5, CocoaMQTTCONNACKReasonCode, MqttDecodeConnAck) -> Void
public var didPublishMessage: (CocoaMQTT5, CocoaMQTT5Message, UInt16) -> Void
public var didPublishAck: (CocoaMQTT5, UInt16, MqttDecodePubAck) -> Void
public var didPublishRec: (CocoaMQTT5, UInt16, MqttDecodePubRec) -> Void
public var didReceiveMessage: (CocoaMQTT5, CocoaMQTT5Message, UInt16, MqttDecodePublish) -> Void
public var didSubscribeTopics: (CocoaMQTT5, NSDictionary, [String], MqttDecodeSubAck) -> Void
public var didUnsubscribeTopics: (CocoaMQTT5, [String], MqttDecodeUnsubAck) -> Void
public var didPing: (CocoaMQTT5) -> Void
public var didReceivePong: (CocoaMQTT5) -> Void
public var didDisconnect: (CocoaMQTT5, Error?) -> Void
public var didDisconnectReasonCode: (CocoaMQTT5, CocoaMQTTDISCONNECTReasonCode) -> Void
public var didAuthReasonCode: (CocoaMQTT5, CocoaMQTTAUTHReasonCode) -> Void
public var didReceiveTrust: (CocoaMQTT5, SecTrust, @escaping (Bool) -> Swift.Void) -> Void
public var didCompletePublish: (CocoaMQTT5, UInt16, MqttDecodePubComp) -> Void
public var didChangeState: (CocoaMQTT5, CocoaMQTTConnState) -> Void
Connect to MQTT broker
public func connect() -> Bool
- Bool: It indicates whether successfully calling socket connect function. Not yet established correct MQTT session
Connect to MQTT broker
public func connect(timeout: TimeInterval) -> Bool
- timeout: Connect timeout
- Bool: It indicates whether successfully calling socket connect function. Not yet established correct MQTT session
Send a DISCONNECT packet to the broker then close the connection
public func disconnect()
public func disconnect(reasonCode : CocoaMQTTDISCONNECTReasonCode,userProperties : [String: String] )
Send a PING request to broker
public func ping()
Publish a message to broker
@discardableResult
public func publish(_ topic: String, withString string: String, qos: CocoaMQTTQoS = .qos1, DUP: Bool = false
, retained: Bool = false, properties: MqttPublishProperties) -> Int
- topic: Topic Name. It can not contain '#', '+' wildcards
- string: Payload string
- qos: Qos. Default is Qos1
- retained: Retained flag. Mark this message is a retained message. default is false
- 0 will be returned, if the message's qos is qos0
- 1-65535 will be returned, if the messages's qos is qos1/qos2
- -1 will be returned, if the messages queue is full
Publish a message to broker
@discardableResult
public func publish(_ message: CocoaMQTT5Message, DUP: Bool = false, retained: Bool = false, properties: MqttPublishProperties) -> Int
- message: Message
Subscribe a <Topic Name>/<Topic Filter>
public func subscribe(_ topic: String, qos: CocoaMQTTQoS = .qos1)
- topic: Topic Name or Topic Filter
- qos: Qos. Default is qos1
Subscribe a lists of topics
public func subscribe(_ topics: [MqttSubscription])
- topics: A list of tuples presented by
(<Topic Names>/<Topic Filters>, Qos)
Unsubscribe a Topic
public func unsubscribe(_ topic: String)
- topic: A Topic Name or Topic Filter
Unsubscribe a list of topics
public func unsubscribe(_ topics: [MqttSubscription])
- topics: A list of
<Topic Names>/<Topic Filters>
Authentication exchange
public func auth(reasonCode : CocoaMQTTAUTHReasonCode,authProperties : MqttAuthProperties)
public func socketConnected(_ socket: CocoaMQTTSocketProtocol)
public func socket(_ socket: CocoaMQTTSocketProtocol,
didReceive trust: SecTrust,
completionHandler: @escaping (Bool) -> Swift.Void)
public func socketDidSecure(_ sock: GCDAsyncSocket)
public func socket(_ socket: CocoaMQTTSocketProtocol, didWriteDataWithTag tag: Int)
public func socket(_ socket: CocoaMQTTSocketProtocol, didRead data: Data, withTag tag: Int)
public func socketDidDisconnect(_ socket: CocoaMQTTSocketProtocol, withError err: Error?)
Types
- CloseCode
- CocoaMQTT
- CocoaMQTT5
- CocoaMQTT5Message
- CocoaMQTTAUTHReasonCode
- CocoaMQTTCONNACKReasonCode
- CocoaMQTTConnAck
- CocoaMQTTConnState
- CocoaMQTTDISCONNECTReasonCode
- CocoaMQTTError
- CocoaMQTTError.FoundationConnection
- CocoaMQTTLogger
- CocoaMQTTLoggerLevel
- CocoaMQTTMessage
- CocoaMQTTPUBACKReasonCode
- CocoaMQTTPUBCOMPReasonCode
- CocoaMQTTPUBRECReasonCode
- CocoaMQTTPUBRELReasonCode
- CocoaMQTTPropertyName
- CocoaMQTTQoS
- CocoaMQTTSUBACKReasonCode
- CocoaMQTTSocket
- CocoaMQTTUNSUBACKReasonCode
- CocoaMQTTWebSocket
- CocoaMQTTWebSocket.DefaultConnectionBuilder
- CocoaMQTTWebSocket.FoundationConnection
- CocoaMQTTWebSocket.StarscreamConnection
- CocoaRetainHandlingOption
- ErrorType
- FoundationStream
- MqttAuthProperties
- MqttConnectProperties
- MqttDecodeConnAck
- MqttDecodePubAck
- MqttDecodePubComp
- MqttDecodePubRec
- MqttDecodePubRel
- MqttDecodePublish
- MqttDecodeSubAck
- MqttDecodeUnsubAck
- MqttPublishProperties
- MqttSubscription
- PayloadFormatIndicator
- SSLCert
- SSLClientCertificate
- SSLClientCertificateError
- SSLSecurity
- SSLSettings
- WSError
- WebSocket
- WebSocket.OpCode
- WebSocket.WSResponse
- formatInt
Protocols
- CocoaMQTT5Delegate
- CocoaMQTTDelegate
- CocoaMQTTSocketDelegate
- CocoaMQTTSocketProtocol
- CocoaMQTTWebSocketConnection
- CocoaMQTTWebSocketConnectionBuilder
- CocoaMQTTWebSocketConnectionDelegate
- SSLTrustValidator
- WSStream
- WSStreamDelegate
- WebSocketAdvancedDelegate
- WebSocketClient
- WebSocketDelegate
- WebSocketPongDelegate