Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home IoT & Smart Home

ESP32 Mesh Network: Build a WiFi Mesh with Painless Mesh

ESP32 Mesh Network: Build a WiFi Mesh with Painless Mesh

March 11, 2026 /Posted byJayesh Jain / 0

Building an ESP32 mesh network WiFi painless mesh setup is one of the most exciting things you can do with the ESP32 platform. Instead of connecting every node to a central router, a mesh network allows ESP32 boards to talk directly to each other, relaying messages across the entire network. This is perfect for large Indian homes, warehouses, farms, or industrial floors where a single WiFi access point cannot reach every corner.

Table of Contents

  1. What is an ESP32 Mesh Network?
  2. Introduction to Painless Mesh Library
  3. Hardware Needed
  4. Installation and Setup
  5. Building Your First Mesh Network
  6. Advanced Use Cases for Indian Applications
  7. Troubleshooting Tips
  8. Frequently Asked Questions

What is an ESP32 Mesh Network?

A traditional WiFi network relies on a single central router. Every device must be within range of that router to communicate. An ESP32 mesh network breaks this limitation by allowing every ESP32 node to act as both a client and an access point simultaneously. Data hops from node to node until it reaches its destination, dramatically extending the range of your wireless network.

Think of it like a chain of walkie-talkies — each one can relay a message to the next one in line, so the message travels far beyond what a single radio could achieve. In a mesh network, if one node fails, the network automatically reroutes messages through another path. This self-healing property makes mesh networks extremely reliable for mission-critical IoT deployments.

Common real-world applications include smart agriculture in large Indian farms, industrial sensor networks in factories, home automation across large bungalows, and emergency communication systems. The ESP32, with its dual-core processor, built-in WiFi, and Bluetooth, is perfectly suited for mesh networking at a fraction of the cost of commercial mesh systems.

Introduction to Painless Mesh Library

Painless Mesh is an open-source Arduino library that makes building a mesh network with ESP32 (and ESP8266) surprisingly straightforward. Without this library, implementing a mesh protocol from scratch would require deep networking knowledge and months of development time. Painless Mesh abstracts all the complex handshaking, routing, and message forwarding behind a clean API.

Key features of Painless Mesh include:

  • Automatic topology management: Nodes discover each other and build the network automatically when powered on.
  • Self-healing routing: If a node drops out, the library finds alternative paths within seconds.
  • Broadcast and unicast messaging: Send messages to one specific node or to all nodes at once.
  • No external server required: The entire mesh operates independently without internet access.
  • JSON-based messaging: Messages are plain JSON strings, making integration easy.
  • Compatible with both ESP32 and ESP8266: Mix and match hardware as needed.

Painless Mesh uses the ESPNOW protocol under the hood combined with TCP/IP WiFi connections, giving it excellent range and reliability. The library is actively maintained and has a large community, which means plenty of examples and support forums are available.

Hardware Needed

To build an ESP32 mesh network, you need at least 2-3 ESP32 development boards (more nodes means better coverage). For this tutorial, we recommend using 3 nodes to demonstrate the mesh concept properly.

Ai Thinker NodeMCU-32S-ESP32 Development Board

Ai Thinker NodeMCU-32S-ESP32 Development Board – IPEX Version

A reliable, full-featured ESP32 development board with external antenna support for maximum WiFi range — ideal for mesh network nodes.

View on Zbotic

2 x 18650 Lithium Battery Shield

2 x 18650 Lithium Battery Shield for Arduino, ESP32, ESP8266

Power your mesh nodes independently with this dual 18650 battery shield, enabling truly wireless deployment across your home or field.

View on Zbotic

DHT11 Digital Humidity and Temperature Sensor

DHT11 Digital Relative Humidity and Temperature Sensor Module

Add real sensor data to your mesh network — each node can read temperature and humidity and broadcast it across the entire mesh.

View on Zbotic

You will also need USB data cables for programming, a laptop with Arduino IDE installed, and optionally some sensors (DHT11, BMP280) to give each mesh node something meaningful to report.

Installation and Setup

Before writing any code, you need to set up your development environment correctly. Follow these steps:

Step 1: Install Arduino IDE and ESP32 Board Support

Download and install Arduino IDE 2.x from arduino.cc. Then open File → Preferences and add this URL to the Additional Board Manager URLs field:

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

Go to Tools → Board → Board Manager, search for “esp32” and install the Espressif Systems esp32 package.

Step 2: Install Painless Mesh Library

