@danielr1996/ng-mqtt

1.0.0 • Public • Published

ng-mqtt is an rxjs based Angular wrapper for the JS Eclipse Paho MQTT library

Usage

  • Install with npm install @danielr1996/ng-mqtt
  • Include <script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js" type="text/javascript"></script> in your index.html
import {INgMqtt, NgMqtt} from 'ng-mqtt/ng-mqtt';

class Usage {
    private client: INgMqtt = new NgMqtt();
    this.client.connect('mqtt.danielr1996.de', 1884, 'client').subscribe(()=>{
        console.log('Connected');
        
        this.client.subscribe('#').subscribe(msg => {
            console.log('Message Received', msg);
        });
        
        this.client.send('<topic>', '<message>');
    });
    
}

API

export interface INgMqtt {
    connect(host: string, port: number, clientId: string): Observable<void>;

    subscribe(topic: string): Observable<string>;

    send(topic: string, message: Paho.MQTT.Message | string): void;
}

Readme

Keywords

Package Sidebar

Install

npm i @danielr1996/ng-mqtt

Weekly Downloads

0

Version

1.0.0

License

WTFPL

Last publish

Collaborators

  • danielr1996