Week-4 (MQTT tutorial)

In my last blog post, we have seen how arduino and raspberry pi functions. Here, in this blog I’ll be discussing about MQTT, necessary installations to implement MQTT on our wireless devices.

What is MQTT?

MQTT stands for Message Queuing telemetry transport. It is one of the most commonly used protocol in IoT project. Let me explain you the functioning of MQTT with the help of a picture.

  • MQTT server is also known as the MQTT Broker which acts as a middleware from client to other client.
  • When a device/client wants to send a message, it is called a publisher.
  • When a device/client wants to receive data, it is called a subscriber.
  • The same device can act as both publisher and subscriber at different times.
  • The devices communicate with other devices through something called “Topic”

Steps to have Publisher-Subscriber model working on PC:

  • Now open a different command prompt, go to the folder where you’ve installed mosquitto.
  • Type mosquito -v, you should now be able to see it running
  • As listed on command prompt, open the node-red server on a website browser.
  • Now let us create a work flow
    • Select an inject component from the nodes given on the left side.
    • Select an mqtt(publisher) from the list
    • Select a debug from the output list
    • Select another mqtt(subscriber), listed under the output
    • Open inject component and mention details as shown in the picture below.
    • Similarly, provide topic and mention the url for subscriber and publisher
    • URL has to be the one mentioned on mosquito server
  • Connect inject to publisher and debug block to subscriber.
  • Deploy it.
  • You should now be able to see the flow between publisher and subscriber.

Let us see the working by connecting it to a device(ESP 8266):

  • Open tools> Select manage libraries> Search for PubSub> Select and install PubSubClient.
  • Make sure you are connected to ESP8266 board.
  • Open File> Go to examples> Select PubSub Client> Select mqtt_esp8266 example
  • Provide the WIFI name as ssid, password is the wifi password and mqtt broker server is the ip address of your computer.
  • Compile and flash the code on to ESP8266.
  • At this stage, I got an error the following error

How to setup MQTT on Mac computer?

I purchased a new Mac book pro and here are the steps to setup MQTT on it:

  • Install Node(npm): open terminal> type brew update > type brew install node > sit back and wait 🕒 > type node -v , which will show you the latest version of node downloaded on your computer
  • Install Node-red: open terminal > type sudo npm install -g –unsafe-perm node-red > after downloading, type node-red. You should that node-red is up and running.

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website at WordPress.com
Get started
%d bloggers like this: