arcoirislabs / cordova-plugin-mqtt

MqTT Cordova Plugin for Apache Cordova (> v3.0)
MIT License
86 stars 49 forks source link

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

Closed ghost closed 6 years ago

ghost commented 6 years ago

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

arcoirislabs commented 6 years ago

Hi, Sure we would love to help you here. Have you run the test code ??

On Tue, May 15, 2018, 12:47 PM Alban notifications@github.com wrote:

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; (window).cordova.plugins.CordovaMqTTPlugin.connect({ url:"tcp://192.168.4.1", port:1883, clientId:"client1", connectionTimeout:3000, willTopicConfig:{ qos:0, retain: true, topic:"", payload:"" }, 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

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/arcoirislabs/cordova-plugin-mqtt/issues/39, or mute the thread https://github.com/notifications/unsubscribe-auth/ADE8ZXP_8tSnAQAnBHR8ZVc_GTnAJ969ks5tyoD_gaJpZM4T_AsL .

ghost commented 6 years ago

No I didn't.

Now I did. the test code works fine !

So the problem come from the transition to javaScript to typeScript and/or the transition from Cordova to Ionic+Cordova

ghost commented 6 years ago

Few informations about me and my project :

I'm a total beginner to mobile app development. I was looking for a way to code an app. I found Ionic and it seems good so I chose this way to make app. At this time I didn't know anything in JavaScript/TypeScript , AngularJS and I had a bit of knowledge about HTML/CSS. So I learned TypeScript while making this project and I like the language. But know that I found the Apache/Cordova way to do apps I don't know which one to choose. It seems harder with Apache/Cordova to make "good looking" apps but I'm not afraid by that. I would like to learn JavaScript so if I don't know the language it's not a problem. And I don't know if I'm right but Apache Cordova seems faster ?

Do you have a preference between Ionic/Cordova and Apache/Cordova ? What are the pros and cons ?

If you think that this is not a question to ask here you are not oblige to reply I would understand.

Thank you for your time

arcoirislabs commented 6 years ago

Can you check for the permissions like Internet permission in the AndroidManifest.xml??

On Tue, May 15, 2018, 3:12 PM Alban notifications@github.com wrote:

Few informations about me and my project :

I'm a total beginner to mobile app development. I was looking for a way to code an app. I found Ionic and it seems good so I chose this way to make app. At this time I didn't know anything in JavaScript/TypeScript , AngularJS and I had a bit of knowledge about HTML/CSS. So I learned TypeScript while making this project and I like the language. But know that I found the Apache/Cordova way to do apps I don't know which one to choose. It seems harder with Apache/Cordova to make "good looking" apps but I'm not afraid by that. I would like to learn JavaScript so if I don't know the language it's not a problem. And I don't know if I'm right but Apache Cordova seems faster ?

Do you have a preference between Ionic/Cordova and Apache/Cordova ? What are the pros and cons ?

If you think that this is not a question to ask here you are not oblige to reply I would understand.

Thank you for your time

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/arcoirislabs/cordova-plugin-mqtt/issues/39#issuecomment-389107814, or mute the thread https://github.com/notifications/unsubscribe-auth/ADE8ZaiB2Ghh9R74wFcEbG549DZSdlANks5tyqMegaJpZM4T_AsL .

arcoirislabs commented 6 years ago

Hi Alban, You can certainly make good looking applications in Cordova. Typescript is only useful to learn only if the application development expect of you to do it. Cordova applications can be developed using conventional JavaScript (ES5). We strongly suggest you take small steps starting from using simple frameworks like Framework7. Its a ready made UI framework that works excellent with Cordova. To make aesthetic applications you should have a brief knowledge in CSS3 to ve able to style the applications with minute details. We also encourage you to learn Polymer that follows Web Components specifications as per the web standard. We would strongly suggest you to follow the online tutorials and learn the Cordova inside out clearly. You can freely ask your queries at oss@arcoirislabs.com Cheers

On Tue, May 15, 2018, 3:12 PM Alban notifications@github.com wrote:

Few informations about me and my project :

I'm a total beginner to mobile app development. I was looking for a way to code an app. I found Ionic and it seems good so I chose this way to make app. At this time I didn't know anything in JavaScript/TypeScript , AngularJS and I had a bit of knowledge about HTML/CSS. So I learned TypeScript while making this project and I like the language. But know that I found the Apache/Cordova way to do apps I don't know which one to choose. It seems harder with Apache/Cordova to make "good looking" apps but I'm not afraid by that. I would like to learn JavaScript so if I don't know the language it's not a problem. And I don't know if I'm right but Apache Cordova seems faster ?

Do you have a preference between Ionic/Cordova and Apache/Cordova ? What are the pros and cons ?

If you think that this is not a question to ask here you are not oblige to reply I would understand.

Thank you for your time

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/arcoirislabs/cordova-plugin-mqtt/issues/39#issuecomment-389107814, or mute the thread https://github.com/notifications/unsubscribe-auth/ADE8ZaiB2Ghh9R74wFcEbG549DZSdlANks5tyqMegaJpZM4T_AsL .