1.0.0 • Published 7 years ago

@danielr1996/ng-mqtt v1.0.0

Weekly downloads
1
License
WTFPL
Repository
gitlab
Last release
7 years ago

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;
}
1.0.0

7 years ago