Parse and generate MQTT-SN packets
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
benchmark
.brackets.json
.gitignore
.jshintrc
.travis.yml
LICENSE
README.md
constants.js
generate.js
mqttsn.js
package.json
packet.js
parser.js
test.js

README.md

mqttsn-packet   Build Status

Encode and Decode MQTT-SN 1.2 packets. It is freely inspired from mqttjs/mqtt-packet.

Install

npm install mqttsn-packet --save

Examples

Generating

var mqttsn  = require('mqttsn-packet'),
    object  = {
      cmd: 'connect',
      will: true,
      cleanSession: true,
      duration: 1800,
      clientId: 'test'
    };

console.log(mqttsn.generate(object));
// prints
// <Buffer 0a 04 0c 01 07 08 74 65 73 74>
// as :
// new Buffer([
//   10, 4, // header
//   12, 1, // flags & protocolId
//   7, 8,  // duration : 1800 seconds
//   116, 101, 115, 116 // client Id : test
// ])

Parsing

var mqttsn  = require('mqttsn-packet'),
    parser  = mqttsn.parser();

parser.on('packet', function (packet) {
  console.log(packet);
  // prints :
  // Packet {
  //   cmd: 'connect',
  //   will: true,
  //   cleanSession: true,
  //   duration: 1800,
  //   clientId: 'test' }
});

parser.parse(new Buffer([
  10, 4, // header
  12, 1, // flags & protocolId
  7, 8,  // duration : 1800 seconds
  116, 101, 115, 116 // client Id : test
]));
// returns the number of bytes left in the parser

License

MIT