How To integrate MQTT in ionic 4 project

Hi All,
how to integrate MQTT in ionic 4 project
i have tried https://www.npmjs.com/package/ngx-mqtt-client but failed
it is showing
ERROR Error: Uncaught (in promise): ReferenceError: global is not defined
i have tried https://stackoverflow.com/questions/50356408/upgrading-to-angular-6-x-gives-uncaught-referenceerror-global-is-not-defined
to fixed this but failed again
please help

thanks in advance

Did you successfully implement this?

Yeah, I have managed that through Web socket

2 Likes

Could you share with us your solution? or you wanna sell it? contact us

sorry for late reply
install mqtt from here https://www.npmjs.com/package/ngx-mqtt-client

in your page.ts

import { ConnectionStatus, MqttService, SubscriptionGrant } from '../../ngx-mqtt-client'; // i have copied this folder to app folder

constructor(private mqttService: MqttService,){}

connectMQTT() {
    this.mqttService.status().subscribe((s: ConnectionStatus) => {
      const status = s === ConnectionStatus.CONNECTED ? 'CONNECTED' : 'DISCONNECTED';
      this.status.push(`Mqtt client connection status: ${status}`);
      console.log(`Mqtt client connection status: ${status}`);
      this.subscribe();
    });
  }