Coder Social home page Coder Social logo

mqtt.dart's Introduction

Mqtt

This is an mqtt client written in DART. It can be used in the browser (over websocket) or the VM (over socker or websocket).

See http://mqtt.org/ for details on mqtt protocol

Usage

Create a connection over websocket: var mqttCnx = new MqttConnectionIOWebSocket.setOptions("ws://127.0.0.1/8080");

Create a connection over socket: var mqttCnx = new MqttConnectionIOSocket.setOptions(host:127.0.0.1, port: 8083);

Create mqtt client: MqttClient c = new MqttClient(mqttCnx, clientID: "MyClientID", qos: QOS_1);

Set a will (must be done before connecting to the broker): c.setWill("MyWillTopic", "MyWillPayload", QOS_1, 0);

Connect to broker: c.connect(onConnectionLost) .then( (c)=> onConnected(c) ) .catchError((e) => print("Error: $e"), test: (e) => e is SocketException)
.catchError((mqttErr) => print("Error: $mqttErr") );

Publish a message: c.publish("MyTopic", "MyMessage", 1, QOS_1, 0) .then( (m) => print("Message ${m.messageID} published"); );

Subscribe to a topic: c.subscribe("MyTopic", QOS_1, onMessage) .then( (s) => print("Subscription done - ID: ${s.messageID} - Qos: ${s.grantedQoS}") );

Unsubscribe: c.unsubscribe("MyTopic", s.messageID) .then( (u) => print("Unsubscribed from subscription ${u.messageID}") );

Disconnect: c.disconnect();

VM Example

See mqtt_sub for a sample mqtt publish and mqtt_pub for a sample subscribe. Available options can be displayed through: > dart mqtt_sub.dart -h > dart mqtt_pub.dart -h

Web Example

See Mqtt_web for a sample web page connecting, subscribing and publishing mqtt messages

Testing

Testing was done using the mosquitto broker (http://mosquitto.org/). A mosquitto test server is available at http://test.mosquitto.org/.

Websocket testing was done throught mqtt_ws_bridge.dart.

mqtt.dart's People

Contributors

jnguillerme avatar ewoutp avatar hecatoncheir avatar

Watchers

James Cloos avatar  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.