Coder Social home page Coder Social logo

arcoirislabs / cordova-plugin-mqtt Goto Github PK

View Code? Open in Web Editor NEW
85.0 9.0 49.0 125 KB

MqTT Cordova Plugin for Apache Cordova (> v3.0)

License: MIT License

Java 15.19% HTML 1.67% JavaScript 19.20% Objective-C 0.66% C 63.28%
cordova mqtt-cordova-plugin wildcard topics

cordova-plugin-mqtt's Introduction

cordova-plugin-mqtt

npm version Join the chat at https://gitter.im/arcoirislabs/cordova-plugin-mqtt

Important Notice

This project is not abandoned or inactive. On 20th Feb 2019, major updates will be pushed.

Updates:

  1. Native Support for iOS & Windows (UWP only)
  2. New API
  3. SSL/TLS support on Android, iOS & Windows
  4. Better config validation.
  5. Resolution of bugs

cordova-plugin-mqtt is plugin for building MQTT client for multiple platforms in Apache Cordova. Currently Android platform is present and next support is planned for iOS & Windows Phone.

Cordova platform support

5.x (CLI) 4.x (Cordova Android) & above.

Note

From v0.3.x, the eventListner implementation shall be deprecated. Kindly take a note of this.

Installation

Install plugins via plugin repository or GitHub

$ cordova plugin add cordova-plugin-mqtt
$ cordova plugin add https://github.com/arcoirislabs/cordova-plugin-mqtt.git

Changelog

  1. Adding temporary support to iOS platform until a stable native support arrives.

Documentation

[UPDATE]

We have written a tutorial for this plugin over here. Kindly check out before you start developing. Cheers

Methods
  1. connect
  2. publish
  3. subscribe
  4. unsubscribe
  5. disconnect
  6. router
  7. listen
Events

Default listeners you can program anywhere for following events

  • connected
  • disconnected
  • failure (connection)
  • subscribed
  • not subscribed
  • published
  • not published

For example you can configure the event in this way

//Deprecated
document.addEventListener("connected",function(e){
 console.log(e.type)
},false)
connect

To connect to a broker. This plugin doesn't supports mqtt:// protocol. Use tcp:// instead.

cordova.plugins.CordovaMqTTPlugin.connect({
    url:"tcp://test.mosquitto.org", //a public broker used for testing purposes only. Try using a self hosted broker for production.
    port:1883,
    clientId:"YOUR_USER_ID_LESS_THAN_24_CHARS",
    connectionTimeout:3000,
    willTopicConfig:{
        qos:0, //default is 0
        retain:true, //default is true
        topic:"<will topic>",
        payload:"<will topic message>"
    },
    username:"uname",
    password:'pass',
    keepAlive:60,
    isBinaryPayload: false, //setting this 'true' will make plugin treat all data as binary and emit ArrayBuffer instead of string on events
    success:function(s){
        console.log("connect success");
    },
    error:function(e){
        console.log("connect error");
    },
    onConnectionLost:function (){
        console.log("disconnect");
    },
    routerConfig:{
        router:routerObject //instantiated router object
        publishMethod:"emit", //refer your custom router documentation to get the emitter/publishing function name. The parameter should be a string and not a function.
        useDefaultRouter:false //Set false to use your own topic router implementation. Set true to use the stock topic router implemented in the plugin.
    }
})
publish

To publish to a channel. You can use this function.

cordova.plugins.CordovaMqTTPlugin.publish({
   topic:"sampletopic",
   payload:"hello from the plugin",
   qos:0,
   retain:false,
   success:function(s){

   },
   error:function(e){

   }
})

In order to debug the publish call you can either go for callbacks in the function or events. Once published the function will call the "published" event & the success callback else the function will call both "not published" event & error callback.

subscribe

To subscribe to a channel. You can use this function. You can also use wildcard based subscription using following ways

//Simple subscribe
cordova.plugins.CordovaMqTTPlugin.subscribe({
   topic:"sampletopic",
   qos:0,
  success:function(s){

  },
  error:function(e){

  }
});

