818  Mobile Labs: Wi-Fi Spectrum Analysis

818.1 Learning Objectives

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

  • Run an RF site survey: Use Wi-Fi scanners to identify interference and congestion in your environment
  • Select optimal Wi-Fi channels: Choose non-overlapping channels (1, 6, 11) and justify a channel plan from measurements
  • Implement an ESP32 scanner: Build tools to inventory nearby networks and visualize channel occupancy
  • Measure signal quality: Collect RSSI vs distance data and explain deviations from theoretical path loss
  • Document findings: Produce a site-survey report with recommendations for channels, placement, and risks

818.2 Prerequisites

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

Deep Dives: - Wi-Fi Fundamentals - 802.11 standards and protocols - Wi-Fi IoT Implementations - Practical Wi-Fi deployments - Mobile Labs: Coverage Planning - Python tools for deployment planning

Comparisons: - Mobile Wireless Comprehensive Review - Technology comparison matrix

Hands-On: - Simulations Hub - RF propagation simulators - Quizzes Hub - Test mobile wireless knowledge

818.3 Getting Started (For Beginners)

These labs are about making the RF concepts from the fundamentals chapters visible in the real world.

  • If you have an ESP32 and can install tools:
    • Run the Wi-Fi scanner, collect RSSI measurements at different locations, and build a simple channel plan.
    • Use the exercises to connect what you see on the screen with ideas like channel congestion and path loss.
  • If you cannot run the code right now:
    • Read through the sketches and focus on the printed outputs and analysis questions.
    • Sketch simple “coverage maps” on paper based on the example outputs, then answer the Knowledge Check.

Key ideas to remember while working through this chapter:

Concept Plain explanation
Channel A slice of spectrum; multiple Wi-Fi networks share it
RSSI Received signal strength indicator (how loud the AP is)
Interference Other devices transmitting on the same/adjacent channel
Path loss How much signal power is lost as distance increases

If terms like RSSI, path loss, or channel overlap feel unfamiliar, skim mobile-wireless-fundamentals.qmd again, then come back and treat these labs as concrete experiments that bring those graphs and formulas to life.

818.4 Hands-On Lab: RF Spectrum Analysis

818.4.1 Lab Objective

Use Wi-Fi scanner tools to analyze the wireless environment and identify interference sources.

818.4.2 Equipment Needed

  • ESP32 development board (built-in Wi-Fi)
  • Arduino IDE
  • Computer with USB connection
  • Optional: smartphone Wi-Fi analyzer app and/or an SDR (e.g., RTL-SDR) for broader spectrum viewing
CautionEthics and Safety

Run scans only in environments you own or have explicit permission to assess. This lab focuses on passive observations (SSID/channel/RSSI) and planning - not capturing traffic or accessing networks.

818.4.3 Wi-Fi Scanner Lab Workflow

Understanding the complete workflow from hardware setup to data analysis ensures successful lab implementation.

