You might have heard about the buzz word “IOT” or Internet of things. Yes, MQTT is the most commonly used protocol in internet of things. There are two key things one has to understand i.e. the publisher and the subscriber. Let us see some background about publisher and subscriber.
Subscriber is the one which is interesting in receiving messages which are published by publisher. You can have one or more subscribers registered to receive messages. Each of these client gets subscribed to messages via topic or topics.
Publisher is the one, which is responsible for publishing the messages. All clients which are subscribed to a specific topic or topics will get notified with the message published by the publisher.
We are building a sample “nodejs” client and server application using MQTT library to demonstrate how we can take advantage MQTT nodejs library is subscribing and publishing messages with ease. Node.js is very powerful, simple and easy to use. One can really take advantage of building simple and elegant applications using “nodejs”.
First, before we start working on the sample application, there are couple of things we have to do. Yes, that’s installing “MQTT” node.js library and some of the dependencies.
Setting up the dependencies and required node.js libraries
Step 1: Download and install Python 2.7.10
Step 2: Execute the following command in command prompt.
npm config set python C:\Python\python.exe
Step 3: Install MQTT node.js library by executing the following command.
npm install –g mqtt

Demo App
Here’s the scenario for which we are coding the node.js application.
For demonstration purpose, we are making use of the following JSON weather forecast sample.
Sample forecast.
MQTT Node.js Client
The following is the code snippet for MQTT client, where you can see the client is getting subscribed to a specific topic – “mydevice/forecast”. The handleMessage is something which gets called asynchronously when the client receive message from the publisher.
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.


Sr KarthigaPosted Feb 14, 2016, 7:50 AM
Good one sir
Santhakumar MunuswamyPosted Oct 25, 2015, 11:52 AM
Good one
Mukesh KumarPosted Oct 22, 2015, 2:50 PM
Thanks for sharing good work..
Ranjan DailataPosted Oct 22, 2015, 9:39 AM
Thank you all for inspiring me :)
Gowtham KPosted Oct 21, 2015, 10:12 PM
Good One, Thanks for Sharing
Akash VarshneyPosted Oct 21, 2015, 11:16 AM
Good one
Nilesh JadavPosted Oct 21, 2015, 7:44 AM
Good work sir !!
Sibeesh VenuPosted Oct 21, 2015, 1:11 AM
Nice Share
Mukesh KumarPosted Oct 21, 2015, 12:35 AM
Great Work
Harshad PansuriyaPosted Oct 20, 2015, 11:56 PM
Nice one
Mohammed IbrahimPosted Oct 20, 2015, 11:03 PM
nice
Priyaranjan K SPosted Oct 20, 2015, 12:27 PM
Good One