All Projects → matsune → swift-mqtt

matsune / swift-mqtt

Licence: MIT license
MQTT client for Swift using SwiftNIO

Programming Languages

swift
15916 projects
shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to swift-mqtt

eMQTT5
An embedded MQTTv5 client in C++ with minimal footprint, maximal performance
Stars: ✭ 51 (+54.55%)
Mutual labels:  mqtt-client
Adafruit CircuitPython MiniMQTT
MQTT Client Library for CircuitPython
Stars: ✭ 51 (+54.55%)
Mutual labels:  mqtt-client
web-mqtt-client
A better MQTT API for the browser
Stars: ✭ 48 (+45.45%)
Mutual labels:  mqtt-client
python-mqtt-client-shell
Python-based MQTT client command shell
Stars: ✭ 45 (+36.36%)
Mutual labels:  mqtt-client
Kitura-NIO
A networking library for Kitura, based on SwiftNIO
Stars: ✭ 35 (+6.06%)
Mutual labels:  swiftnio
hfeasy
HFeasy - firmware for HF-LPx100/LPx30 based devices
Stars: ✭ 35 (+6.06%)
Mutual labels:  mqtt-client
StriderMqtt
A very thin MQTT client
Stars: ✭ 21 (-36.36%)
Mutual labels:  mqtt-client
swift-nio-mqtt
MQTT v5.0 client powered by SwiftNIO.
Stars: ✭ 23 (-30.3%)
Mutual labels:  mqtt-client
net-mqtt-client-react
Asynchronous MQTT client built on React
Stars: ✭ 45 (+36.36%)
Mutual labels:  mqtt-client
tuya-home-assistant
Home Assistant integration for controlling Powered by Tuya (PBT) devices using Tuya Open API, maintained by the Home Assistant Community and Tuya Developer Team.
Stars: ✭ 684 (+1972.73%)
Mutual labels:  mqtt-client
homie-device
NodeJS port of Homie for IoT
Stars: ✭ 20 (-39.39%)
Mutual labels:  mqtt-client
MQTT-Board
Diagnostic-oriented MQTT client tool. Supports MQTT 5.0 and 3.1.X protocols, connections to multiple brokers, MQTT operations logs and multiple subscribe widgets with unique/history topic filtering mode. Saves configuration in browser's local cache.
Stars: ✭ 81 (+145.45%)
Mutual labels:  mqtt-client
ESP8266 WiFi v2.x
ESP8266 WiFi for OpenEVSE Version 2.x
Stars: ✭ 72 (+118.18%)
Mutual labels:  mqtt-client
flutter im demo
📞 Flutter 使用 MQTT实现IM功能
Stars: ✭ 81 (+145.45%)
Mutual labels:  mqtt-client
UnrealMosquitto
A MQTT client with blueprint support for Unreal Engine 4, based on Mosquitto.
Stars: ✭ 41 (+24.24%)
Mutual labels:  mqtt-client
Android-MQTT-Demo
An android application to demonstrate the complete MQTT lifecycle.
Stars: ✭ 31 (-6.06%)
Mutual labels:  mqtt-client
MQTTnet
MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.
Stars: ✭ 3,309 (+9927.27%)
Mutual labels:  mqtt-client
nmqtt
Native Nim MQTT client library
Stars: ✭ 39 (+18.18%)
Mutual labels:  mqtt-client
owlos
DIY Open Source OS for building IoT ecosystems
Stars: ✭ 43 (+30.3%)
Mutual labels:  mqtt-client
mica-mqtt
基于 java aio 实现的低延迟、高性能百万级 mqtt client 组件和 mqtt broker 服务。🔝🔝 记得右上角点个star 关注更新!
Stars: ✭ 128 (+287.88%)
Mutual labels:  mqtt-client

swift-mqtt

Asynchronous MQTT client library using SwiftNIO for networking layer.

Usage

Create an instance of MQTTClient with parameters for connection.

let client = MQTTClient(
    host: "localhost",
    port: 1883,
    clientID: "swift-mqtt client",
    cleanSession: true,
    keepAlive: 30,
    willMessage: PublishMessage(topic: "will", payload: "will msg", retain: false, qos: .atMostOnce),
)
client.connect()

You can handle events with delegate methods.

client.delegate = self

...

// MQTTClientDelegate

func mqttClient(_ client: MQTTClient, didReceive packet: MQTTPacket) {
    ...
}

func mqttClient(_ client: MQTTClient, didChange state: ConnectionState) {
    ...
}

func mqttClient(_ client: MQTTClient, didCatchError error: Error) {
    ...
}

Publish

client.publish(topic: "topic", retain: false, qos: QOS.0, payload: "payload")

Subscribe

client.subscribe(topic: "topic", qos: QOS.0)

Unsubscribe

client.unsubscribe(topic: "topic")

Disconnect

client.disconnect()

SSL/TLS connection

This library uses SwiftNIO SSL for SSL connection. You can configure settings of a client.

let caCert = "./server/certs/ca/ca_cert.pem"
let clientCert = "./server/certs/client/client_cert.pem"
let keyCert = "./server/certs/client/private/client_key.pem"
let tlsConfiguration = try? TLSConfiguration.forClient(
    minimumTLSVersion: .tlsv11,
    maximumTLSVersion: .tlsv12,
    certificateVerification: .noHostnameVerification,
    trustRoots: NIOSSLTrustRoots.certificates(NIOSSLCertificate.fromPEMFile(caCert)),
    certificateChain: NIOSSLCertificate.fromPEMFile(clientCert).map { .certificate($0) },
    privateKey: .privateKey(.init(file: keyCert, format: .pem))
)

client.tlsConfiguration = tlsConfiguration
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].