iT邦幫忙

0

ionic3 MQTT

想問一下有人有在ionic3 使用過MQTT嗎?
我照google爬文上寫得做,可是在onSuccess後不會respones?
不知道是什麼原因,有做過MQTT的人可以分享教學嗎,感激不盡~

以下是我寫的程式碼
想寫一個servise 可以做DI,然後功能只有兩個按鈕,subscribe & unsubscribe ,訂閱時做function connect()

import { Injectable } from '@angular/core';
import { Paho } from 'ng2-mqtt/mqttws31';
import { Observable } from 'rxjs/Observable';

@Injectable()

export class MqttConnection {
  _client;
  constructor() { }
  connect(){
    this._client = new Paho.MQTT.Client("192.168.0.82", 1883,  "hui");   
    this._client.connect({ onSuccess:this.onConnected});
  }
  onConnected() {
    console.log('Connected to broker.');
    this._client.subscribe("KR800");
  }
  onMessage(){  
    this._client.onMessageArrived = (message: Paho.MQTT.Message) => {
      console.log('Message arrived.');
    };
  }
  onConnectionLost(){
    this._client.onConnectionLost = (responseObject: Object) => {
      console.log('Connection lost.');
    };
  }
}
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答