31  Wi-Fi Architecture Modes

In 60 Seconds

Wi-Fi operates in three architecture modes: infrastructure (star topology centered on an access point), Wi-Fi Direct (peer-to-peer without a router), and mesh (multi-hop self-healing coverage). Infrastructure mode suits most home/office IoT, Wi-Fi Direct enables temporary device-to-device links, and mesh extends coverage across large facilities through relay nodes – though each hop reduces effective bandwidth and relay nodes must remain always-on.

31.1 Learning Objectives

By the end of this chapter, you will be able to:

  • Differentiate Wi-Fi Architectures: Classify infrastructure mode, Wi-Fi Direct, and mesh networking by topology, scalability, and power requirements
  • Evaluate Architecture Trade-offs: Analyse coverage, power consumption, and throughput implications of each Wi-Fi mode for a given IoT deployment scenario
  • Implement ESP32 Mesh: Configure a multi-node mesh network using the painlessMesh library and verify self-healing behaviour
  • Design for Coverage: Calculate hop-count bandwidth impact and apply access point placement strategies to optimise IoT network coverage

31.2 Prerequisites

Before diving into this chapter, you should be familiar with:

  • Wi-Fi Fundamentals and Standards: Understanding Wi-Fi standards (802.11b/g/n/ac/ax), frequency bands (2.4/5 GHz), and basic Wi-Fi characteristics is essential background for exploring advanced Wi-Fi architectures
  • Networking Basics: Knowledge of network topologies (star, mesh), MAC layer concepts, and wireless communication fundamentals helps understand Wi-Fi architecture decisions
  • Wireless Sensor Networks: Familiarity with multi-hop routing, self-healing networks, and coverage extension techniques provides context for Wi-Fi mesh networking concepts
Key Takeaway

In one sentence: Wi-Fi mesh networks extend coverage through multi-hop routing and self-healing topology, making Wi-Fi viable for large-scale IoT deployments beyond single access point range.

Remember this rule: Use infrastructure mode for simple deployments, Wi-Fi Direct for temporary peer-to-peer connections without routers, and mesh for whole-building coverage with seamless roaming.

Deep Dives:

Comparisons:

Architecture Context:

Learning Resources:

Think of Wi-Fi network architecture like different ways people organize conversations at a party. In infrastructure mode (the most common type), everyone talks through a central “host” – your Wi-Fi router. It’s like a moderator at a meeting who makes sure only one person talks at a time, preventing everyone from talking over each other. This works great for homes and offices where the router can reach all your devices.

Wi-Fi Direct is like two friends having a private conversation in a corner – no moderator needed. Your phone can connect directly to a printer or camera to transfer files, without needing a router in between. It’s faster than asking everyone at the party to pass a message along!

Mesh networks are the most interesting. Imagine the party is spread across a huge mansion, and people in different rooms can’t hear the host. In a mesh network, helpful guests relay messages from room to room until everyone can communicate. If one person leaves, others automatically find a new path – that’s called “self-healing.” The catch? Each time a message gets passed along (called a “hop”), it takes longer to arrive and uses up more of the available “talking time” on the wireless channel. So mesh networks trade speed for coverage: they extend Wi-Fi across large areas, but each hop can reduce the effective speed.

31.3 🌱 Getting Started (For Beginners)

👋 New to Wi-Fi Networks? Start Here!

This section is designed for beginners. If you’re already familiar with Wi-Fi infrastructure mode, mesh networks, and CSMA/CA, feel free to skip to the technical sections below.

31.3.1 What is Wi-Fi Architecture? (Simple Explanation)

Analogy: Think of Wi-Fi architecture as different ways to organize a conversation in a room full of people.

Key Terms for Wi-Fi Architecture:

Term What It Means Real-World Example
Infrastructure Mode All devices connect through central router Your home Wi-Fi (most consumer Wi-Fi IoT devices)
Wi-Fi Direct (P2P) Two devices connect without router Phone → Printer direct connection
Mesh Network Multiple routers relay messages Google Wi-Fi, Eero whole-home systems
SSID Network name (same for all mesh nodes) “MyHome_Wi-Fi” appears everywhere
Backhaul Connection between mesh nodes How mesh nodes talk to each other
Self-Healing Automatic rerouting when node fails If Node B dies, uses Node C instead

31.3.2 Why Wi-Fi Architecture Matters for IoT

Wi-Fi is widely available, but architecture choices determine: - Coverage and roaming behavior (single AP vs multiple nodes) - Power strategy (how many nodes must be always-on) - Performance under load (more devices, more contention) - Provisioning and temporary links (router required or not)

Three main Wi-Fi modes:

  1. Infrastructure Mode = Everyone talks through a moderator (router)
    • Like a conference call where everyone calls a central number
    • The router is the “traffic cop” directing all messages
  2. Wi-Fi Direct = Two people talking directly to each other
    • Like a phone call between two friends (no middleman)
    • One device acts as a temporary hotspot
  3. Mesh Network = Multiple conversations with everyone helping relay messages
    • Like people in a crowded room passing notes to help messages reach far corners
    • If one person leaves, others find a new path

31.3.3 Wi-Fi Modes Comparison (Everyday Examples)