//Single level wildcard subscribe
cordova.plugins.CordovaMqTTPlugin.subscribe({
   topic:"/+/sampletopic",
   qos:0,
  success:function(s){

  },
  error:function(e){

  }
});

//multi level wildcard subscribe
cordova.plugins.CordovaMqTTPlugin.subscribe({
   topic:"/sampletopic/#",
   qos:0,
  success:function(s){

  },
  error:function(e){

  }
});

//Using both kinds of wildcards

cordova.plugins.CordovaMqTTPlugin.subscribe({
   topic:"/+/sampletopic/#",
   qos:0,
  success:function(s){

  },
  error:function(e){

  }
})

The success callback can notify you once you are successfully subscribed, so it will be called only once. The onPublish method is deprecated. If you want to read the payload, you can listen to the event by the name of the topic. For example if you have subscribed to the topic called "sampletopic". You can read the payload in this way.

#####Update:- We are introducing topic pattern support to listen to certain topics in a way the developer wishes to. This topic pattern helps developer to make a common listener to different topics sharing same levels using single and multi-level wildcards.

 //Deprecated
 document.addEventListener("sampletopic",function(e){
  console.log(e.payload)
 },false);

 //New way to listen to topics
 cordova.plugins.CordovaMqTTPlugin.listen("/topic/+singlewc/#multiwc",function(payload,params){
  //Callback:- (If the user has published to /topic/room/hall)
  //payload : contains payload data
  //params : {singlewc:room,multiwc:hall}
})
unsubscribe

To unsubscribe to a channel. You can use this function.

cordova.plugins.CordovaMqTTPlugin.unsubscribe({
   topic:"sampletopic",
  success:function(s){

  },
  error:function(e){

  }
})

This function will also fire the unsubscribe event which yiu can listen to using the document.addEventListener function. Also the event listener for the topic is removed automatically once the client successfully unsubscibes.

disconnect

To disconnect yourself from a server, use following function

cordova.plugins.CordovaMqTTPlugin.disconnect({
  success:function(s){

  },
  error:function(e){

  }
})
router

This function provides you the access to all the topic router functions you have used. If you have used a the stock topic router you can access the payload for a topic by this method.

//Declare this function in any scope to access the router function "on" to receive the payload for certain topic
cordova.plugins.CordovaMqTTPlugin.router.on("/topic/+singlewc/#multiwc",function(payload,params){
  //Callback:- (If the user has published to /topic/room/hall)
  //payload : contains payload data
  //params : {singlewc:room,multiwc:hall}
});

//To get a callback on topic subscribe/unsubscribe event, you can listen by this method
cordova.plugins.CordovaMqTTPlugin.router.onadd(function(topic){

});
cordova.plugins.CordovaMqTTPlugin.router.onremove(function(topic){

});
listen

This function lets you listen to certain topic pattern specifically constructed by topic patters as shown below.

//Declare this function in any scope to access the router function "on" to receive the payload for certain topic
cordova.plugins.CordovaMqTTPlugin.listen("/topic/+singlewc/#multiwc",function(payload,params){
  //Callback:- (If the user has published to /topic/room/hall)
  //payload : contains payload data
  //params : {singlewc:room,multiwc:hall}
});

Todos

  • Add a stable iOS support in v0.3.0
  • Plan support for new platform (Windows Phone)
  • Add background service support in Android version to save the payload related from certain topics in a DB when the app is in background.

License

MIT

cordova-plugin-mqtt's People

Contributors

4refr0nt avatar ameykshirsagar avatar arcoirislabs avatar gitter-badger avatar uprtdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-mqtt's Issues

clean session flag support?

Is this flag supported? I could connect to a broker with RETAIN MSG support but only receiving latest message. I would like to get all the queued messages..

Thanks

MQTT serverConnection lost

MQTT plugin suddenly disconnects and when tried to reconnect back it shows the error:
Error while connecting to MQTT serverConnection lost (32109) - java.net.SocketException: Software caused connection abort.
This happens very often. Is there any fix for this?

Publish function sometimes retain false, sometimes true

Hi everybody, I'm using this great plugin and I create a function to send message.

