GithubHelp home page GithubHelp logo

kryndex / swiftmqtt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aciidb0mb3r/swiftmqtt

0.0 2.0 0.0 3.56 MB

MQTT Client in pure swift ❤️

License: MIT License

Ruby 1.88% Swift 96.87% Objective-C 1.24%

swiftmqtt's Introduction

SwiftMQTT

MQTT Client in pure Swift ❤️

Build Status Version License

Info

Sample Project Screenshot

How to use

Create Session

mqttSession = MQTTSession(host: "localhost", port: 1883, clientID: "swift", cleanSession: true, keepAlive: 15, useSSL: false)

Connect

mqttSession.connect { (succeeded, error) -> Void in
  if succeeded {
    print("Connected!")
  }
}

Subscribe

mqttSession.subscribe(to: "/hey/cool", delivering: .atLeastOnce) { (succeeded, error) -> Void in
 if succeeded {
    print("Subscribed!")
  }
}

Unsubscribe

 mqttSession.unSubscribe(from: ["/ok/cool", "/no/ok"]) { (succeeded, error) -> Void in
  if succeeded {
    print("unSubscribed!")
  }
}

Publish

let jsonDict = ["hey" : "sup"]
let data = try! JSONSerialization.data(withJSONObject: jsonDict, options: .prettyPrinted)

mqttSession.publish(data, in: "/hey/wassap", delivering: .atLeastOnce, retain: false) { (succeeded, error) -> Void in
  if succeeded {
    print("Published!")
  }
}

Conform to MQTTSessionDelegate to receive messages

mqttSession.delegate = self
func mqttSession(session: MQTTSession, received message: Data, in topic: String) {
	let string = String(data: message, encoding: .utf8)!
}

Installation

CocoaPods

Install using CocoaPods by adding the following lines to your Podfile:

use_frameworks!
pod 'SwiftMQTT'  

License

MIT

swiftmqtt's People

Contributors

aciidb0mb3r avatar f2m2rd avatar paulw11 avatar

Watchers

 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.