EAZYLife STEM LAB · MODULE 22

Wireless Communication and IoT Systems

Connect embedded devices to networks. Understand wireless links, network roles, data protocols and security, then build a local sensor dashboard with an ESP32.

Free open lessonWireless systemsIoT architecture
SENSE · CONNECT · EXCHANGE · RESPOND
01 · CONNECTED SYSTEMS

From an embedded controller to an IoT system

An Internet of Things system connects physical devices that measure, report or act on information. A typical node combines sensors, a microcontroller, communication hardware, firmware and a power source. Data may travel to a local computer, gateway or remote service.

Typical IoT data path

SensorControllerWireless linkGatewayApplicationphysical dataprocess / encoderadio / protocolnetwork routingdisplay / actionA gateway is optional when a node connects directly to a network.

Common roles include node, gateway, message broker, server and client.

What makes it useful?

  • A defined physical measurement or control purpose.
  • Reliable operation when connectivity is lost.
  • Clear data format, identity and units.
  • Security, privacy and maintenance planning.
  • A safe local behaviour if remote services fail.

Connectivity alone does not make a product useful. A connected system must also handle missing data, stale readings, power loss and unauthorised commands.

02 · WIRELESS TECHNOLOGIES

Choose the link for the job

Wireless technologies trade range, data rate, power use, cost, infrastructure and complexity differently. No single radio is best for every project.

Wi-Fi

Connects devices to local IP networks and often the internet. Useful for dashboards, updates and moderate-to-high data rates. Usually consumes more energy than low-power sensor links.

Bluetooth Classic and BLE

Classic supports continuous links and serial-style modules. Bluetooth Low Energy is designed for lower average power and short bursts, such as nearby phone configuration or sensor readings.

Zigbee and Thread

Low-power networking for distributed sensor and home-automation nodes. Mesh routing can extend coverage but introduces ecosystem, coordinator or border-router considerations.

LoRa / LoRaWAN and cellular

LoRa supports long-range, low-data-rate telemetry; LoRaWAN adds a network architecture. Cellular offers wide-area connectivity where coverage and a service plan exist, with energy and recurring-cost trade-offs.

TechnologyTypical roleImportant trade-off
Wi-FiLocal IP, dashboards, updatesPower and access-point dependence
BLENearby phone / sensor linksRange and data model
Zigbee / ThreadLow-power distributed nodesNetwork ecosystem
LoRaWANSmall messages over long distancesLow throughput and gateway
CellularWide-area remote assetsCoverage, energy and subscription

Qualitative comparisons only. Actual performance depends on radio, antenna, region, interference and site conditions.

03 · NETWORK BASICS

How devices find each other

Network building blocks

  • Access point: provides Wi-Fi access.
  • SSID: the network name.
  • IP address: identifies an interface on an IP network.
  • DHCP: commonly assigns addresses.
  • DNS: maps names to IP addresses.
  • Router: forwards traffic between networks.
  • Port: identifies a service endpoint.

Local network is not the internet

An ESP32 can serve a dashboard reachable only by devices on the same Wi-Fi network. This is useful for a workshop and does not require publishing the device to the public internet.

Remote access requires additional routing, firewall, service and authentication decisions. A private local IP address is not automatically reachable from outside.

ESP32 nodesensor + serverWi-Fi routeraccess pointPhone / laptopbrowser clientSame local network; internet access is not needed for this practical.

A Wi-Fi connection does not prove internet availability. DNS, routing or a remote server may still be unavailable.

04 · APPLICATION PROTOCOLS

How IoT devices exchange information

HTTP request / response

A client requests a resource and a server responds with a status and data. HTTP is common for web dashboards and REST APIs.

GET /api/reading
HTTP/1.1 200 OK
{"adc": 1840, "voltage": 1.48}

MQTT publish / subscribe

Devices publish messages to topics on a broker. Clients subscribe to topics and receive matching messages. Publishers and subscribers do not need to know each other.

