Skip to content

MQTT.js full concept with all codes, syntax and notes

Notifications You must be signed in to change notification settings

DNSingh-15/MQTT.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

drawing

  • MQTT ---> Message Queuing Telemetry Transport

  • it is a client library for MQTT protocol written in JavaScript for node.js and the browser

  • MQTT is a lightweight client-server publish/subscribe messaging protocol

  • MQTT is used for data exchange between devices and server applications

installation

npm install mqtt --save

component

  1. Publisher
  2. broker --- inside broker there are some queues
  3. subscriber

drawing

methods

  1. connect
client.on('connect', function (connack) {
   console.log('Connected')
})
  1. reconnect
client.on('reconnect', function () {
  console.log('Reconnecting...')
})
  1. close
client.on('close', function () {
  console.log('Disconnected')
})
  1. disconnect
client.on('disconnect', function (packet) {
   console.log(packet)
})
  1. publish
Client.publish(topic, message, [options], [callback]
                🔽
client.publish('topic', 'Hello world')
                🔽
client.publish('testtopic', 'Hello, function () {
    console.log('Published')
})
  1. subscribe
client.subscribe('test', function (err) {
    console.log(error)
})
  1. error
client.on('error', function (error) {
  console.log(error)
})
  1. message
client.on('message', function (topic, payload, packet) {
  console.log(`Topic: ${topic}, Message: ${payload.toString()}, QoS: ${packet.qos}`)
})

About

MQTT.js full concept with all codes, syntax and notes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published