Mode Real-World Analogy When You Use It IoT Example
Infrastructure Coffee shop Wi-Fi - everyone connects to router Home, office, public Wi-Fi Smart home devices → router → internet
Wi-Fi Direct AirDrop between two phones (direct connection) Phone to printer, phone to camera Camera directly streaming to phone
Mesh Relay race - multiple runners passing baton Large house, office building, warehouse Sensors spread across factory floor

31.3.4 Infrastructure Mode (Most Common)

How it works:

Diagram: IoT

Diagram: IoT
Figure 31.1: Infrastructure mode: All devices connect through a central router (star topology)

Key points:

  • One router controls everything (like a traffic cop)
  • All devices connect to router (star topology)
  • Router provides internet access (bridge to cloud services)
  • Most Wi-Fi IoT deployments start here

Real example: Your smart home has 15 devices (lights, sensors, cameras). All connect to your Wi-Fi router. Router assigns each device an IP address and forwards messages between devices and the internet.

Limitations:

  • ❌ Router is single point of failure (router dies = all offline)
  • ❌ Indoor coverage can drop quickly through walls/floors/metal
  • ❌ Extending coverage usually means adding APs/mesh/extenders (each with trade-offs)

31.3.5 Wi-Fi Direct (Peer-to-Peer)

Analogy: Wi-Fi Direct is like Bluetooth, but faster and longer range.

How it works:

Diagram: PHONE

Diagram: PHONE
Figure 31.2: Wi-Fi Direct: Two devices connect directly without a router

Key points:

  • Two devices connect directly (no router required)
  • One device acts as “soft AP” (temporary hotspot)
  • ✅ Often higher throughput than Bluetooth (especially BLE), but throughput depends on Wi-Fi standard, channel width, and RF conditions
  • ✅ Range can be longer than Bluetooth in open space, but is highly environment/antenna dependent

Real examples:

  • 📱→📷 Phone to camera: Transfer photos from DSLR to phone instantly
  • 📱→🖨️ Phone to printer: Print documents without router
  • 📱→🔊 Phone to speaker: Stream music to Wi-Fi Direct speaker
  • 🎮→📺 Game console to TV: Miracast screen mirroring

When to use:

  • ✅ Temporary connections (don’t need internet)
  • ✅ High-speed file transfers
  • ✅ Field deployment (no existing Wi-Fi infrastructure)

Limitations:

  • ❌ Only 1-to-1 or 1-to-few connections (not scalable)
  • ❌ One device must stay awake as soft AP (drains battery)

31.3.6 Wi-Fi Mesh Networks (Self-Healing Magic!)

Analogy: A mesh network is like a relay race where runners pass messages across a large area.

Traditional Wi-Fi (Single Router):

Diagram: ROUTER

Diagram: ROUTER
Figure 31.3: Traditional Wi-Fi: Signal degrades over distance, creating dead zones

Wi-Fi Mesh:

Diagram: ROUTER

Diagram: ROUTER
Figure 31.4: Wi-Fi Mesh: Multiple nodes relay signals for full coverage everywhere

How it works:

  1. Main router connects to internet
  2. Mesh nodes placed throughout area (hallway, bedroom, garage)
  3. Each node relays messages to extend coverage
  4. Automatic routing - finds best path to destination
  5. Self-healing - if one node fails, finds alternate path

Key concepts:

A) Self-Healing (Automatic Rerouting)

Scenario: Node 2 battery dies

Diagram: BEFORE

Diagram: BEFORE
Figure 31.5: Self-healing: Mesh automatically finds alternate path when a node fails

B) Multi-Hop Communication

Diagram: SENSOR

Diagram: SENSOR
Figure 31.6: Multi-hop communication: Message relays through multiple nodes to reach the cloud

Each hop can extend coverage into another area, but it also increases airtime usage (the same payload is forwarded multiple times), adds latency, and can reduce effective throughput—especially when client traffic and backhaul share the same radio/channel.

Real-world mesh examples:

Application Why Mesh? Typical scale
Large office building Concrete walls/floors create dead zones Multiple rooms/floors
Warehouse Metal racks and long aisles block signals Large indoor floor
Outdoor site / farm Wide spacing and limited infrastructure Field-scale (line-of-sight dependent)
Campus / neighborhood Coverage extension with many powered nodes Street/block-scale (deployment dependent)

Mesh vs Wi-Fi Extenders:

Feature Wi-Fi Extender Mesh Network
Setup Simple Complex
Network name Different SSID Same SSID (seamless)
Handoff Manual switch Automatic
Performance Often reduced (retransmits on same channel) Varies; dedicated backhaul or wired uplinks preserve more
Self-healing ❌ No ✅ Yes
Best for 1-2 extra rooms Whole house/building

31.3.7 Hidden Terminal Problem (Why Mesh is Tricky)

Analogy: The hidden terminal problem is like two people trying to talk to you at the same time, but they can’t hear each other.

Scenario:

Wi-Fi Architecture Diagram 1

Wi-Fi Architecture Diagram 1
Figure 31.7: Hidden terminal: Two sensors cannot hear each other but both reach the router