Open Sketch → Include Library → Manage Libraries. Search for “painlessMesh” and install it. The library manager will also prompt you to install its dependencies: ArduinoJson, TaskScheduler, and ESPAsyncTCP. Install all of them.

Step 3: Configure Board Settings

Select Tools → Board → ESP32 Arduino → NodeMCU-32S (or whichever board you have). Set the upload speed to 115200 and select the correct COM port.

Building Your First Mesh Network

With the environment ready, let’s write the code. All nodes in a Painless Mesh network share the same MESH_SSID and MESH_PASSWORD. They discover each other automatically — you do not need to configure which node connects to which.

#include <painlessMesh.h>

#define MESH_PREFIX   "ZboticMesh"
#define MESH_PASSWORD "meshpass123"
#define MESH_PORT     5555

Scheduler userScheduler;
painlessMesh mesh;

void sendMessage();
Task taskSendMessage(TASK_SECOND * 2, TASK_FOREVER, &sendMessage);

void sendMessage() {
  String msg = "Hello from node: ";
  msg += mesh.getNodeId();
  mesh.sendBroadcast(msg);
}

void receivedCallback(uint32_t from, String &msg) {
  Serial.printf("Received from %u: %sn", from, msg.c_str());
}

void newConnectionCallback(uint32_t nodeId) {
  Serial.printf("New connection, nodeId = %un", nodeId);
}

void changedConnectionCallback() {
  Serial.println("Connections changed");
}

void setup() {
  Serial.begin(115200);
  mesh.setDebugMsgTypes(ERROR | STARTUP | CONNECTION);
  mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);
  mesh.onReceive(&receivedCallback);
  mesh.onNewConnection(&newConnectionCallback);
  mesh.onChangedConnections(&changedConnectionCallback);
  userScheduler.addTask(taskSendMessage);
  taskSendMessage.enable();
}

void loop() {
  mesh.update();
  userScheduler.execute();
}

Upload this exact same sketch to all three ESP32 boards — you do not need different code for different nodes. Each board will automatically negotiate its role in the mesh. Open the Serial Monitor on any one of the boards and you will see messages from all other nodes appearing every 2 seconds.

Adding Sensor Data to Each Node

To make the mesh useful, integrate a DHT11 sensor on each node. Add these changes to the sketch:

#include <DHT.h>
#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void sendMessage() {
  float temp = dht.readTemperature();
  float hum = dht.readHumidity();
  String msg = "{"node":" + String(mesh.getNodeId());
  msg += ","temp":" + String(temp);
  msg += ","hum":" + String(hum) + "}";
  mesh.sendBroadcast(msg);
}

Now every node broadcasts a JSON payload with its own temperature and humidity. Any node with internet access (connected to a home router) can forward this data to a cloud service like ThingSpeak or Blynk.

Advanced Use Cases for Indian Applications

The ESP32 mesh network is not just a toy project — it has serious real-world potential, especially in the Indian context where infrastructure challenges make centralized WiFi impractical.

Smart Agriculture

Indian farmers managing large fields can deploy a mesh network of ESP32 nodes with soil moisture sensors, temperature sensors, and water flow meters. One node near the farmhouse with internet access acts as the gateway, forwarding all sensor data to a cloud dashboard. The farmer can monitor every corner of a 5-acre field from a single mobile app.

Industrial Floor Monitoring

In manufacturing plants across cities like Pune, Surat, or Coimbatore, mesh networks can monitor machine temperatures, vibration levels, and power consumption without needing to run Ethernet cables. Nodes can be placed on each machine, and any node near the control room serves as the gateway.

Smart Homes and Apartments

In a large Indian bungalow or a multi-floor apartment, WiFi dead zones are common. A mesh network of ESP32 nodes can extend automation control to garages, terraces, utility rooms, and basements without additional routers.

Emergency Communication

In areas prone to floods or natural disasters (common in coastal India), a pre-deployed ESP32 mesh network continues to function even when the internet is down. Nodes relay status messages about water levels, power outages, or emergency alerts across the network without any infrastructure dependency.

BMP280 Barometric Pressure Sensor

BMP280 Barometric Pressure and Altitude Sensor I2C/SPI Module

Attach a BMP280 to mesh nodes deployed in agricultural fields to monitor atmospheric pressure and altitude alongside temperature data.

View on Zbotic

Troubleshooting Tips

