I need to use publish Subscribe methods in my Ionic 3 application.
I followed this page.
Is there any way we can link MQTT with our Ionic 3 application? If yes, how so? How exactly do I need to go about it for a successful connection?
I installed ng2-mqtt
service using
npm install ng2-mqtt --save
This is my code:
index.html
<script src="cordova.js"></script>
<script src="node_modules/ng2-mqtt/mqttws31.js" type="text/javascript"></script>
home.ts
import {Paho} from 'mqttws31'
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
private _client: Paho.MQTT.Client;
constructor(public paho: Paho) {
}
this._client = new Paho.MQTT.Client("52.66.30.178", 1883, "path", "someclient_id");
this._client.onConnectionLost = (responseObject: Object) => {
console.log('Connection lost.');
this.getServerMessage();
this._client.onMessageArrived = (message: Paho.MQTT.Message) => {
console.log('Message arrived.');
};
this._client.connect({ onSuccess: this.onConnected.bind(this); });
}
Still I can't get it to work.
Any suggestions and changes will help me. I'm stuck please do.