What happens:

  1. Sensor A checks: “Is anyone talking?” (silence, can’t hear B)
  2. Sensor A starts transmitting to Router
  3. Sensor B checks: “Is anyone talking?” (silence, can’t hear A)
  4. Sensor B starts transmitting to Router at SAME TIME
  5. COLLISION! Router receives garbled message from both

Solution: RTS/CTS (Request To Send / Clear To Send)

Wi-Fi Architecture Diagram 2

Wi-Fi Architecture Diagram 2
Figure 31.8: RTS/CTS handshake prevents hidden terminal collisions

Real impact:

  • Without RTS/CTS: hidden-terminal collisions can cause frequent retransmissions and noticeable packet loss
  • With RTS/CTS: typically improves reliability, but adds protocol overhead and can reduce throughput

31.3.8 Quick Self-Check

- ~6 mesh nodes total (2-3 per floor), each covering ~50m radius - Overlap zones ensure redundancy (self-healing)

Why NOT the other options:

  • A) Single router ❌ — Router range ~20m through concrete floors; ~70% of sensors would be out of range
  • B) Wi-Fi Direct ❌ — 1-to-1 connections only; 70 sensors can’t all connect directly to gateway
  • D) Bluetooth mesh ❌ — Different technology; question asks for Wi-Fi solution

Power reality check: Mesh relay nodes should be mains/PoE powered (they must stay awake to forward traffic). For multi-year battery sensors, consider Zigbee/Thread/LoRaWAN instead.


Ready for technical details? The sections below cover ESP32 mesh implementation and interactive challenges!

🎓 Cross-Hub Connections

Enhance Your Learning:

This chapter connects to multiple learning resources across the module:

🎥 Watch: Videos Hub has Wi-Fi mesh tutorials, CSMA/CA animations, and ESP32 mesh setup walkthroughs

🧪 Practice: Simulations Hub offers interactive mesh topology visualizers, hidden terminal simulators, and network performance calculators

✅ Test: Quizzes Hub provides Wi-Fi architecture assessments, mesh design challenges, and CSMA/CA problem sets

📊 Map: Knowledge Map shows how Wi-Fi mesh connects to WSN routing, network topologies, and edge computing patterns

🔍 Gaps: Knowledge Gaps clarifies common misconceptions about mesh self-healing times, RTS/CTS overhead, and Wi-Fi Direct limitations

⚠️ Common Misconception: “Wi-Fi Mesh = Always Faster”

The Myth: Many assume Wi-Fi mesh networks are faster than single routers because they have more access points.

The Reality: Mesh networks trade speed for coverage—each hop reduces effective bandwidth.

The following numbers are illustrative for single-radio (shared channel) backhaul. Actual performance varies by hardware, environment, and traffic patterns.

Illustrative Throughput Impact (shared-channel backhaul):

Path Effective Throughput Notes
Single router (no mesh) ~300 Mbps Baseline at 10m
Mesh with 1 hop ~150-180 Mbps ~40-50% reduction
Mesh with 2 hops ~75-90 Mbps ~70% reduction
Mesh with 3 hops ~40-50 Mbps ~85% reduction

Why This Happens:

Diagram: SINGLE

Diagram: SINGLE
Figure 31.9: Mesh bandwidth reduction: Each hop reuses the channel, effectively halving throughput

Why each hop approximately halves mesh bandwidth:

In single-radio mesh (most consumer systems), the same Wi-Fi radio handles both client traffic and backhaul. Each hop requires a separate transmission that shares the same channel airtime.

Channel capacity division: $ = $

For 802.11ac with 300 Mbps baseline throughput:

1 hop (direct to root): $ = = = 150 $ (Device → Root requires 2 transmissions: device TX + root ACK)

2 hops (via one relay node): $ = = = 100 $ (Device → Node A → Root = 3 transmissions sharing the channel)

3 hops (via two relay nodes): $ = = = 75 $

Real-world degradation (accounting for overhead):

  • Protocol overhead (MAC headers, ACKs, interframe spacing): ~30%
  • Contention and retransmissions: ~10-20%
  • Backhaul inefficiency: Each hop adds ~5-10% overhead

Realistic throughput: $ = = $

For 2-hop mesh: $ 100 = 60 $

Key insight: The \(\frac{1}{1 + N}\) formula is a simplified upper bound. Real mesh networks lose additional capacity to MAC overhead, contention, and scheduling inefficiencies. Each hop doesn’t exactly halve throughput, but the degradation is substantial—typically 40-50% reduction per hop in shared-channel designs.

The Problem: Most consumer mesh systems use single-radio backhaul: - Same Wi-Fi radio handles both client devices AND mesh links - Each hop “re-uses” the wireless channel - Bandwidth effectively divided by number of hops

How to design around it:

  • Prefer wired/ethernet backhaul where possible (best performance)
  • Use dual-band or tri-band mesh with dedicated backhaul channel
  • Keep critical devices to ≤2 wireless hops from the root
  • For high-bandwidth IoT (cameras), minimize hops or use wired connections

Key takeaway: Mesh solves coverage problems, not speed problems. For bandwidth-sensitive applications, minimize hops and consider wired backhaul.

31.4 🧪 Interactive Lab: ESP32 Wi-Fi Mesh Network

Let’s build a Wi-Fi mesh network using multiple ESP32 devices that automatically route messages and self-heal when nodes fail!

🔧 Lab Setup

Hardware (Simulated):

  • 4× ESP32 DevKit v1 (mesh nodes)
  • Each node has temperature sensor (simulated)
  • Root node connects to Wi-Fi router

What This Lab Does:

  1. Creates 4-node mesh network
  2. Each node broadcasts temperature data
  3. Messages auto-route through mesh
  4. Demonstrates self-healing when node fails
  5. (Optional extension) Bridge mesh data to an MQTT broker via a gateway/root node

31.4.1 Mesh Messaging Simulation (Arduino painlessMesh)

This section has two parts:

  1. A small interactive toy model to build intuition about hop count and airtime.
  2. A hardware-oriented ESP32 example using painlessMesh.

31.4.1.1 Interactive: Hop Count vs Airtime (Toy Model)

31.4.1.2 Hardware Lab: ESP32 Mesh Messaging (painlessMesh)

This code is intended for real ESP32 hardware (or a simulator that supports multi-node mesh libraries). Use it as a starting point for a physical lab build and adapt credentials/keys for your environment.

Code Explanation: The mesh node uses painlessMesh for auto-discovery, broadcasts sensor data as JSON every 5 seconds, and logs received messages from other nodes.

#include "painlessMesh.h"
#include <Arduino_JSON.h>

// Mesh network credentials
#define MESH_PREFIX     "IoT_Mesh_Network"
#define MESH_PASSWORD   "mesh_password_123"
#define MESH_PORT       5555

// Node identification
String nodeName = "TempSensor_";  // Will append node ID
int nodeNumber = 0;  // Set uniquely for each node (0-3)

Scheduler userScheduler;
painlessMesh mesh;

// Task to send sensor data periodically
void sendMessage();
Task taskSendMessage(TASK_SECOND * 5, TASK_FOREVER, &sendMessage);

// Simulate temperature reading
float readTemperature() {
  // Each node returns slightly different temp
  return 20.0 + nodeNumber * 2.5 + random(-10, 10) / 10.0;
}

// Send temperature data to mesh
void sendMessage() {
  float temp = readTemperature();

  // Create JSON message
  JSONVar msg;
  msg["node"] = nodeName + String(mesh.getNodeId());
  msg["type"] = "temperature";
  msg["value"] = temp;
  msg["unit"] = "C";
  msg["timestamp"] = millis();

  String str = JSON.stringify(msg);

  // Broadcast to all nodes in mesh
  mesh.sendBroadcast(str);

  Serial.printf("📡 Sent: %s = %.1f°C (NodeID: %u)\n",
                nodeName.c_str(), temp, mesh.getNodeId());
}

// Callback when message received
void receivedCallback(uint32_t from, String &msg) {
  Serial.printf("📥 Received from %u: %s\n", from, msg.c_str());

  // Parse JSON
  JSONVar myObject = JSON.parse(msg);

  if (JSON.typeof(myObject) == "undefined") {
    Serial.println("❌ JSON parsing failed");
    return;
  }

  String node = JSON.stringify(myObject["node"]);
  String type = JSON.stringify(myObject["type"]);
  double value = myObject["value"];

  Serial.printf("   └─ Node: %s, Type: %s, Value: %.1f\n",
                node.c_str(), type.c_str(), value);
}

// Callback when new node joins mesh
void newConnectionCallback(uint32_t nodeId) {
  Serial.printf("✅ New node joined! NodeID: %u\n", nodeId);
  Serial.printf("   Total nodes in mesh: %d\n", mesh.getNodeList().size() + 1);
}

// Callback when node leaves mesh
void changedConnectionCallback() {
  Serial.printf("🔄 Mesh topology changed\n");
  Serial.printf("   Connected nodes: %d\n", mesh.getNodeList().size() + 1);

  // Print node list
  Serial.print("   NodeIDs: ");
  auto nodes = mesh.getNodeList();
  for (auto &&id : nodes) {
    Serial.printf("%u ", id);
  }
  Serial.println();
}

// Callback when mesh time is adjusted
void nodeTimeAdjustedCallback(int32_t offset) {
  Serial.printf("⏰ Time adjusted by %ld us\n", (long)offset);
}

void setup() {
  Serial.begin(115200);
  delay(1000);

  Serial.println("\n\n=== ESP32 Wi-Fi Mesh Node Starting ===");
  Serial.printf("Node: %s%d\n", nodeName.c_str(), nodeNumber);

  // Append node number to name
  nodeName += String(nodeNumber);

  // Set mesh debugging
  mesh.setDebugMsgTypes(ERROR | STARTUP | CONNECTION);

  // Initialize mesh network
  mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);

  // Register callbacks
  mesh.onReceive(&receivedCallback);
  mesh.onNewConnection(&newConnectionCallback);
  mesh.onChangedConnections(&changedConnectionCallback);
  mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCallback);

  // Add task to send messages
  userScheduler.addTask(taskSendMessage);
  taskSendMessage.enable();

  Serial.println("✅ Mesh network initialized!");
  Serial.printf("   Node ID: %u\n", mesh.getNodeId());
}

void loop() {
  mesh.update();  // Maintain mesh connections
}

31.4.2 Interactive Challenges

Challenge 1: Mesh Topology - How Many Hops?

You have a mesh network with this topology:

Diagram: ROOT

Diagram: ROOT
Figure 31.10

Question: A message from Sensor Node D needs to reach the Root Router. How many “hops” does the message make?

Click for hint

A “hop” is each time a message passes through a mesh node.

Count the arrows: D → C → B → A → Root How many arrows are there?

Click for answer

Answer: 4 hops

Step-by-step message path:

Diagram: D

Diagram: D
Figure 31.11

Why this matters:

Latency and airtime:

  • Each hop adds processing/queueing delay and consumes additional airtime.
  • More hops generally means higher latency and lower effective throughput.

Power consumption:

  • Each hop costs battery power
  • Node C relays: D’s messages + B’s messages + own messages
  • Middle nodes drain battery faster than edge nodes

Bandwidth impact:

  • Each hop “re-uses” the wireless channel
  • 4 hops = message transmitted 4 times over the air
  • In shared-channel designs, multi-hop forwarding can reduce the best-case capacity available to each flow (a simple upper bound is ~1/(hops+1)).

Optimal mesh design:

  • Minimize hops: Keep hop counts low for critical traffic
  • Place nodes strategically: Avoid long linear chains
  • Use multiple paths: Redundancy improves reliability

Better topology for same 5 nodes:

Diagram: ROOT

Diagram: ROOT
Figure 31.12

Now any sensor reaches the root in fewer hops than a long linear chain.

Pro tip: ESP-Wi-Fi-MESH automatically finds shortest path. You don’t manually configure routes - the mesh protocol handles it.


Challenge 2: Self-Healing - What Happens When Node B Fails? ⭐⭐

Original topology:

Diagram: ROOT

Diagram: ROOT
Figure 31.13

Node B suddenly fails (battery dies, power loss, crash).

Question: What happens to messages from Sensor D? Can they still reach the Root?

Scenario options:

    1. Messages lost forever (no route to Root)
    1. Mesh automatically reroutes through alternate path
    1. Sensor D connects directly to Root (too far away)
    1. All nodes restart and rebuild mesh
Click for hint

Remember: Mesh networks are “self-healing” - they automatically find alternate paths when nodes fail.

In a proper mesh, nodes should have multiple neighbor connections, not just a single linear path.

Realistic topology (with redundant paths):

Diagram: ROOT

Diagram: ROOT
Figure 31.14
Click for answer

Answer: B) Mesh automatically reroutes through alternate path

What happens step-by-step:

Before failure:

Diagram: ROOT

Diagram: ROOT
Figure 31.15

Node B fails:

Diagram: ROOT

Diagram: ROOT
Figure 31.16

Self-healing process (conceptual):

  1. Detection: Neighbors stop receiving expected frames/acks and mark the link down.
  2. Route selection: Nodes search for a new parent/next hop based on link quality and path cost.
  3. Rerouting: Traffic resumes along the new path once routing reconverges.

New topology:

Diagram: ROOT

Diagram: ROOT
Figure 31.17

Key points:

Messages can resume if an alternate path exists ✅ No manual intervention (automatic rerouting) ✅ No node restart required (only failed node is offline) ⚠️ Some delay/loss is possible during reconvergence

In a well-designed mesh (with redundancy):

If topology had multiple paths from the start:

Diagram: ROOT

Diagram: ROOT
Figure 31.18

Then C already knows an alternate path through A, so recovery is typically faster (often under 1 second).

Code example - detecting topology changes:

void changedConnectionCallback() {
  Serial.printf("🔄 Mesh topology changed!\n");

  // List current connections
  auto nodes = mesh.getNodeList();
  Serial.printf("   Connected nodes: %d\n", nodes.size() + 1);

  if (nodes.size() < 2) {
    Serial.println("   ⚠️  WARNING: Low node count, limited redundancy!");
  }

  // Mesh automatically reroutes - no action needed
}

Reality check: Recovery time varies widely by stack, topology, traffic load, and RF conditions. For critical IoT, design redundancy (multiple neighbor links) so a single node failure doesn’t isolate edge devices.


Challenge 3: Root Node Selection ⭐⭐⭐

In ESP-Wi-Fi-MESH, one node must be the “Root Node” that connects to the Wi-Fi router and internet.

Question: You have 4 nodes: - Node A: Battery-powered (small battery) - Node B: Powered by USB adapter / mains (always on) - Node C: Solar-powered (intermittent unless designed with storage) - Node D: Battery-powered (larger pack)

Which node should be the Root Node?

Click for hint

The Root Node has special responsibilities: - Always stays awake (can’t deep sleep) - Connects to Wi-Fi router (extra power for two radios) - Routes ALL traffic to/from internet - Single point of failure (if root dies, mesh loses internet)

Which power source is most reliable and has highest capacity?

Click for answer

Answer: Node B (USB powered, always on) is the best choice.

Why:

  • The root/gateway must stay awake, maintain the upstream link, and forward other nodes’ traffic.
  • Battery-only roots drain quickly because they cannot deep-sleep like leaf sensors.
  • Solar can work, but only if engineered like an always-on gateway (panel sizing + storage + worst-case weather).

How ESP-Wi-Fi-MESH selects root automatically (high level):

// Root election is framework-specific. Common factors include:
// - Upstream link quality to the router/AP
// - Node centrality / number of neighbors
// - Stability (power/uptime), if the stack accounts for it
// Consult your framework docs for the exact behavior.

You can manually set root node:

// Force Node B to become root
mesh.setRoot(true);  // This node becomes root
mesh.setContainsRoot(true);  // Helps root discovery

// On other nodes
mesh.setRoot(false);  // Don't become root

Optimal mesh power design:

Diagram: POWERED

Diagram: POWERED
Figure 31.19: For multi-year battery requirements at scale, consider lower-power radios (Thread/Zigbee/LPWAN) instead of Wi-Fi mesh.

Pro tip: Place root node where you have reliable AC power and good Wi-Fi router signal. All other mesh design decisions flow from root node placement.


Challenge 4: Mesh vs Infrastructure - When to Use Which? ⭐⭐⭐⭐

You’re designing IoT deployments for three scenarios. Choose the best Wi-Fi architecture for each:

Scenario 1: Smart Home (100 sqm, 2-story house)

  • 25 smart devices (lights, sensors, cameras)
  • Good Wi-Fi router centrally located

Scenario 2: Industrial Warehouse (large indoor floor with metal shelving)

  • 80 temperature sensors spread across the site
  • Metal racks/aisles create dead zones and reflections

Scenario 3: Outdoor Smart Farm (large fields)

  • 50 soil moisture sensors spread across a wide area
  • Limited existing power infrastructure

For each scenario, choose: - A) Single Wi-Fi router (infrastructure mode) - B) Wi-Fi extenders (2-3 extenders + router) - C) Wi-Fi mesh network (multiple mesh nodes)

Click for hint

Consider for each scenario: - Area coverage: Can single router reach all devices? - Obstacles: Do walls, metal, or outdoor distance block Wi-Fi? - Backhaul: Do you have wired uplinks (best) or must you use wireless backhaul? - Roaming: Do devices move and need seamless handoff? - Power + maintenance: Can you power always-on nodes, and can you service them if they fail?

Click for answer

Answers:

Scenario 1: Smart Home → A) Single Wi-Fi router

Why: A centrally placed AP/router often covers a typical home, and a single SSID is easy to manage. If you discover dead zones, add an additional AP or move to mesh.

When to upgrade to mesh:

  • If you consistently have dead zones despite good placement
  • If you need seamless coverage across multiple floors/areas
  • If you can power additional nodes and want centralized management

Scenario 2: Industrial Warehouse → C) Wi-Fi mesh network

Why: A warehouse usually needs multiple RF points because racks/aisles create dead zones. Mesh is one way to extend coverage with a single SSID and some self-healing. In enterprise setups, multiple wired APs (controller-managed) can also be a strong option; among the choices here, mesh captures the “multi-node” requirement.

Pros: ✅ Extends coverage across a large site ✅ Can reroute around node failures (topology dependent) ✅ Same SSID (sensors auto-connect to nearest node) ✅ Scalable (easily add more nodes later)

Cons: ❌ More complex than a single AP (placement, backhaul, troubleshooting) ❌ Requires powered nodes and ongoing management ❌ Wireless hops can reduce capacity; validate with a site survey and real traffic


Scenario 3: Outdoor Smart Farm → C) Wi-Fi mesh network(but with special considerations)

Why: If you must use Wi-Fi over a wide outdoor area, you’ll likely need powered relay points (solar + storage or mains) and careful antenna placement. In practice, many farms choose LPWAN options (LoRaWAN, NB‑IoT/LTE‑M) because Wi-Fi’s association overhead and always-on relay requirement can be a poor fit for multi-year batteries.


31.4.3 Summary Table:

Scenario Best Wi-Fi choice (given options) Key considerations
Smart Home Single router (A) Start simple; move to multi-node only if you have persistent dead zones
Warehouse Mesh (C) Plan RF placement and backhaul; prefer wired uplinks or dedicated backhaul where possible
Farm Mesh (C), but reconsider Wi-Fi Power availability and maintenance dominate; LPWAN is often a better match

Decision checklist:

  • If a single AP covers the space with good RSSI/SNR → start with infrastructure mode.
  • If you need multiple RF points and want one SSID with simpler management → mesh (or controller-managed wired APs).
  • If you can’t power always-on relays or need multi-year batteries at scale → consider LPWAN instead of Wi-Fi.

31.4.4 📝 Lab Takeaways

After completing this lab, you should understand:

Wi-Fi mesh networking - How multiple nodes self-organize and route messages ✅ Self-healing - Automatic rerouting when nodes fail ✅ Multi-hop communication - Messages relay through intermediate nodes ✅ Root node selection - Importance of reliable power for root ✅ Mesh vs infrastructure - When to use each architecture ✅ ESP32 mesh frameworks - Build a simple mesh with painlessMesh (Arduino) and compare with ESP-IDF ESP-Wi-Fi-MESH