Building a mesh network can throw up some challenges. Here are the most common problems and how to fix them:

  • Nodes not connecting to each other: Ensure all nodes use exactly the same MESH_PREFIX and MESH_PASSWORD (case-sensitive). Verify that nodes are within WiFi range of at least one other node.
  • Messages not being received: Check that the painlessMesh library version is the same on all nodes. Mismatched versions can cause incompatibility.
  • Frequent disconnections: Reduce the message broadcast frequency. Sending too many messages too quickly congests the mesh. Add a delay or use TaskScheduler with a longer interval.
  • Node not appearing in the mesh topology: Power-cycle the node. Sometimes a hard reset is needed for the node to re-announce itself to its neighbours.
  • Memory issues on ESP32: Painless Mesh is memory-intensive. If you’re running out of heap, reduce the JSON payload size or limit the number of simultaneous connections per node.
  • Gateway node losing internet connectivity: The gateway node uses two WiFi connections simultaneously — the mesh network and the home router. Ensure your home router signal is strong at the gateway node’s location.
30Pin ESP32 Expansion Board

30Pin ESP32 Expansion Board with Type-C USB and Micro USB

Easily connect multiple sensors to each mesh node using this expansion board — it provides a clean breakout for all GPIO pins.

View on Zbotic

Frequently Asked Questions

How many nodes can Painless Mesh support?

Painless Mesh can theoretically support hundreds of nodes, but practical deployments work best with up to 20-30 nodes per mesh. Beyond that, message latency increases significantly and memory constraints on the ESP32 can become a problem. For larger networks, consider breaking the deployment into multiple independent mesh clusters connected by gateway nodes.

Can I mix ESP32 and ESP8266 nodes in the same mesh?

Yes, Painless Mesh supports both ESP32 and ESP8266 in the same network. However, ESP8266 has a single-core processor and less RAM, so it may be slower in forwarding messages. It’s best to use ESP32 boards as the backbone nodes and ESP8266 boards as leaf nodes that only send data without relaying.

Does the ESP32 mesh work without internet?

Absolutely. The entire Painless Mesh network operates without any internet connection. Nodes discover each other, route messages, and exchange data completely offline. You only need internet access if you want to forward data from the mesh to a cloud platform.

How far apart can mesh nodes be placed?

Standard ESP32 boards with PCB antennas can communicate over 50-100 metres in open air and 10-20 metres indoors through walls. Using boards with external IPEX antennas can extend this to 200+ metres outdoors. For a large farm or warehouse, place nodes every 30-50 metres to ensure reliable connectivity.

Is Painless Mesh secure?

Painless Mesh uses WPA2 encryption on the WiFi connections between nodes, so the wireless transmissions are encrypted. However, the messages themselves are plain JSON strings — add application-level encryption if your data is sensitive.

Ready to Build Your ESP32 Mesh Network?

Get all the ESP32 boards, sensors, and accessories you need from Zbotic — India’s trusted electronics components store with fast delivery across all major cities.

Shop ESP32 & IoT Products on Zbotic

Tags: ESP32, iot, Mesh Network, Painless Mesh, WiFi Mesh
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
IoT Soil Monitor for Farms: ES...
blog iot soil monitor for farms esp32 lora dashboard 595444
blog esp32 configurable web portal wifimanager auto setup 595448
ESP32 Configurable Web Portal:...

Related posts

Svg%3E
Read more

IoT Home Insurance Sensor Kit: Leak, Smoke, and Motion

April 1, 2026 0
Table of Contents IoT and Home Insurance Water Leak Detection Smoke and Fire Detection Motion and Intrusion Sensing Building the... Continue reading
Svg%3E
Read more

IoT Pet Tracker: GPS Collar with Geofencing Alerts

April 1, 2026 0
Table of Contents Introduction and Overview Hardware Components Required GPS Module Integration with ESP32 Cloud Platform Setup Real-Time Tracking Dashboard... Continue reading
Svg%3E
Read more

IoT Aquaponics Controller: Fish and Plant Automation

April 1, 2026 0
Table of Contents The Water Monitoring Challenge in India Sensor Technologies for Water Building the Sensor Node Data Transmission and... Continue reading
Svg%3E
Read more

IoT Composting Monitor: Temperature and Moisture Tracking

April 1, 2026 0
Table of Contents Why Temperature Monitoring Matters Sensor Selection Guide Hardware Assembly and Wiring Firmware Development Cloud Data Logging Alert... Continue reading
Svg%3E
Read more

IoT Beehive Monitor: Weight, Temperature, and Humidity

April 1, 2026 0
Table of Contents Why Monitor Beehives Weight Measurement System Temperature and Humidity Sensing Building the Monitor Data Analysis for Bee... Continue reading

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now