Topic: workshop/node1/temperature
Payload: {"c": 27.4}

WebSocket

Maintains a two-way connection so server and client can exchange updates without a new HTTP request for every message. Useful for live dashboards.

Payload formats

JSON is readable and easy to debug. Compact binary formats can reduce bandwidth. Include units, timestamps, device identity and data-quality information where useful.

Telemetry reports what a device measures. A command asks it to change something. Authenticate command senders, validate values, enforce limits, acknowledge outcomes and log important actions.

05 · INTERACTIVE EXPLORATION

Explore an IoT telemetry stream

Change the simulated sensor value and reporting interval. The model creates a JSON message and estimates payload data rate. It is not a Wi-Fi throughput or battery-life prediction.

Messages / minute12
Payload rate0.7 bps
Payload / day4.1 kB

Example JSON payload

{
  "device": "node-01",
  "sensor": "demo",
  "value": 42,
  "unit": "%",
  "sequence": 1
}

Counts this JSON payload only. Excludes Wi-Fi, TCP/IP, encryption, retries and acknowledgements.

06 · PRACTICAL BUILD

Build an ESP32 local sensor dashboard

The ESP32 reads a potentiometer and serves a small web page over local Wi-Fi. A phone or laptop on the same network opens the ESP32's local IP address and sees live readings. The ESP32 is both sensor controller and HTTP server.

What you need

  • ESP32 development board with Wi-Fi.
  • 10 kΩ linear potentiometer.
  • Breadboard and jumper wires.
  • USB data cable and Arduino IDE with ESP32 board support.
  • Authorised 2.4 GHz Wi-Fi network or compatible private hotspot.
  • Phone or laptop browser on the same network.

Wiring diagram

ESP323V3GPIO34 / ADCGND10 kΩ pot3 terminals3.3 VWiperGND
  • Pot outer terminal 1 → 3V3.
  • Pot outer terminal 2 → GND.
  • Centre wiper → GPIO34 on common original ESP32 DevKit boards.
  • Never apply 5 V to an ESP32 GPIO.

ESP32 variants differ. Confirm the exact pinout and ADC-capable pins for your board. GPIO34 is input-only on the original ESP32 family and may not exist or map identically on other variants. Keep inputs within the board's specified voltage range.

Arduino sketch: local HTTP sensor server

Install ESP32 board support, select the correct board and port, enter your own Wi-Fi credentials locally, then upload. Never publish real credentials in a public repository.

#include <WiFi.h>
#include <WebServer.h>

// Keep real credentials private and out of public source control.
const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
const int SENSOR_PIN = 34; // Verify for your exact board.
WebServer server(80);

const char PAGE[] PROGMEM = R"HTML(
<!doctype html><html><head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>ESP32 Sensor</title></head><body>
<h1>ESP32 Local Sensor</h1>
<p>ADC: <strong id="adc">--</strong></p>
<p>Voltage estimate: <strong id="volts">--</strong> V</p>
<script>
async function updateReading() {
  try {
    const response = await fetch('/api/reading', {cache:'no-store'});
    if (!response.ok) throw new Error('HTTP ' + response.status);
    const data = await response.json();
    document.getElementById('adc').textContent = data.adc;
    document.getElementById('volts').textContent = data.voltage.toFixed(2);
  } catch (error) {
    document.getElementById('adc').textContent = 'Connection lost';
  }
}
updateReading();
setInterval(updateReading, 1000);
</script></body></html>
)HTML";

void handleRoot() { server.send_P(200, "text/html", PAGE); }

void handleReading() {
  int raw = analogRead(SENSOR_PIN);
  // Nominal scale only; not a calibrated measurement.
  float voltage = (raw / 4095.0f) * 3.3f;
  String json = "{\"adc\":" + String(raw) +
                ",\"voltage\":" + String(voltage, 3) + "}";
  server.send(200, "application/json", json);
}