function mqttSend(thisTopic,thisPayload,callback){

cordova.plugins.CordovaMqTTPlugin.publish({
   topic:thisTopic,
   payload:thisPayload,
   qos:0,
   retain:false,
   success:function(s){	   	
   	console.log("Mqtt send OK");
   	if(callback!==undefined){
   		callback(1);
   	}
   },
   error:function(e){
   	console.log("Mqtt send error");
   	console.log(e);
   	callback(-1);
   }
})

}

If I check the logs on the server that receives the messages it tells me some sendings are with retain false and others with retail true but the function is always the same.

Has anyone encountered the same problem?

Thanks!

It star give error on visual studio

Severity Rating Code Description Project File Trace Concealment Status
Warning Apache Cordova applications cannot be debugged on Android targets in version configuration or targets running versions under 4.4. For JavaScript console output, see Output window.

Warning An error occurred while trying to add a debugger to the emulator or device. Exception: The program 'C: \ ProgramData \ Microsoft \ AndroidSDK \ 25 \ platform-tools \ adb.exe' failed to start.

Operation is not supported. Unknown error: 0x80070057

Ionic 4- Use Cordova-plugin-mqtt

I'm trying to make an app to allow my phone to subscribe to MQTT topics. So I found your plugin and when I try to use it with Ionic 4 looks like something goes wrong.

I've installed your plugin with this command : ionic cordova plugin add cordova-plugin-mqtt
When I try to use it :
import {CordovaMqTTPlugin} from 'cordova-plugin-mqtt';

I've got this issue : "Cannot find module 'cordova-plugin-mqtt' "

Any suggestions ?

Thank you

Raspberry Pi Broker

WOW... I found my subscribing problem. Maybe you could clarify, that you need to subscribe AND to listen to get the payload... I often tried them "stand-alone" because most of the libaries work like this :S

Running the plugin in background

Hello. First of all, let me say that this plugin is really useful for mobile, since by default, the MQTT protocol has such a low overhead, and prioritizes the battery life of the device.
However, I was wondering if there is any official support for running the plugin in background, and keeping the tcp socket open while the main cordova application is sleeping ?

Also, as a side note, how difficult would be to implement the plugin for IOS ? I understand that there are certain limitation with calling C++ methods ( PAHO MQTT ) from Objective-C ( such as not working over cellular mobile )

Messages listener logic as standart paho.js

At now, we must add listeners to every subscribed topic, but usually, enough one listener for all received messages from all subscibed topics. Also, we can't remove listener (mqtt-emitter not support removeListener) now. If we want receive messages from one topic, then we must:

  • Check existing listeners for prevent dublicates before adding listener (and after reconnecting too).
  • Add listener
  • Subscribe

Easy way, may be: we subscribing to some topics (may be wildcard) and receive all messages from subscribed topics by one listener onMessageArrived (as paho.js cb onMessageArrived). After unsubscribing, this listener will not receive messages from unsubsribed topics, but receive from subscribed.

I'm use this method on version 0.2.7 cordova-plugin-mqtt by replacing cordova.fireDocumentEvent(cd.topic,cd); to cordova.fireDocumentEvent("onMessageArrived",cd); and receiving all messages, include subscribed wildcards topics too (prefix/+/+/suffix , prefix/# and other) by one listener without thinking about other listeners.

SSL Support?

Hi,

What are the blockers to support SSL encryption for all communications?

Installation error

Hi... I am trying to install this plugin in Intel XDk. I was not able to install it. Have you seen any issue with installation in XDK before

Thanks,
Mallik

paho not defined

Paho not defined error when using connect function. The error message points to cordova-plugin-mqtt.js at line 110 "client = new Paho.MQTT.Client(args.url.split("tcp://")[1], Number(args.wsPort), args.urlPath||"/ws", args.clientId);".

Is this a known error? Am I doing something wrong?

Thanks in advance!

Why was onPublish removed?

I'm worried that MQTT events could easily interfere with regular DOM events and mess things up. As well, it means that cleaning up connections is more prone to memory leaks.

Not subscribes

Hi
try to run demo app
successfully connect to test.mosquitto.org: 1883
also successfully publish