%%{init: {'theme': 'base', 'themeVariables': {'primaryColor':'#2C3E50','primaryTextColor':'#fff','primaryBorderColor':'#16A085','lineColor':'#16A085','secondaryColor':'#E67E22','tertiaryColor':'#ecf0f1','textColor':'#2C3E50','fontSize':'14px'}}}%%
flowchart TD
    START["Hardware Setup:<br/>Connect ESP32"] --> CODE["Load Wi-Fi<br/>Scanner Code"]
    CODE --> COMPILE["Compile &<br/>Upload"]
    COMPILE --> CHECK1{"Upload<br/>Success?"}

    CHECK1 -->|No| DEBUG["Check connections<br/>& COM port"]
    DEBUG --> CODE
    CHECK1 -->|Yes| SCAN1["Scan Location 1<br/>(Record RSSI)"]

    SCAN1 --> SCAN2["Scan Location 2<br/>(Record RSSI)"]
    SCAN2 --> SCAN3["Scan Locations 3-5<br/>(Record RSSI)"]
    SCAN3 --> ANALYZE["Analyze Data:<br/>Channel congestion<br/>Path loss<br/>Dead zones"]

    ANALYZE --> VIZ["Create Visualization:<br/>Heatmap<br/>Bar charts"]
    VIZ --> REC["Generate<br/>Recommendations"]
    REC --> VERIFY["Verify Knowledge<br/>Check Questions"]

    VERIFY --> END["Lab Complete"]

    style START fill:#E67E22,stroke:#2C3E50,color:#fff
    style CODE fill:#16A085,stroke:#2C3E50,color:#fff
    style COMPILE fill:#16A085,stroke:#2C3E50,color:#fff
    style CHECK1 fill:#2C3E50,stroke:#16A085,color:#fff
    style DEBUG fill:#E67E22,stroke:#2C3E50,color:#fff
    style SCAN1 fill:#16A085,stroke:#2C3E50,color:#fff
    style SCAN2 fill:#16A085,stroke:#2C3E50,color:#fff
    style SCAN3 fill:#16A085,stroke:#2C3E50,color:#fff
    style ANALYZE fill:#2C3E50,stroke:#16A085,color:#fff
    style VIZ fill:#16A085,stroke:#2C3E50,color:#fff
    style REC fill:#16A085,stroke:#2C3E50,color:#fff
    style VERIFY fill:#2C3E50,stroke:#16A085,color:#fff
    style END fill:#E67E22,stroke:#2C3E50,color:#fff

Figure 818.1

818.5 Task 1: Wi-Fi Channel Scanner

Create a tool to scan all 2.4 GHz Wi-Fi channels and identify the least congested channel:

#include <WiFi.h>

void setup() {
    Serial.begin(115200);
    WiFi.mode(WIFI_STA);
    WiFi.disconnect();
    delay(100);
    Serial.println("\n\nWi-Fi Channel Scanner");
    Serial.println("=====================");
}

void loop() {
    Serial.println("\nScanning Wi-Fi networks...");

    // Scan for networks
    int n = WiFi.scanNetworks();

    // Create channel usage array
    int channelCount[15] = {0};  // index 1..13 (2.4 GHz); keep 14 safe for region-specific cases

    if (n == 0) {
        Serial.println("No networks found");
    } else {
        Serial.printf("Found %d networks:\n\n", n);
        Serial.println("SSID                             | RSSI | Ch | Encryption");
        Serial.println("-----------------------------------------------------------------");

        for (int i = 0; i < n; i++) {
            int channel = WiFi.channel(i);
            if (channel >= 1 && channel <= 14) {
                channelCount[channel]++;
            }

            Serial.printf("%-32s | %4d | %2d | %s\n",
                WiFi.SSID(i).c_str(),
                WiFi.RSSI(i),
                channel,
                getEncryptionType(WiFi.encryptionType(i)));
        }

        // Analyze channel congestion
        Serial.println("\n\nChannel Congestion Analysis:");
        Serial.println("============================");
        for (int ch = 1; ch <= 13; ch++) {
            Serial.printf("Channel %2d: ", ch);
            for (int i = 0; i < channelCount[ch]; i++) {
                Serial.print("█");
            }
            Serial.printf(" (%d networks)\n", channelCount[ch]);
        }

        // Find least congested channel (from 1, 6, 11)
        int channels[] = {1, 6, 11};
        int minCount = 999;
        int bestChannel = 1;

        for (int i = 0; i < 3; i++) {
            if (channelCount[channels[i]] < minCount) {
                minCount = channelCount[channels[i]];
                bestChannel = channels[i];
            }
        }

        Serial.printf("\nRecommended channel: %d (%d networks)\n",
                      bestChannel, minCount);
    }

    delay(10000);  // Scan every 10 seconds
}

