mqtt-extension

1.0.7 • Public • Published

MQTT-EXTENSION


This package is an extension of mqtt to initialice a mqtt broker and extends it's functions.

INSTALLATION


Run on the project folder

npm i mqtt-extension

USAGE


To customize your funtions you can extends the metods:

/**************/
/*    MQTT    */
/**************/

var topics = ['topic1','topic2'];

/* Example for override MQTT functions */
class mqtt extends require('mqtt-extension') {
  onConnectHandler(connack){
    this.subscribe(topics,null, function (err) {
        if (!err) {
            console.log('[MQTT]: Subcription to topic ' + topics);
        } else {
            console.error('[MQTT]: Error to subcribe');
        }
    });
  }

	onMessageRecHandler(topic, message, packet){
		console.log('[MQTT]:' + 'Message Received\n');
		console.log('\t Topic: ' + topic);
		console.log('\t Message: [MQTT-' + message);		
	}
}

mqttBroker = new mqtt (process.env.MQTT_HOST, process.env.MQTT_PORT, process.env.MQTT_OPTIONS).init();

.ENV EXAMPLE
MQTT_HOST='localhost'
MQTT_PORT=1883
MQTT_OPTIONS={
    clean: true,
    clientId: 'mqtt-id',
    keepalive: 6000, 
    username: 'root',
    password: Buffer.from('example'), 
}

License

DEVELOPMENT

TAREAS

  • Definir opciones subcribe publish en el package

References

Readme

Keywords

none

Package Sidebar

Install

npm i mqtt-extension

Weekly Downloads

7

Version

1.0.7

License

ISC

Unpacked Size

8.76 kB

Total Files

5

Last publish

Collaborators

  • salvacnj