but when subscribe - there is no reactions for subscribed topics

in Adnroid studio i get this, when publish to subscribed topics:

I/mqttalabs: for subscribe the callback id is CordovaMqTTPlugin126837709

Stop Listen (Un-Listen) to a topic without disconnect

Hello all,

I want to ask about: how to stop Listen (Un-Listen) to a topic without disconnecting from the server?

I've tried to Unsubscribe the topic, but the 'Listen' function is not destroyed,
so when I Subscribe to the same topic again, I have two 'Listen' function listening to the same topic and when a message published into that topic, I got two message from that topic.
What I need is: I can stop the 'Listen' function when i Unsubscribe the topic, and Listen again when i Subscribe the topic.

Thank you!

Publish Message Always Retain?

Hi,
I'm using Cordova for android application.
I'm trying to publish messages without retain flag, but seem my message always sent with retain feature.
Please let me know what is wrong with my code, below code is my publish function:

document.getElementById("id_btn_mqtt_publish").addEventListener('touchend', function (e) {
            try {
                if (mqtt_connect_flag) {
                    mqtt_publish_topic = document.getElementById("id_mqtt_publish_topic").value;
                    mqtt_publish_message = document.getElementById("id_mqtt_message").value;
                    mqtt_publish_setting =  document.getElementById("id_setting_message").checked

                    if ((mqtt_publish_topic != "") && ( mqtt_publish_message != ""))
                    {
                        var mqtt_message;
                        if(mqtt_publish_setting)
                        {
                            mqtt_message =  "\r\n" + mqtt_publish_message + "\r\n";
                        }
                        else
                        {
                            mqtt_message = mqtt_publish_message;
                        }
                        cordova.plugins.CordovaMqTTPlugin.publish({
                            topic: mqtt_publish_topic,
                            payload: mqtt_message,
                            qos: 1,
                            retain: false,
                            success: function (s) {
                                swal("MQTT Success", "MQTT publish success: " + s, "success");
                            },
                            error: function (e) {
                                swal("MQTT Failed", "Publish failed: " + e, "error");
                            }
                        });
                    }
                    else {
                        if (mqtt_publish_topic == "")
                            swal("MQTT Error", "Please type a topic name !", "error");
                        else if(mqtt_publish_message == "")
                            swal("MQTT Error", "Please type message to send !", "error");
                    }
                }
                else {
                    swal("MQTT Error", "Please connect to broker before publish", "error");
                    document.getElementById("id_btn_mqtt_connect").innerText = "Connect";
                }
            } catch (e) {
                swal("MQTT Error", "Error: " + e, "error");
            }
        }); 

Client ID register as "null" by broker

Hi

After test (running mosquitto broker in verbose mode), I discover that whatever I set as clientId, the broker don't receive ID client and set it as "null".

this is a big issue if two or more tablet run the application : broker can't have client with same ID (ie "null").

Did someone find a solution to solve it ??

thanks in advance

Arguments checking

Please, add range checking to JS part for preventing app crashes.

java.lang.IllegalArgumentException: Invalid topic length, should be in range[1, 65535]!
    at org.eclipse.paho.client.mqttv3.MqttTopic.validate(MqttTopic.java:158)
    at org.eclipse.paho.client.mqttv3.MqttAsyncClient.subscribe(MqttAsyncClient.java:823)
    at org.eclipse.paho.client.mqttv3.MqttAsyncClient.subscribe(MqttAsyncClient.java:783)
    at com.arcoirislabs.plugin.mqtt.CordovaMqTTPlugin.subscribe(CordovaMqTTPlugin.java:273)
    at com.arcoirislabs.plugin.mqtt.CordovaMqTTPlugin.access$200(CordovaMqTTPlugin.java:24)
    at com.arcoirislabs.plugin.mqtt.CordovaMqTTPlugin$3.run(CordovaMqTTPlugin.java:76)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5264)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)

No javascript work with the plugin

Hey, i have try to use your plugin for test but i did not succeed to etablish any connection to my mosquitto server. I have install the plugin with
cordova plugin add https://github.com/arcoirislabs/cordova-plugin-mqtt.git

and use this code:

<script>
        cordova.plugins.CordovaMqTTPlugin.connect({
            url:"tcp://192.168.1.11",
            port:1883,
            clientId:"",
            connectionTimeout:3000,
            willTopicConfig:{
                qos:0,
                retain:true,
                topic:"remote",
                payload:"test"
            },
            username:"remote",
            password:'test',
            keepAlive:60,
            success:function(s){
                alert("connect success");
            },
            error:function(e){
                alert("connect error");
            },
            onConnectionLost:function (){
                alert("disconnect");
            }
        })

        cordova.plugins.CordovaMqTTPlugin.publish({
           topic:"remote",
           payload:"hello from the plugin",
           qos:0,
           retain:false
          success:function(s){

          },
          error:function(e){

          }
        })
    </script> 

When i launch my app with your plugin no javascript script work.

Thx in advance

QoS selection support

Actually plugin seems to use QoS 1 without any possibility to change it. It could be great to let user to select QoS.

Background Instance

Hey there

In the notes you guys said you were working on background stuff. Have you finished that yet.
I would love to do some stuff with the background part and this plugin is what I need

Subscribe to multiple topics.

Hi all. I've just downloaded your plugin and wanted to sy that it's working nicely and is quite well documented.
There is however a missing information in the examples. Can somebody provide en example how to subscribe to multiple topics at the same time in one broker? I hope it is possible to subscribe to two topics simultaneously (i.e. without a need to unscubscribe from first and then subscribing to second).
Thanks!

When subscribe ,error: java.lang.NullPointerException

my code is

 cordova.plugins.CordovaMqTTPlugin.subscribe({
            topic: "vip/shop/" + newValue + "/personInfo",
            qos: 0,
            success: function (s) {
            },
            error: function (e) {
            }
          });

but it comes to an error:

java.lang.NullPointerException: Attempt to invoke virtual method 'org.eclipse.paho.client.mqttv3.IMqttToken org.eclipse.paho.client.mqttv3.MqttAsyncClient.subscribe(java.lang.String, int, java.lang.Object, org.eclipse.paho.client.mqttv3.IMqttActionListener)' on a null object reference
07-15 14:40:00.078  4535  4535 E AndroidRuntime: 	at com.arcoirislabs.plugin.mqtt.CordovaMqTTPlugin.subscribe(CordovaMqTTPlugin.java:273)
07-15 14:40:00.078  4535  4535 E AndroidRuntime: 	at com.arcoirislabs.plugin.mqtt.CordovaMqTTPlugin.access$200(CordovaMqTTPlugin.java:24)
07-15 14:40:00.078  4535  4535 E AndroidRuntime: 	at com.arcoirislabs.plugin.mqtt.CordovaMqTTPlugin$3.run(CordovaMqTTPlugin.java:76)
07-15 14:40:00.078  4535  4535 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:754)
07-15 14:40:00.078  4535  4535 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:95)
07-15 14:40:00.078  4535  4535 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:160)
07-15 14:40:00.078  4535  4535 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:6200)
07-15 14:40:00.078  4535  4535 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
07-15 14:40:00.078  4535  4535 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
07-15 14:40:00.078  4535  4535 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)

args.success is not a function

Have a problem with that error, as after few minutes it forcing my whole app to crash.
Usually, error appears on 96 line of cordova-plugin-mqtt.js and 312 line of cordova.js

Attempted to send a second callback for ID

I'm using the plugin in an ionic project with angularjs
I'm trying to use the plugin's subscribe method subscribe to multiple topics like code below.
The result is only one of element in array $scope.gateInfo can successfully subscribe to the topic and I found the error message in logcat which says :
W/CordovaPlugin: Attempted to send a second callback for ID: CordovaMqTTPlugin592666074
After some searching I found that to eliminate this error request plugin support asynchronous communication between javascript and plugin. Is it true? Any ideas are welcome.

var mqttSetupSubscribe = function(){
    var arr = [];
    for (var i = $scope.gateInfo.length - 1; i >= 0; i--) {
        arr.push(mqttSubscribe(i));
    }
    return $q.all(arr);
}