String getEncryptionType(wifi_auth_mode_t encryptionType) {
    switch (encryptionType) {
        case WIFI_AUTH_OPEN:
            return "Open";
        case WIFI_AUTH_WEP:
            return "WEP";
        case WIFI_AUTH_WPA_PSK:
            return "WPA-PSK";
        case WIFI_AUTH_WPA2_PSK:
            return "WPA2-PSK";
        case WIFI_AUTH_WPA_WPA2_PSK:
            return "WPA/WPA2-PSK";
        case WIFI_AUTH_WPA2_ENTERPRISE:
            return "WPA2-Enterprise";
#ifdef WIFI_AUTH_WPA3_PSK
        case WIFI_AUTH_WPA3_PSK:
            return "WPA3-PSK";
#endif
#ifdef WIFI_AUTH_WPA2_WPA3_PSK
        case WIFI_AUTH_WPA2_WPA3_PSK:
            return "WPA2/WPA3-PSK";
#endif
        default:
            return "Unknown";
    }
}

818.5.1 Understanding Channel Selection

The 2.4 GHz Wi-Fi band has 14 channels (13 in most regions), but each channel is 20-22 MHz wide while channels are spaced only 5 MHz apart. This means channels overlap:

%%{init: {'theme': 'base', 'themeVariables': {'primaryColor':'#2C3E50','primaryTextColor':'#fff','primaryBorderColor':'#16A085','lineColor':'#16A085','secondaryColor':'#E67E22','tertiaryColor':'#ecf0f1','textColor':'#2C3E50','fontSize':'14px'}}}%%
graph LR
    subgraph BAND["2.4 GHz Band (2400-2483.5 MHz)"]
        C1["Ch 1<br/>2412 MHz"]
        C6["Ch 6<br/>2437 MHz"]
        C11["Ch 11<br/>2462 MHz"]
    end

    C1 ---|"25 MHz gap"| C6
    C6 ---|"25 MHz gap"| C11

    style C1 fill:#16A085,stroke:#2C3E50,color:#fff
    style C6 fill:#E67E22,stroke:#2C3E50,color:#fff
    style C11 fill:#2C3E50,stroke:#16A085,color:#fff

Figure 818.2

Why only 1, 6, and 11?

  • These channels are 25 MHz apart (5 channels × 5 MHz spacing)
  • With 20 MHz channel width, they don’t overlap
  • Using channel 3 would interfere with both 1 and 6
  • In regions allowing channels 12-13, alternative schemes like 1/5/9/13 are possible

818.6 Task 2: Signal Strength Mapping

Modify the scanner to create a heat map of signal strength at different locations:

  1. Take measurements at 5-10 locations in your environment
  2. Record RSSI for each channel
  3. Create a simple visualization showing signal strength patterns
  4. Identify dead zones and interference sources

818.6.1 Data Collection Template

Location Distance (m) RSSI (dBm) Ch 1 Networks Ch 6 Networks Ch 11 Networks
Near AP 1 -35 2 3 1
Office 5 -55 2 4 1
Hallway 10 -68 3 5 2
Far room 20 -78 4 6 2
Basement 25 -85 5 7 3

818.7 Task 3: Path Loss Measurements

  1. Set up two ESP32 boards (one as AP, one as client)
  2. Measure RSSI at distances: 1m, 5m, 10m, 20m
  3. Calculate observed path loss
  4. Compare with theoretical free space path loss
  5. Identify factors causing deviation (walls, furniture, interference)

818.7.1 Path Loss Analysis Code

#include <WiFi.h>

// Target network to measure
const char* targetSSID = "YourTestAP";

void setup() {
    Serial.begin(115200);
    WiFi.mode(WIFI_STA);
    WiFi.disconnect();
    delay(100);

    Serial.println("\n\nPath Loss Measurement Tool");
    Serial.println("==========================");
    Serial.println("Move to different distances and press Enter to measure");
}

