Code Monkey home page Code Monkey logo

mqtt-client-framework's Introduction

MQTT-Client-Framework

an Objective-C native MQTT Framework http://mqtt.org

Tested with a long list of brokers

  • mosquitto
  • paho
  • rabbitmq
  • hivemq
  • rsmb
  • mosca
  • vernemq
  • emqtt
  • moquette
  • ActiveMQ
  • Apollo
  • CloudMQTT
  • aws
  • hbmqtt (MQTTv311 only, limitations)
  • aedes

As a CocoaPod

Use the CocoaPod MQTTClient!

Add this to your Podfile:

pod 'MQTTClient'

which is a short for

pod 'MQTTClient/Min'
pod 'MQTTClient/Manager'

The Manager subspec includes the MQTTSessionManager class.

Additionally add this subspec if you want to use MQTT over Websockets:

pod 'MQTTClient/Websocket'

If you want to do your logging with CocoaLumberjack (my suggestion), use

pod 'MQTTClient/MinL'
pod 'MQTTClient/ManagerL'
pod 'MQTTClient/WebsocketL'

instead.

As a dynamic library

Or use the dynamic library created in the MQTTFramework target.

As source

Or include the source from here.

With Carthage

Carthage

docs

Documentation generated with doxygen http://doxygen.org in the ./MQTTClient/dist/documentation subdirectory.

Here is the PDF.

You may open the HTML version of the documentation here index.html

Run make install in the ./MQTTClient/dist/documentation/html subdirectory to install the the documentation as a DOCSET on your Mac.

Usage

Create a new client and connect to a broker:

#import "MQTTClient.h"

\@interface MyDelegate : ... <MQTTSessionDelegate>
...

        MQTTCFSocketTransport *transport = [[MQTTCFSocketTransport alloc] init];
        transport.host = @"localhost";
        transport.port = 1883;

        MQTTSession *session = [[MQTTSession alloc] init];
        session.transport = transport;
        
	session.delegate = self;

	[session connectAndWaitTimeout:30];  //this is part of the synchronous API

Subscribe to a topic:

[session subscribeToTopic:@"example/#" atLevel:2 subscribeHandler:^(NSError *error, NSArray<NSNumber *> *gQoss){
    if (error) {
        NSLog(@"Subscription failed %@", error.localizedDescription);
    } else {
        NSLog(@"Subscription sucessfull! Granted Qos: %@", gQoss);
    }
 }]; // this is part of the block API

Add the following to receive messages for the subscribed topics

 - (void)newMessage:(MQTTSession *)session
	data:(NSData *)data
	onTopic:(NSString *)topic
	qos:(MQTTQosLevel)qos
	retained:(BOOL)retained
	mid:(unsigned int)mid {
	// this is one of the delegate callbacks
}

Publish a message to a topic:

[session publishAndWaitData:data
                    onTopic:@"topic"
                     retain:NO
	                qos:MQTTQosLevelAtLeastOnce]; // this is part of the asynchronous API

Comparison MQTT Clients for iOS (incomplete)

Wrapper --- ---- MQTTKit Marquette Moscapsule Musqueteer MQTT-Client MqttSDK CocoaMQTT
Obj-C Obj-C Swift Obj-C Obj-C Obj-C Swift
Library IBM Paho Mosquitto Mosquitto Mosquitto Mosquitto native native native

mqtt-client-framework's People

Contributors

ckrey avatar kirillyakimovich avatar bobwenx avatar jakesc avatar jcavar avatar matsukaz avatar e1t0n avatar ogres avatar anagromataf avatar rndmtsk avatar cooperrs avatar mycoboco avatar felixlam avatar devashishmamgain avatar carllee avatar aterribili avatar lilhinx avatar danielevans avatar iyuna avatar marotan3 avatar mark2b avatar rift-walker avatar omidid avatar tetriscode avatar kirang89 avatar leimingdu avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.