Giter Club home page Giter Club logo

mqtt-cordova's Introduction

mqtt-cordova

MQTT Plugin for Cordova

This is a plugin for MQTT protocol of messaging. Currently Android is supported. Forthcoming support for Windows Phone. More features are stil being developed.

Features

This plugin can publish and subscribe for any MQTT server. Currently it works only for compulsory authentication. to add the plugin

Usage

You can use the following functions after onDeviceReady was triggered. Use connect() before any other functions.

mqtt.connect({
    url: "tcp://m2m.eclipse.org:1883",
    clientId: "SampleJavaV3_",
    success: function (subscribedTopicsString) {
        alert('success: ' + subscribedTopicsString);
    },
    error: function (message) {
         alert('error:' + message);
    }    
	cleanSession: true/false, // optional
});

To publish a message you can use this function. It should be used after connect() was succesful, maybe use the corresponding callback of the latter.

mqtt.publish({
    topic: "topic",
    qos: "2",
    message: "Howzaaa",
	username:"",
	password:"",
	debug:true/false,
    success: function (data){
        alert(data);
    },
    error: function (data){
         alert(data);
    }
});

To subscribe you can use this function. This is not tested yet and you will likely have to work on MQTTPlugin.java yourself

mqtt.subscribe({
	topic:"",
	qos:"",
	username:"",
	password:"",
	debug:true/false,
	success:function (data) {},
	error:function (data) {}
});

Building

This plugin makes use of the Android Service lib org.eclipse.paho.android.service. An App which uses this service must include the appropriate service tag in its manifest - e.g.

<!-- Mqtt Service -->
<service android:name="org.eclipse.paho.android.service.MqttService" />

This might be added by Cordova automatically through this repository's plugin.xml specification.

Add "Android Support Repository" through the Standalone Android SDK Manager in Android Studio.

Then add the following line to your dependencies in the build.gradle file of the Android Module, not in CordovaLib. It's likely that the specified version is not the only one that's working, but that's not tested.

compile "com.android.support:support-v4:22.2.+"

Created and maintained by Arcoiris Labs

Have fun!

Released under Apache 2.0 Licence

mqtt-cordova's People

Contributors

bogn avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

goalryan askie

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.