void loop() {
    if (Serial.available()) {
        Serial.read();  // Clear input

        Serial.println("\nScanning...");
        int n = WiFi.scanNetworks();

        bool found = false;
        for (int i = 0; i < n; i++) {
            if (WiFi.SSID(i) == targetSSID) {
                found = true;
                int rssi = WiFi.RSSI(i);

                Serial.printf("Network: %s\n", targetSSID);
                Serial.printf("RSSI: %d dBm\n", rssi);
                Serial.printf("Channel: %d\n", WiFi.channel(i));

                // Calculate path loss (assuming TX power of 20 dBm)
                int txPower = 20;  // Typical ESP32 TX power
                int pathLoss = txPower - rssi;
                Serial.printf("Observed Path Loss: %d dB\n", pathLoss);

                // Compare with FSPL at 2.4 GHz
                Serial.println("\nTheoretical FSPL at 2.4 GHz:");
                Serial.println("  1m:  40 dB");
                Serial.println("  5m:  54 dB");
                Serial.println(" 10m:  60 dB");
                Serial.println(" 20m:  66 dB");

                break;
            }
        }

        if (!found) {
            Serial.printf("Network '%s' not found\n", targetSSID);
        }
    }

    delay(100);
}

818.8 Analysis Questions

After completing the lab tasks, answer these questions:

  1. Which 2.4 GHz channels are most congested in your environment?
  2. What is the RSSI difference between 1m and 10m measurements?
  3. How does the observed path loss compare to the theoretical value?
  4. Can you identify specific interference sources (e.g., microwave ovens, Bluetooth devices)?

818.9 Deliverable: Mini Site-Survey Report

NoteReport Template (1-2 pages)

Use this template to turn measurements into deployment decisions:

1. Environment Description - Location, obstacles, expected device density - Constraints (power, mounting, regulations)

2. Measurement Plan - Where you measured, tools used, time of day - Duration of measurements

3. Channel Occupancy - Top networks by RSSI - Channel histogram (2.4 GHz) - Recommended channel (1/6/11)

4. Coverage Notes - RSSI vs distance observations - Suspected blockers (walls, metal, etc.) - Dead zones identified

5. Recommendations - Channel selection justification - AP placement suggestions - Coexistence risks (Bluetooth/Zigbee/microwave)

6. Validation Plan - What to re-measure after changes - Latency, packet loss, RSSI stability metrics

818.10 Knowledge Check: RF Spectrum Analysis

Test your understanding of RF spectrum analysis and channel planning:

Question 1: When scanning for the best Wi-Fi channel in a crowded environment, why should you only consider channels 1, 6, and 11 in the 2.4 GHz band?

Explanation: In the 2.4 GHz band, 20/22 MHz-wide Wi-Fi channels are spaced 5 MHz apart, so most channel numbers partially overlap. In many deployments (especially where only channels 1-11 are used), channels 1, 6, and 11 are the common non-overlapping set for 20 MHz operation. If channels 12/13 are available in your regulatory domain, some planners consider other schemes (e.g., 1/5/9/13) depending on channel width and tolerance for adjacent-channel interference. The key idea is to pick channels with enough separation to minimize overlap and validate the choice with measurements.

Question 2: Your ESP32 Wi-Fi scanner shows RSSI values of -45 dBm at 1 meter and -75 dBm at 10 meters from the access point. What does this 30 dB difference indicate about the environment?

Explanation: Free-space path loss at 2.4 GHz from 1m to 10m would be approximately 20 dB (using FSPL formula: 20*log10(10/1) = 20 dB). Observing 30 dB of loss indicates an additional 10 dB from environmental factors like walls, furniture, human bodies, or reflections. This is typical for indoor environments. Understanding this deviation helps you plan realistic coverage and identify obstruction sources.

Question 3: You need to deploy IoT sensors in a metal-rich industrial factory. Your link budget analysis shows 2.4 GHz has -5 dB margin (insufficient) while 868 MHz has +9 dB margin (adequate). Why does sub-GHz perform better in this environment?

