0

members

Easy Basics: Project 074a Some words about MQTT

of Lex C. (Not selected)

Basics: Project 074a

Basics: Project 070s
Project name: ESP8266 ESP-12E module with TMP36 sensor
Tags: ESP, ESP8266, WI FI module, ESP-12E, Ai Thinker, AI-Cloud, SOC, GPIO, General Purpose Input Output, System On a Chip, IOT, internet of things, FTDI232, FTDI 232, how to upload sketch, LoLin NODEMCU V3, NODEMCU, V3, Development Board with USB-to-Serial Onboard, NodeMCU DevKit, TMP36, temperature
Attachments:  sketch1 
In this project, you need these parts :Basics: Project 073a

Project name: Some words about MQTT

Tags: MQTT, how it works, some words about MQTT

We will give you an idea what is MQTT protocol and how to use it for your DIY projects.

MQTT stands for Message Queuing Telemetry Transport. It is a publish and subscribe system where you can publish and receive messages as a client. MQTT is a simple messaging protocol, designed for constrained devices with low-bandwidth. So, it’s the perfect solution for Internet of Things applications. MQTT allows you to send commands to control outputs, read and publish data from sensor nodes and much more. With MQTT is very easy to establish a communication between multiple devices.

MQTT Basic Concepts

There are a few basic concepts in MQTT:

  1. Publish/Subscribe
  2. Messages
  3. Topics
  4. Broker

1.Publish/Subscribe

The first concept is the publish and subscribe system. In a publish and subscribe system, a device can publish a message on a topic, or it can be subscribed to a particular topic to receive messages.

For example, device 1 publishes on a topic. Devices 2 and 3 subscribed to the same topic as Device 1 publishing in. Devices 2 and 3 get the message.

2. Messages

Messages are the information that you want to exchange between your devices. Whether it’s a command or data.

3. Topics

Another important concept are the topics. Topics are the way you register interest for incoming messages or how you specify where you want to publish the message.  Topics are case-sensitive.

Topics are represented with strings separated by a forward slash. Each forward slash indicates a topic level. Here’s an example on how you would create a topic for a TV set in your home bedroom:

If you would like to turn on a TV set in your home bedroom using MQTT you can imagine the following process:

  • You have a Device 1 that publishes ON/OFF messages on the home/bedroom/TV set topic.
  • You have a Device 2 that controls a TV set (it can be an ESP32, ESP8266, or any other board). The ESP32 that controls your TV set, is subscribed to that topic: home/bedroom/TV set.
  • When a new message published on this topic, the ESP32 receives the ON/OFF message and turns the TV set on or off.

Device 1 can be ESP32, ESP8266 or Home Automation controller platform like Node-RED, Home Assistant, Domoticz or OpenHAB.

4. Broker

You also need to be aware of the term broker. The broker is primarily responsible for receiving all messages, filtering the messages, decide who is interested in them and then publishing the message to all subscribed clients.

There are several brokers you can use. In our home automation projects we use the Mosquitto broker which can be installed in the Raspberry Pi. Alternatively, you can use a cloud MQTT broker.

You can find the information on how to install Mosquitto Broker on Raspberry PI here.

How to Use MQTT in Home Automation and IoT Projects

The MQTT is the best tool for home automation and internet of things projects. If you want to start making your own DIY projects using MQTT see  an example of what you can do:

Follow these steps:

  1. Set up your Raspberry Pi
  2. Enable and Connect your Raspberry Pi with SSH.
  3. You need Node-RED installed on your Raspberry Pi and Node-RED Dashboard.
  4. Install the Mosquitto broker on the Raspberry Pi.
  5. Add the ESP8266 or the ESP32 to this system: ESP32 development board MQTT , ESP8266 ESP-12E module MQTT


Other projects of Lex C.

Published at 25-09-2018
Viewed: 1541 times