var mqttSubscribe = function(index){
    var defer = $q.defer();
    var subTopic = mqttSubDevInfo + $scope.gateInfo[index].serial;

        cordova.plugins.CordovaMqTTPlugin.subscribe({
        topic: subTopic,
        qos:0,
        success:function(s){
            cordova.plugins.CordovaMqTTPlugin.listen(subTopic, 
                function (payload, params, topic, topic_pattern) {
              alert(JSON.stringify(payload));
            });
            defer.resolve();
        },
        error:function(e){
            defer.reject();
        }
        });
    return defer.promise;
}

//
mqttSetupSubscribe().then(function(){
alert("done");
})

SSL/TLS

Hi,
I would just like to know whether SSL/TLS is already implemented or it is rather an announcement?

SSL/TLS support on Android, iOS & Windows

thank You
max

I have a probelm MQTT Plugin is not working

Hi, there
I tried few days ago this plugin with cordova but it is not get working
can you please do example to me for connect and publish
all your efforts are appreciated

Major updates Feb 2019

This project is not abandoned or inactive. On 20th Feb 2019, major updates will be pushed.

Is this coming anytime soon? Thanks

How know if connection is alive

I want to know if the plugin has policies of reconnections and if possible know the status of connections (alive or died).

Thanks in advance

I need help, I don't know how to make it work

Hello,

I'm using this plugin with Ionic to make a Mqtt app on a smartphone.

I'm trying to listen to a topic and see the content of it on my phone.

This is what I did :

import { Component} from '@angular/core';
import { NavController,NavParams } from 'ionic-angular';
import {Observable} from 'rxjs/Observable';
import {Platform} from 'ionic-angular';


@Component({
  selector: 'page-mypage',
  templateUrl: 'mypage.html'
})
export class MyPage{
	
  txt1:string="?";
  txt2:string="?";
  txt3:string="?";

  constructor(public navCtrl: NavController, public navParams: NavParams, platform: Platform) {

    platform.ready().then(() => {
      //console.dir(window);
      this.connectMQTT();
    });
    
  }
  
  public connectMQTT(){
    console.log("connecting...");
    var root = this;
    (<any>window).cordova.plugins.CordovaMqTTPlugin.connect({
        url:"tcp://192.168.4.1",
        port:1883,
        clientId:"client1",
        connectionTimeout:3000,
        willTopicConfig:{
          qos:0,
          retain: true,
          topic:"<will topic>",
          payload:"<will topic message>"
        },
        username:"uname",
        password:'pass',
        keepAlive:60,
        success:function(s){
          console.log("Connecté");

          (<any>window).cordova.plugins.CordovaMqTTPlugin.listen("/Server/led",function(payload,params){
            root.txt2= payload;
          });

        },
        error:function(e){
          console.log("connect failed : "+e);
          root.connectMQTT();
        },
        onConnectionLost:function (){
          console.log("disconnect");
          root.connectMQTT();
        }
      });
  }

}

This code is not working, it's always losing the connection (printing "disconnect").

Thank you for your time, I hope you can help me

Can't open mqtt reconnect function

author use paho.mqtt.java library, this library support reconnect flag.
just
connOpts.setAutomaticReconnect(true)
paho.mqtt.java library default automaticReconnect = false

Cant install cordova plugin

Hello, i cant install your plugin.

