33 lines
556 B
JavaScript
33 lines
556 B
JavaScript
const mqtt = require("mqtt-packet");
|
|
const { Readable } = require("stream");
|
|
|
|
const parser = mqtt.parser({
|
|
protocolId: "MQIsdp",
|
|
protocolVersion: 3,
|
|
clean: true,
|
|
clientId: "mqttwsclient",
|
|
reschedulePings: true,
|
|
keepalive: 60
|
|
});
|
|
|
|
parser.on("packet", function(packet){
|
|
|
|
console.log(packet);
|
|
if(
|
|
typeof packet.payload != "undefined" &&
|
|
packet.payload !== null
|
|
){
|
|
|
|
console.log(JSON.parse(packet.payload.toString()));
|
|
}
|
|
});
|
|
|
|
parser.on("error", function(error){
|
|
|
|
console.log("Error: ", error);
|
|
});
|
|
|
|
parser.parse(
|
|
Buffer.from("", "hex")
|
|
);
|