Simulation of sending live sensors data on IoT Platform using MQTT Protocols and ESP8266/ESP32

MQTT (Message Queuing Telemetry Transport) is one of the most widely used communication protocols in IoT applications. It is lightweight, fast, and designed for devices with low processing power and limited network bandwidth—making it ideal for microcontrollers like ESP8266 and ESP32. In this experiment, we simulate the process of reading sensor data and publishing it to an IoT cloud platform using the MQTT protocol.


ESP8266/ESP32 Microcontroller

Overview

Both are Wi-Fi-enabled microcontrollers used for IoT-based communication.

  • ESP8266: Low-cost Wi-Fi SoC with basic GPIO pins.
  • ESP32: Advanced dual-core processor with integrated Wi-Fi & Bluetooth.

Role in MQTT Communication

  • Acts as an MQTT client
  • Connects to the broker (cloud server) over Wi-Fi
  • Publishes sensor data and subscribes to topics for receiving commands

MQTT Protocol in IoT

MQTT is a publish–subscribe communication protocol designed for efficient IoT messaging.

Key Features

  • Lightweight and bandwidth-efficient
  • Works over TCP/IP
  • Very low latency
  • Excellent for real-time communication
  • Supports thousands of clients

MQTT Components

MQTT Broker (Cloud Server)

  • Manages distribution of messages
  • Popular examples: Mosquitto, HiveMQ, Adafruit IO, ThingsBoard

Publisher

  • Sends data to a topic
  • ESP8266/ESP32 acts as the publisher

Subscriber

  • Receives messages from subscribed topics
  • Can be dashboards, phones, or other IoT devices

Topic

  • Logical communication channel
  • Example: "home/sensors/temperature"

Example Workflow

  1. ESP connects to Wi-Fi
  2. Connects to MQTT broker
  3. Publishes sensor data
  4. Subscribed dashboard receives live updates

Live Sensor Data Collection

Sensors such as DHT11, DHT22, LDR, Soil Moisture, MQ sensors, Ultrasonic can be interfaced with the ESP board.
The ESP reads values using analog/digital pins and publishes them to the MQTT topic.

Data Flow

  • Sensor → ESP board
  • ESP → MQTT Publish
  • Broker → Subscribers
  • Dashboard → Real-time visualization

MQTT vs. HTTP (Why MQTT Is Preferred)

Feature HTTP MQTT
Communication Type Request/Response Publish/Subscribe
Bandwidth Usage High Very Low
Speed Medium Very Fast
Real-Time Updates Limited Excellent
Power Consumption Higher Very Low

MQTT is ideal for battery-powered IoT devices and real-time applications.


IoT Cloud Platforms for MQTT

Cloud platforms supporting MQTT include:

  • HiveMQ Cloud
  • ThingsBoard
  • Adafruit IO
  • AWS IoT Core
  • Google Cloud IoT
  • Mosquitto Broker

Features

  • Real-time dashboards
  • Topic-based message organization
  • Device authentication
  • Remote control using publish/subscribe
  • Graphs and charts for visualization

Simulation Environment

Virtual lab tools like Wokwi, Tinkercad (extensions), Proteus IoT Builder allow full MQTT simulation.

What Can Be Simulated

  • Sensor readings
  • Wi-Fi connection
  • MQTT broker connection
  • Publish/subscribe operations
  • Live dashboard updates

Benefits

  • No physical Wi-Fi required
  • Easy debugging
  • Cost-free and safe
  • Real-time IoT simulation