This library relies on MQTT.js library for interacting with mqtt server.
npm install resmetry --save
var resmetrylib=;var host='mqtt://localhost';//Standard settings available in npm package mqttvar settings=protocolId: 'MQIsdp'protocolVersion: 3;/*** The last parameter should be true for an always active connection, false for a one time connection* @type*/var resmetry= hostsettingsfalse;/** Get mqtt client for advanced operations, Refer npm package mqtt for more information* For other features offered by MQTT, the modifications can be made using the object* Only applicable true is passed the last parameter of the constructor*///var mqtt=resmetry.getMQTTClient();//MQTT operations//mqtt.subscribe('request/1');//Connection listenerresmetry;//Message event listenervar temp=25;resmetry;//Making a request to topic 'request' with message 'send me details' whose expected result goes to topic response with optionsvar options=qos:2;//Options are standard options available for publishing in npm package mqttresmetry;
Connected Topic: request/1 Message: temp Topic: response/1 Message: 25 Response:25
Connects to the broker specified by the given url and options and ted options. Options are as mentioned in connect part of npm package mqtt.js ConnectionType specifies whether current operation is one-time or continuous. One-time activated by passing false, makes the connection end after obtaining the response. Whereas, continuous operation mode activated by passing true, runs forever.
- 'topic' is the topic to which message will be send to.[Like request]
- 'data' is the message which needs to be passed along with request
- 'options' are additional options like qos and retain features. Refer npm package mqtt.js publish
- 'responseTopic' is the the topic to which response will be send to[Like response]
- 'callback' is where any err or result will be passed
Returns the mqtt client for the functionality of add your listeners other than 'message' event.Refer mqtt.js Events for information on events and other functionalities.
Disconnects the active MQTT client connection
- Fired when mqtt client connects to server
- 'message' is a string saying Connected
- Fired when a message comes
- 'topic' is the topic to which message was published
- 'message' contains the message send in the topic
- Fired when error is encountered
- error contains details related to the error thrown