Next Steps:

  • Modify code to add more mesh nodes (test scalability)
  • Simulate node failures (disconnect power to test self-healing)
  • Add MQTT integration (root node publishes to broker)
  • Measure latency across different hop counts
  • Experiment with different mesh topologies (linear, star, grid)

Sammy the Sensor lives in a smart home with lots of friends – Lila the LED, Bella the Battery, and Max the Microcontroller. They all need to talk to the cloud, but they do it in different ways!

Infrastructure Mode is like having a teacher in the classroom. Everyone raises their hand and talks through the teacher (the Wi-Fi router). The teacher makes sure nobody talks at the same time. This works great when the classroom is small – but what if some students are in another building? They cannot hear the teacher!

Wi-Fi Direct is like two friends passing notes to each other during recess. No teacher needed! Sammy can send photos directly to Max’s phone, just like using AirDrop. But this only works between two friends at a time.

Mesh Mode is the coolest one! Imagine the whole school is playing a relay game. If Sammy in the gym needs to send a message to the cloud in the principal’s office, the message gets passed from friend to friend: gym to hallway to cafeteria to office. If one friend goes home sick, the others find a new path – that is called self-healing!

Remember: Mesh is great for covering big areas, but every time a message gets passed to another friend (a “hop”), it takes a little longer and uses up some of the “talking time.” So keep the number of hops small for important messages!

Scenario: A 4-node ESP32 mesh network covers a warehouse. A sensor at the far end sends 1 KB data packets every 10 seconds. Calculate the network bandwidth consumption accounting for multi-hop relaying.

Given:

  • Topology: Linear chain (worst case for hops)
    • Root (wired to internet) → Node A → Node B → Sensor Node C
  • Packet size: 1 KB = 8,192 bits
  • Reporting interval: Every 10 seconds
  • Wi-Fi PHY rate: 54 Mbps (802.11g, realistic ESP32 rate)
  • Protocol overhead: 40% (MAC headers, acks, contention)
  • Effective throughput: 54 × 0.6 = 32.4 Mbps

Step 1: Calculate Data Rate from Sensor

Sensor data rate = Packet size / Interval
                 = 8,192 bits / 10 seconds
                 = 819.2 bits/second
                 ≈ 0.82 kbps (kilobits per second)

Step 2: Count Wireless Transmissions

Each packet must be transmitted once per hop:

Transmission path:
  1. Sensor C → Node B (Hop 1)
  2. Node B → Node A (Hop 2)
  3. Node A → Root (Hop 3)

Total wireless transmissions: 3 (one per hop)

Step 3: Calculate Total Airtime Consumed

Airtime per transmission = Packet size / Effective throughput
                         = 8,192 bits / 32,400,000 bits/sec
                         = 0.253 milliseconds

Total airtime per packet = 0.253 ms × 3 hops = 0.759 ms

Airtime per 10 seconds = 0.759 ms (one packet)
Airtime utilization = 0.759 ms / 10,000 ms × 100%
                    = 0.0076% utilization

Step 4: Calculate Bandwidth Multiplication Factor

Single-hop bandwidth (if sensor direct to Root): 0.82 kbps
Multi-hop bandwidth (3 hops): 0.82 kbps × 3 = 2.46 kbps

Bandwidth multiplier: 3× (equals hop count)

Step 5: Scale to 10 Sensors

Now add 9 more sensors, all at Node C (worst case):

Single sensor: 2.46 kbps total network load
10 sensors: 10 × 2.46 = 24.6 kbps total network load

Network utilization:
  = 24.6 kbps / 32,400 kbps
  = 0.076% (still negligible)

Step 6: Add a Bandwidth-Intensive Device (Camera)

Add 1 security camera at Node C streaming 2 Mbps:

Camera data rate: 2,000 kbps
Multi-hop multiplication: 2,000 × 3 = 6,000 kbps (6 Mbps)

Total network load:
  Sensors: 24.6 kbps
  Camera: 6,000 kbps
  Total: 6,024.6 kbps ≈ 6 Mbps

Network utilization: 6,000 / 32,400 = 18.5% ✓ ACCEPTABLE

Step 7: Analyze Bottlenecks

Where does congestion occur?

Link utilization:
  - Sensor C → Node B: 6 Mbps (18.5% utilized)
  - Node B → Node A: 6 Mbps (must relay everything)
  - Node A → Root: 6 Mbps (must relay everything)

Shared medium problem:
  - All 3 links share the SAME 2.4 GHz channel
  - When Node B transmits, Node A and C must wait
  - When Node A transmits, Node B and C must wait

Effective per-link capacity:
  32.4 Mbps / 3 active transmitters ≈ 10.8 Mbps per link

Per-link utilization: 6 Mbps / 10.8 Mbps = 55.6% ⚠️ MODERATE

Step 8: Determine Maximum Camera Capacity

At what camera bitrate does the mesh saturate?

Conservative utilization target: 50% (allows bursts)
Available bandwidth per link: 32.4 × 0.5 = 16.2 Mbps

With 3 hops:
  Maximum camera bitrate = 16.2 Mbps / 3 = 5.4 Mbps

