MQTTKit can be installed using Carthage, add this line in your Carthage file:
github "arnecs/MQTTKit"
Manually
Clone the project repository, and add it to the your project.
git clone https://github.com/arnecs/MQTTKit.git
Usage
Use closures to get notified of events
public var didRecieveMessage: ((_ mqtt: MQTTClient, _ message: MQTTMessage) -> Void)?
public var didRecieveConack: ((_ mqtt: MQTTClient, _ status: MQTTConnackResponse) -> Void)?
public var didSubscribe: ((_ mqtt: MQTTClient, _ topic: String) -> Void)?
public var didUnsubscribe: ((_ mqtt: MQTTClient, _ topic: String) -> Void)?
public var didConnect: ((_ mqtt: MQTTClient, _ connected: Bool) -> Void)?
public var didDisconnect: ((_ mqtt: MQTTClient, _ error: Error?) -> Void)?
public var didChangeState: ((_ mqtt: MQTTClient, _ state: MQTTConnectionState) -> Void)?
Connect to a MQTT Broker
import MQTTKit
let mqtt = MQTTClient(host: "localhost")
mqtt.didConnect = {mqtt, connected in
// Gets called when a connack.accepted is recieved
}
// Or
mqtt.didRecieveConnack = {mqtt, response in
// Gets callen when connack is recieved
}
mqtt.connect()
Subscribe and unsubscribe to topics
mqtt.didSubscribe = {mqtt, topic in
// Gets called when suback is recieved
}
mqtt.didUnsubscribe = {mqtt, topic in
// Gets called when unsuback is recieved
}
mqtt.subscribe(to: "/my/topic")
mqtt.unsubscribe(from: "/my/topic")
MQTTKit
MQTT Client written in Swift
Getting Started
Installing
Swift Package Manager
MQTTKit can be installed using Swift Package Manager, add MQTTKit to the dependency list in Package.swift:
Carthage
MQTTKit can be installed using Carthage, add this line in your Carthage file:
Manually
Clone the project repository, and add it to the your project.
Usage
Use closures to get notified of events
Connect to a MQTT Broker
Subscribe and unsubscribe to topics
Publish and recieved messages
Running the tests
The tests requires a connection to a MQTT Broker. The address is located in the test file.
To start the tests, run:
or use
xcodebuild
to test for a specific platform:License
This project is licensed under the MIT License - see the LICENSE.md file for details