$ cordova plugin add com.arcoirislabs.plugin.mqtt
Fetching plugin "com.arcoirislabs.plugin.mqtt" via plugin registry
Installing "com.arcoirislabs.plugin.mqtt" for android
Error during processing of action! Attempting to revert...
Failed to install 'com.arcoirislabs.plugin.mqtt':Error: Uh oh!
"d:\DEV\proj\WEB_MOBILITY\demoAc\plugins\com.arcoirislabs.plugin.mqtt\src\a
ndroid\Mqtt.java" not found!
at Object.module.exports.common.copyFile (c:\npm\node_modules\cordova\node_m
odules\cordova-lib\src\plugman\platforms\common.js:43:40)
at Object.module.exports.common.copyNewFile (c:\npm\node_modules\cordova\nod
e_modules\cordova-lib\src\plugman\platforms\common.js:60:16)
at module.exports.source-file.install (c:\npm\node_modules\cordova\node_modu
les\cordova-lib\src\plugman\platforms\android.js:51:20)
at Object.ActionStack.process (c:\npm\node_modules\cordova\node_modules\cord
ova-lib\src\plugman\util\action-stack.js:70:25)
at handleInstall (c:\npm\node_modules\cordova\node_modules\cordova-lib\src\p
lugman\install.js:560:20)
at c:\npm\node_modules\cordova\node_modules\cordova-lib\src\plugman\install.
js:320:20
at _fulfilled (c:\npm\node_modules\cordova\node_modules\q\q.js:798:54)
at self.promiseDispatch.done (c:\npm\node_modules\cordova\node_modules\q\q.j
s:827:30)
at Promise.promise.promiseDispatch (c:\npm\node_modules\cordova\node_modules
\q\q.js:760:13)
at c:\npm\node_modules\cordova\node_modules\q\q.js:574:44
Error: Uh oh!
"d:\DEV\proj\WEB_MOBILITY\demoAc\plugins\com.arcoirislabs.plugin.mqtt\src\a
ndroid\Mqtt.java" not found!
at Object.module.exports.common.copyFile (c:\npm\node_modules\cordova\node_m
odules\cordova-lib\src\plugman\platforms\common.js:43:40)
at Object.module.exports.common.copyNewFile (c:\npm\node_modules\cordova\nod
e_modules\cordova-lib\src\plugman\platforms\common.js:60:16)
at module.exports.source-file.install (c:\npm\node_modules\cordova\node_modu
les\cordova-lib\src\plugman\platforms\android.js:51:20)
at Object.ActionStack.process (c:\npm\node_modules\cordova\node_modules\cord
ova-lib\src\plugman\util\action-stack.js:70:25)
at handleInstall (c:\npm\node_modules\cordova\node_modules\cordova-lib\src\p
lugman\install.js:560:20)
at c:\npm\node_modules\cordova\node_modules\cordova-lib\src\plugman\install.
js:320:20
at _fulfilled (c:\npm\node_modules\cordova\node_modules\q\q.js:798:54)
at self.promiseDispatch.done (c:\npm\node_modules\cordova\node_modules\q\q.j
s:827:30)
at Promise.promise.promiseDispatch (c:\npm\node_modules\cordova\node_modules
\q\q.js:760:13)
at c:\npm\node_modules\cordova\node_modules\q\q.js:574:44

Failed to connect

Please help me with the following:
I use https://build.phonegap.com to build your sampleapp. I tried to connect to tcp://test.mosquitto.org port 1883, but I received --> You got `disconnected and never succed to connect.

Config.xml is:

<?xml version="1.0" encoding="UTF-8"?>
    <widget xmlns  = "http://www.w3.org/ns/widgets"
        xmlns:gap     = "http://phonegap.com/ns/1.0"
        id                   = "com.phonegap.example"
        versionCode = "10" 
        version     = "1.0.0" >
    <name>Test</name>
    <platform name="android" />
    <description>Test</description>
    <preference name="android-build-tool" value="gradle" /> 
    <gap:plugin name="cordova-plugin-mqtt" spec="0.2.7" source="npm" />

    <preference name="phonegap-version" value="cli-5.2.0" />
    <preference name="orientation"      value="default" />
    <preference name="target-device"    value="universal" />
    <preference name="fullscreen"       value="false" />
    <preference name="webviewbounce"    value="false" />
</widget>

Arguments checking bug

If you pass retain = false when publish, then retain is true.
Disabling retain flag only if retain option is undefined

                var options = {}
                options.topic = topic;
                options.payload = msg;
                options.qos = 0;
                options.retain = false;
                options.success = function() {};
                options.error = function() {};

                cordova.plugins.CordovaMqTTPlugin.publish(options)

Intent Service

Hi There

I would like to use this as my messaging platform so I can do and send data to the device as well as create and manage push notifications myself.

Do you have example code on how I can set this up as an intent service like firebase on android and ios?

Thanks

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.