This supports:
  - 5.4 Mbps camera: 1× camera at 1080p (ideal)
  - 2.0 Mbps camera: 2-3× cameras at 720p
  - 4.0 Mbps camera: 1× camera at 1080p (marginal)

Step 9: Compare Star Topology (Better Design)

If Node A, B, C all connect directly to Root (1 hop):

Sensor bandwidth: 0.82 kbps × 1 hop = 0.82 kbps
Camera bandwidth: 2,000 kbps × 1 hop = 2,000 kbps

Total network load: 2,000.82 kbps ≈ 2 Mbps
Network utilization: 2 / 32.4 = 6.2% ✓ EXCELLENT

Star topology vs Linear chain:
  Bandwidth efficiency: 3× better (no multi-hop penalty)
  Latency: 3× lower (direct to root)
  Reliability: Better (no relay dependencies)

Results Summary:

Configuration Network Load Utilization Camera Limit
10 sensors only (3-hop chain) 24.6 kbps 0.08% N/A
10 sensors + 1 camera (3-hop) 6 Mbps 18.5% (55% per-link) 5.4 Mbps max
10 sensors + 1 camera (star) 2 Mbps 6.2% 16+ Mbps (no multi-hop)

Key Insights:

  1. Multi-hop multiplication: Each hop multiplies bandwidth by (1 + hop_count). 3 hops = 3× more airtime consumed.

  2. Sensor traffic is negligible: Even 10 sensors use <0.1% of network capacity. Mesh hop penalty doesn’t matter for low-rate IoT.

  3. Camera traffic is dominant: A single 2 Mbps camera at 3 hops consumes 18.5% of network capacity—250× more than all sensors combined.

  4. Topology matters: Star topology (1 hop) uses 67% less bandwidth than linear chain (3 hops) for same traffic.

  5. Shared medium is the bottleneck: Single-radio mesh must time-division between backhaul and client traffic, reducing effective capacity.

Design Recommendations:

For sensor-only networks:

  • Linear chains acceptable (hop penalty negligible)
  • Can support 100+ sensors even with 4 hops
  • Battery life is the constraint, not bandwidth

For mixed sensor + camera networks:

  • Keep cameras ≤2 hops from root (star or shallow tree)
  • Use dual-radio or tri-band mesh if cameras need 3+ hops
  • Consider wired Ethernet to camera nodes (eliminates wireless backhaul)

For high-density camera networks:

  • Wired APs mandatory (mesh cannot sustain 10+ cameras)
  • Each camera needs dedicated wired uplink
  • Mesh only for low-bandwidth sensors

Key Insight: Multi-hop mesh is a coverage extension tool, not a capacity multiplier. Each hop adds latency and consumes channel airtime, effectively reducing per-device bandwidth. For bandwidth-intensive applications (cameras, streaming), minimize hops or use wired backhaul. For low-rate sensors, mesh works well even with 4+ hops because the absolute bandwidth consumption remains negligible (<1% utilization).

Common Pitfalls

IBSS mode has no coordinator, limited to 11 Mbps, and breaks down with more than 4-5 devices. For IoT mesh networking, use 802.11s mesh mode or a proper mesh stack like Thread or Zigbee. IBSS is only appropriate for simple two-device connections in controlled environments.

In STA+AP mode, both interfaces must operate on the same channel. If the upstream router uses channel 6, the ESP32 AP mode will also use channel 6, which may not be optimal for devices connecting to it. Plan channel selection accounting for this constraint.

When using AP mode for device configuration, leaving the AP open (no password) allows anyone nearby to connect and access the configuration interface. Always require authentication for AP mode configuration portals, even for temporary provisioning.

Monitor mode captures raw 802.11 frames including management frames from all networks without associating. Promiscuous mode captures data frames but only on the associated network. For Wi-Fi analysis tasks requiring packet capture from unassociated networks, monitor mode is required. Many IoT chipsets do not support monitor mode in firmware.

31.5 Summary

This chapter covered Wi-Fi architecture modes for IoT:

  • Infrastructure Mode: Centralized star topology where an access point manages association and typically provides DHCP/routing/internet access—common in home/office IoT
  • Wi-Fi Direct: Peer-to-peer connections without a traditional router, where one device acts as a temporary soft AP (Group Owner); useful for ad-hoc links and provisioning
  • Wi-Fi Mesh Networks: Multi-hop topology where nodes relay traffic to extend coverage; resilience and reconvergence behavior depend on stack/topology, and backhaul design strongly affects performance
  • Mesh Power Design: Always-on root/relay nodes typically need mains/PoE/solar; battery sensors should be leaf nodes that transmit infrequently and sleep most of the time
  • ESP32 Mesh Implementation: Practical hands-on experience with painlessMesh library for building self-healing mesh networks

31.6 What’s Next

If you want to… Read this
Learn full Wi-Fi architecture and mesh Wi-Fi Architecture and Mesh
Understand Wi-Fi MAC protocols Wi-Fi MAC Layer and Protocols
Implement Wi-Fi with ESP32 Wi-Fi Implementation: ESP32 Basics
Review Wi-Fi fundamentals and standards Wi-Fi Standards Index
Explore Wi-Fi security and provisioning Wi-Fi Security and Provisioning