Explanation: At the same distance, sub-GHz frequencies experience approximately 9 dB less free-space path loss than 2.4 GHz (following the FSPL formula where loss increases with frequency). Additionally, longer wavelengths (34 cm at 868 MHz vs 12 cm at 2.4 GHz) diffract around metal obstacles more effectively. This combination gives sub-GHz a significant “link budget advantage” in challenging industrial environments. Transmit power limits are similar, and neither band has exclusive spectrum.

Question 4: Approximately how many dB less free-space path loss does 868 MHz have compared to 2.4 GHz at the same distance?

dB

Explanation: FSPL increases with frequency: ΔFSPL = 20·log10(f2/f1). For 2.4 GHz vs 868 MHz, 20·log10(2.4/0.868) ≈ 8.8 dB (≈ 9 dB).

Question 5: Which items belong in a practical Wi-Fi site-survey report? (Select ALL that apply.)

Explanation: A good site survey turns measurements into a deployment decision: how you measured, what you saw (occupancy/RSSI), what you recommend, and how you will confirm it worked.

818.11 Understanding Check: Industrial Scenario

Scenario: An automotive factory needs to monitor 300 sensors across a 500m x 200m production floor with: overhead metal cranes, stamping presses (heavy RF noise), thick concrete support columns, and conveyor systems. Each sensor reports machine vibration, temperature, and throughput (combined 10 kbps data rate). Existing 2.4 GHz Wi-Fi network experiences 15-30% packet loss in metalworking areas. Factory operates 24/7 with zero downtime tolerance.

Think about:

  1. Why does free-space path loss at 500m differ by 9 dB between 868 MHz and 2.4 GHz?
  2. How do longer sub-GHz wavelengths (34 cm) diffract around metal machinery better than 2.4 GHz (12 cm)?
  3. What’s the link budget margin when your path loss approaches receiver sensitivity limits?

Key Insight: At the same distance, 868 MHz has ~9 dB less free-space path loss than 2.4 GHz. In cluttered industrial spaces, that difference can translate into meaningful link-margin headroom, but the actual margin depends on your radios and the environment.

Illustrative link budget at 500 m (replace these numbers with your datasheet + measurements):

Transmit EIRP: +10 dBm (example)
Receiver sensitivity: -110 dBm (example)
Link budget: 120 dB

Free-space path loss at 500 m:
- 868 MHz: ~85 dB
- 2.4 GHz: ~94 dB  (≈9 dB higher)

Assume additional losses (clutter + fading margin):
- 868 MHz: +26 dB → total loss ~111 dB → margin ~+9 dB ✓
- 2.4 GHz: +31 dB → total loss ~125 dB → margin ~-5 dB ✗

Why sub-GHz can help:

  • Lower FSPL at the same distance and often better diffraction in cluttered environments
  • More link margin for the same EIRP and receiver sensitivity (radio-dependent)
  • Trade-off: typically lower data rates; confirm your workload fits

Verify Your Understanding:

  • If you increased transmit power to +20 dBm, would 2.4 GHz become viable? Calculate the new link margin.
  • How would you use the Wi-Fi scanner lab to measure actual 2.4 GHz congestion in your factory deployment area?

Quick calculation: If the 2.4 GHz link margin is -5 dB at +10 dBm TX power, what is the new margin if you increase TX power to +20 dBm (all else equal)?

dB

Explanation: +10 dB TX power increases link margin by +10 dB. New margin = -5 dB + 10 dB = +5 dB (viable but still needs fade margin in practice).

818.12 Summary

This chapter provided hands-on experience with Wi-Fi spectrum analysis:

  • Wi-Fi channel scanning turns spectrum congestion into actionable channel plans (1/6/11) for 2.4 GHz deployments
  • Channel overlap understanding helps you avoid interference from adjacent channels
  • RSSI measurements at multiple locations reveal coverage patterns and dead zones
  • Path loss comparison between theoretical and measured values identifies environmental obstacles
  • Site survey reports document findings and provide actionable deployment recommendations

818.13 What’s Next

With RF analysis skills established, continue your wireless IoT journey with: