{"id":13995312,"url":"https://github.com/matsune/swift-mqtt","last_synced_at":"2026-02-21T19:46:42.900Z","repository":{"id":53793373,"uuid":"287924638","full_name":"matsune/swift-mqtt","owner":"matsune","description":"MQTT client for Swift using SwiftNIO","archived":false,"fork":false,"pushed_at":"2021-03-13T07:01:50.000Z","size":98,"stargazers_count":36,"open_issues_count":4,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-10T14:19:00.780Z","etag":null,"topics":["async","mqtt","mqtt-client","swiftnio"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matsune.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-16T10:50:05.000Z","updated_at":"2024-06-18T22:44:58.000Z","dependencies_parsed_at":"2022-08-23T21:10:44.627Z","dependency_job_id":null,"html_url":"https://github.com/matsune/swift-mqtt","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsune%2Fswift-mqtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsune%2Fswift-mqtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsune%2Fswift-mqtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsune%2Fswift-mqtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matsune","download_url":"https://codeload.github.com/matsune/swift-mqtt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227177897,"owners_count":17743194,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","mqtt","mqtt-client","swiftnio"],"created_at":"2024-08-09T14:03:20.727Z","updated_at":"2026-02-21T19:46:42.893Z","avatar_url":"https://github.com/matsune.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# swift-mqtt\n\nAsynchronous MQTT client library using [SwiftNIO](https://github.com/apple/swift-nio) for networking layer.\n\n- Based on [MQTT Version 3.1.1 Specification](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718028).\n- Supports SSL/TLS connection\n\n## Usage\n\nCreate an instance of `MQTTClient` with parameters for connection.\n\n```swift\nlet client = MQTTClient(\n    host: \"localhost\",\n    port: 1883,\n    clientID: \"swift-mqtt client\",\n    cleanSession: true,\n    keepAlive: 30,\n    willMessage: PublishMessage(topic: \"will\", payload: \"will msg\", retain: false, qos: .atMostOnce),\n)\nclient.connect()\n```\n\nYou can handle events with delegate methods.\n\n```swift\nclient.delegate = self\n\n...\n\n// MQTTClientDelegate\n\nfunc mqttClient(_ client: MQTTClient, didReceive packet: MQTTPacket) {\n    ...\n}\n\nfunc mqttClient(_ client: MQTTClient, didChange state: ConnectionState) {\n    ...\n}\n\nfunc mqttClient(_ client: MQTTClient, didCatchError error: Error) {\n    ...\n}\n```\n\n### Publish\n\n```swift\nclient.publish(topic: \"topic\", retain: false, qos: QOS.0, payload: \"payload\")\n```\n\n### Subscribe\n\n```swift\nclient.subscribe(topic: \"topic\", qos: QOS.0)\n```\n\n### Unsubscribe\n\n```swift\nclient.unsubscribe(topic: \"topic\")\n```\n\n### Disconnect\n\n```swift\nclient.disconnect()\n```\n\n## SSL/TLS connection\n\nThis library uses [SwiftNIO SSL](https://github.com/apple/swift-nio-ssl) for SSL connection. You can configure settings of a client.\n\n```swift\nlet caCert = \"./server/certs/ca/ca_cert.pem\"\nlet clientCert = \"./server/certs/client/client_cert.pem\"\nlet keyCert = \"./server/certs/client/private/client_key.pem\"\nlet tlsConfiguration = try? TLSConfiguration.forClient(\n    minimumTLSVersion: .tlsv11,\n    maximumTLSVersion: .tlsv12,\n    certificateVerification: .noHostnameVerification,\n    trustRoots: NIOSSLTrustRoots.certificates(NIOSSLCertificate.fromPEMFile(caCert)),\n    certificateChain: NIOSSLCertificate.fromPEMFile(clientCert).map { .certificate($0) },\n    privateKey: .privateKey(.init(file: keyCert, format: .pem))\n)\n\nclient.tlsConfiguration = tlsConfiguration\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatsune%2Fswift-mqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatsune%2Fswift-mqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatsune%2Fswift-mqtt/lists"}