void setup() {
  Serial.begin(115200);
  analogReadResolution(12);
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("Connecting");
  unsigned long started = millis();
  while (WiFi.status() != WL_CONNECTED &&
         millis() - started < 20000UL) {
    delay(300);
    Serial.print(".");
  }
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("\nWi-Fi connection failed. Check credentials and network.");
    return;
  }
  Serial.println("\nConnected. Open this address on the same network:");
  Serial.println(WiFi.localIP());
  server.on("/", HTTP_GET, handleRoot);
  server.on("/api/reading", HTTP_GET, handleReading);
  server.begin();
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) server.handleClient();
}
Implementation notes
  • The voltage formula uses a nominal 3.3 V / 4095 scale. ESP32 ADC response depends on chip, attenuation, calibration and board design; it is not a precision voltmeter.
  • The example waits for Wi-Fi during setup. Production firmware should use non-blocking connection management, reconnect backoff and a clear offline state.
  • The server has no authentication and is for a trusted isolated learning network only. Never expose it publicly or use it to control hazardous equipment.
  • Some networks isolate wireless clients, preventing a phone from reaching the ESP32.

Build and test in stages

  1. With power disconnected, identify the potentiometer terminals.
  2. Power the ESP32 from USB and verify the wiper remains between GND and 3.3 V.
  3. Upload the sketch with your own credentials. Open Serial Monitor at 115200 baud.
  4. Read the local IP printed by the board. Connect the phone/laptop to the same network and enter the address in a browser.
  5. Turn the potentiometer and confirm the ADC and voltage estimate update.
  6. Disconnect Wi-Fi, observe failure, reconnect and consider how robust firmware should recover.

Troubleshooting

  • Wi-Fi fails: check credentials, 2.4 GHz support, signal and network restrictions.
  • Browser cannot connect: check IP address, same network, client isolation and server startup.
  • ADC stays fixed: check wiper, ground, ADC pin and board variant.
  • Reading is noisy: inspect wiring, use suitable averaging and avoid long floating signal wires.
  • Voltage differs from a meter: ADC scaling is approximate and needs calibration.

Extension challenges

  • Replace the potentiometer with an LDR divider or digital sensor.
  • Add timestamp and device identity to the JSON response.
  • Build an MQTT version using a private broker and device-specific topic.
  • Add a reconnect state machine and stale-data indicator.
  • Add authenticated access and role-limited commands before remote control.
07 · KNOWLEDGE CHECK

Check your understanding

1. What is the main role of an IoT gateway?

2. What distinguishes MQTT publish/subscribe?

3. Why use a 3.3 V potentiometer supply?

4. Is a device on Wi-Fi necessarily reachable from the public internet?

08 · SECURITY AND RELIABILITY

Connected devices need responsible design

Protect devices and networks

  • Change default credentials and use unique passwords.
  • Use HTTPS or secure MQTT/TLS on untrusted networks.
  • Authenticate clients and restrict read/write permissions.
  • Keep Wi-Fi credentials, API keys and certificates out of public repositories.
  • Update firmware through a controlled process and disable unused services.

Plan for failure and privacy

  • Define behaviour when Wi-Fi, DNS, broker or server is unavailable.
  • Do not treat stale telemetry as a current measurement.
  • Validate commands and enforce local limits.
  • Collect only necessary data and protect personal/location information.
  • Provide safe local mode and manual override where physical control is involved.

Threat modelling, secure provisioning, logging, maintenance and recovery are engineering requirements, not finishing touches.

KEEP LEARNING · GO FURTHER

Free to learn. More support when you need it.

Explore these open lessons at your own pace. For personalised explanations, project-specific troubleshooting, guided practical training or masterclasses, EazyLife offers paid support tailored to your learning goals.

Free or sponsored lesson referrals may be available through active programmes; they are not guaranteed.

Enquire about guidance