All Projects → emqx → Cocoamqtt

emqx / Cocoamqtt

Licence: other
MQTT for iOS and macOS written with Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Cocoamqtt

Wavin Ahc 9000 Mqtt
Esp8266 mqtt interface for Wavin AHC-9000/Jablotron AC-116
Stars: ✭ 47 (-95.84%)
Mutual labels:  mqtt
Server
Enterprise Open Source IM Solution
Stars: ✭ 53 (-95.31%)
Mutual labels:  mqtt
Pysmartnode
Micropython Smarthome framework
Stars: ✭ 58 (-94.86%)
Mutual labels:  mqtt
Lua Mosquitto
Lua bindings to the libmosquitto MQTT client library.
Stars: ✭ 47 (-95.84%)
Mutual labels:  mqtt
Hermes
Tiny MQTT broker written in Go
Stars: ✭ 50 (-95.57%)
Mutual labels:  mqtt
Homeautomation.codesys3
Home Automation system build in CoDeSys 3 with MQTT communication to any third party Home Automation software
Stars: ✭ 55 (-95.13%)
Mutual labels:  mqtt
Haskell Mqtt
An MQTT protocol implementation (client and server)
Stars: ✭ 42 (-96.28%)
Mutual labels:  mqtt
Flogo Contrib
Flogo Contribution repo. Contains activities, triggers, models and actions.
Stars: ✭ 60 (-94.69%)
Mutual labels:  mqtt
Paho.mqtt.c
An Eclipse Paho C client library for MQTT for Windows, Linux and MacOS. API documentation: https://eclipse.github.io/paho.mqtt.c/
Stars: ✭ 1,056 (-6.47%)
Mutual labels:  mqtt
Luamqtt
luamqtt - Pure-lua MQTT v3.1.1 and v5.0 client
Stars: ✭ 58 (-94.86%)
Mutual labels:  mqtt
Docker Flask Mongodb Example
Uses docker compose with a python flask microservice and MongoDB instance to make a sample application
Stars: ✭ 49 (-95.66%)
Mutual labels:  mqtt
Esp32 Onenet
ESP32 通过 MQTT 连接到中国移动物联网云平台 OneNET
Stars: ✭ 49 (-95.66%)
Mutual labels:  mqtt
Addon Zwave2mqtt
Z-Wave to MQTT - Home Assistant Community Add-ons
Stars: ✭ 58 (-94.86%)
Mutual labels:  mqtt
Mqtt Mongo
A generic service that subscribes to MQQT broker and saves messages to MongoDB.
Stars: ✭ 46 (-95.93%)
Mutual labels:  mqtt
Mqtt blackbox exporter
Prometheus Exporter for MQTT monitoring
Stars: ✭ 57 (-94.95%)
Mutual labels:  mqtt
Hass Yaap
Yet another alarm (control) panel for Home Assistant.
Stars: ✭ 44 (-96.1%)
Mutual labels:  mqtt
Gleam
An operation cluster based on MQTT
Stars: ✭ 53 (-95.31%)
Mutual labels:  mqtt
Nanodemqtt
MQTT for Nanode
Stars: ✭ 61 (-94.6%)
Mutual labels:  mqtt
Mqtt
MQTT broker written in D, using vibe.d
Stars: ✭ 59 (-94.77%)
Mutual labels:  mqtt
Mqtt Siemens S7 300
MQTT library block written in Siemens SCL for S7-300 PLC with CP343-1
Stars: ✭ 57 (-94.95%)
Mutual labels:  mqtt

CocoaMQTT

PodVersion Platforms License Swift version Coverage Status

MQTT v3.1.1 client library for iOS/macOS/tvOS written with Swift 5

Build

Build with Xcode 11.1 / Swift 5.1

Installation

CocoaPods

Install using CocoaPods by adding this line to your Podfile:

use_frameworks! # Add this if you are targeting iOS 8+ or using Swift
pod 'CocoaMQTT'  

Then, run the following command:

$ pod install

Carthage

Install using Carthage by adding the following lines to your Cartfile:

github "emqx/CocoaMQTT" "master"

Then, run the following command:

$ carthage update --platform iOS,macOS,tvOS

Last if you're building for OS X:

  • On your application targets “General” settings tab, in the "Embedded Binaries" section, drag and drop CocoaMQTT.framework from the Carthage/Build/Mac folder on disk.

If you're building for iOS, tvOS:

  • On your application targets “General” settings tab, in the "Linked Frameworks and Libraries" section, drag and drop each framework you want to use from the Carthage/Build folder on disk.

  • On your application targets "Build Phases" settings tab, click the "+" icon and choose "New Run Script Phase". Create a Run Script with the following contents:

    /usr/local/bin/carthage copy-frameworks
    
  • and add the paths to the frameworks you want to use under "Input Files", e.g.:

    $(SRCROOT)/Carthage/Build/iOS/CocoaMQTT.framework
    

Usage

Create a client to connect MQTT broker:

let clientID = "CocoaMQTT-" + String(ProcessInfo().processIdentifier)
let mqtt = CocoaMQTT(clientID: clientID, host: "localhost", port: 1883)
mqtt.username = "test"
mqtt.password = "public"
mqtt.willMessage = CocoaMQTTWill(topic: "/will", message: "dieout")
mqtt.keepAlive = 60
mqtt.delegate = self
mqtt.connect()

Now you can use closures instead of CocoaMQTTDelegate:

mqtt.didReceiveMessage = { mqtt, message, id in
	print("Message received in topic \(message.topic) with payload \(message.string!)")           
}

SSL Secure

One-way certification

No certificate is required locally. If you want to trust all untrust CA certificates, you can do this:

mqtt.allowUntrustCACertificate = true

Two-way certification

Need a .p12 file which is generated by a public key file and a private key file. You can generate the p12 file in the terminal:

openssl pkcs12 -export -clcerts -in client-cert.pem -inkey client-key.pem -out client.p12

MQTT over Websocket

In the 1.3.0, The CocoaMQTT has supported to connect to MQTT Broker by Websocket.

If you integrated by CocoaPods, you need to modify you Podfile like the followings and execute pod install again:

use_frameworks!

target 'Example' do
    pod 'CocoaMQTT/WebSockets', '1.3.0-rc.2'
end

Then, Create a MQTT instance over Websocket:

let websocket = CocoaMQTTWebSocket(uri: "/mqtt")
let mqtt = CocoaMQTT(clientID: clientID, host: host, port: 8083, socket: websocket)

// ...

_ = mqtt.connect()

If you want to add additional custom header to the connection, you can use the following:

let websocket = CocoaMQTTWebSocket(uri: "/mqtt")
websocket.headers = [
            "x-api-key": "value"
        ]
        websocket.enableSSL = true

let mqtt = CocoaMQTT(clientID: clientID, host: host, port: 8083, socket: websocket)

// ...

_ = mqtt.connect()

Example App

You can follow the Example App to learn how to use it. But we need to make the Example App works fisrt:

$ cd Examples

$ pod install

Then, open the Example.xcworkspace/ by Xcode and start it!

Dependencies

These third-party functions are used:

LICENSE

MIT License (see LICENSE)

Contributors

Author

Twitter

https://twitter.com/emqtt

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].