Coder Social home page Coder Social logo

Comments (3)

arcoirislabs avatar arcoirislabs commented on August 22, 2024

Well it won't work unless you call it after the 'deviceready' event is called from cordova library.
Also you cannot publish unless the connection to the broker is successfully established.
Have you called it after the 'deviceready' event is triggered??

from cordova-plugin-mqtt.

celianvdb avatar celianvdb commented on August 22, 2024

I have try it

// Wait for device API libraries to load
    //
    function onLoad() {
        document.addEventListener("deviceready", onDeviceReady, false);
    }

    // device APIs are available
    //
    function onDeviceReady() {
        cordova.plugins.CordovaMqTTPlugin.connect({
            url:"tcp://192.168.1.26",
            port:1883,
            clientId:"",
            connectionTimeout:3000,
            willTopicConfig:{
                qos:0,
                retain:true,
                topic:"remote",
                payload:"test"
            },
            username:"remote",
            password:"remote",
            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){

          }
        })
    }

But i have the same problem :'(

from cordova-plugin-mqtt.

arcoirislabs avatar arcoirislabs commented on August 22, 2024

Have you tried to connect to a public broker?? Because it looks like you are connecting to a locally hosted server from your app. Can you check your server's firewall settings. Maybe it is not allowing the connection.
We have never faced such problem in our production apps.

Suggestions to debug:-

  1. Read the error dump from the error callback in the connect function. There you will exactly know the what is wrong.
  2. Your publish function should be called from inside the success callback.

from cordova-plugin-mqtt.

Related Issues (20)

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.