ESP32 & the Internet of Things

Understanding Communication Protocols and Sending Sensor Data to the Cloud with ThingSpeak

1. Introduction

Building a real IoT product usually involves several protocols working together — from the sensor to the microcontroller, and finally from the microcontroller to the cloud. To keep things simple, this guide assumes you already have a network-connected device (an ESP32) with a valid IP address obtained through a Wi-Fi router, and it already has internet connectivity.

The focus here is purely on the last leg of the journey: how the ESP32 talks to a cloud platform once it is online.

ESP32 Wi-Fi Router Internet HTTP / MQTT / CoAP
Fig. 1 — Data path from ESP32 to the cloud, passing through a Wi-Fi router and an internet-facing protocol.

2. The Three Popular IoT Protocols

When an ESP32 needs to push sensor data to a cloud service, it almost always uses one of three well-known application-layer protocols:

HTTP / HTTPS

The classic web protocol. Uses simple GET and POST requests. Very easy to implement, but has a larger message overhead and is the slowest of the three.

MQTT

Message Queuing Telemetry Transport. A lightweight publish/subscribe protocol, the most widely used general-purpose protocol for IoT devices.

CoAP

Constrained Application Protocol. A specialized, very low-latency protocol used in constrained networks where speed and small packet size matter most.

HTTP / HTTPS in Detail

HTTP (HyperText Transfer Protocol) and its secure version HTTPS are by far the simplest protocols to work with. Data is exchanged using standard request types such as GET and POST. The main drawback is that the header/message size for each request-response cycle is larger than the other two protocols, which also makes HTTP the slowest option for frequent, real-time data transfer.

MQTT in Detail

MQTT is a lightweight, broker-based messaging protocol built around a publish/subscribe model. Devices "publish" data to a topic, and any number of subscribers (dashboards, other devices, cloud services) can "listen" to that topic. Because the header overhead is tiny compared to HTTP, MQTT is considered the most popular and general-purpose protocol for IoT applications.

CoAP in Detail

CoAP is designed for constrained devices and constrained networks, targeting scenarios where very low latency is critical. It is less commonly used than MQTT for general purpose projects but shines in specialized, real-time control systems.

3. Quick Comparison

Protocol Model Overhead Speed Best For
HTTP / HTTPS Request / Response High Slow Simple, low-frequency data logging
MQTT Publish / Subscribe Low Fast General-purpose IoT, real-time dashboards
CoAP Request / Response (UDP-based) Very Low Very Fast Ultra-low-latency, constrained networks
For most beginner and intermediate ESP32 projects, HTTP is the easiest starting point, and MQTT is the natural next step once you need efficiency and scalability.

4. Meet ThingSpeak

ThingSpeak is a cloud platform built specifically for IoT projects. Its free tier supports data transfer over HTTP, and paid tiers add MQTT support as well.

Each ThingSpeak channel gives you up to 8 data fields, so a single channel could, for example, log temperature, humidity, pressure, and several other readings for a home-automation or industrial-automation project simultaneously.

On the free plan, updates are limited — you cannot send data more frequently than roughly every 15 seconds.
ThingSpeak Channel Field 1: Temp Field 2: Humidity Field 3: ... Field 4-8 Up to 8 fields per channel — perfect for multi-sensor projects
Fig. 2 — A single ThingSpeak channel can host up to 8 independent data fields.

5. Creating Your First ThingSpeak Channel

  1. Go to the ThingSpeak website and click Sign In.
  2. If you don't have an account, click Create One and provide your email, location, first name, and last name.
  3. Check your email and click the verification link, then set a password.
  4. Log in with your new credentials.
  5. From the dashboard, click New Channel.
  6. Give your channel a name, e.g. "IoT Project 1".
  7. Add a short description such as "Temperature and humidity monitoring" (optional).
  8. Enable Field 1 and name it Temperature.
  9. Enable Field 2 and name it Humidity.
  10. Leave the remaining settings at their defaults.
  11. Click Save Channel.
As soon as you save the channel, ThingSpeak automatically generates a dashboard with empty charts — one per active field — ready to display data the moment you start sending it.

6. Sending Data to ThingSpeak with a Simple HTTP Request

Every channel has a unique Write API Key, found under the API Keys tab of the channel. This key lets any device — even a web browser — push data into your channel fields using a plain HTTP GET request.

Basic URL Structure

https://api.thingspeak.com/update?api_key=YOUR_API_KEY&field1=VALUE

Step-by-Step Test (from a browser)

  1. Open the API Keys tab of your channel.
  2. Copy your Write API Key.
  3. Open any web browser.
  4. Paste the update URL and replace the key with your own.
  5. Set field1 to a sample temperature value.
  6. Press Enter to send the request.
  7. Check the response — a returned number greater than 0 means success.
  8. Go back to your channel dashboard to see the new data point plotted.

Example Requests

Sending a single temperature reading of 11.5°C:

https://api.thingspeak.com/update?api_key=YOUR_API_KEY&field1=11.5

Sending both temperature and humidity together:

https://api.thingspeak.com/update?api_key=YOUR_API_KEY&field1=25.3&field2=74

Updating both values again a little later:

https://api.thingspeak.com/update?api_key=YOUR_API_KEY&field1=25.8&field2=77
ThingSpeak's free tier only accepts one update roughly every 15 seconds. Sending requests faster than that will simply be ignored, so don't panic if a rapid second request doesn't show up immediately.
This browser test is exactly what your ESP32 sketch will do automatically — instead of you typing the URL, the ESP32's Wi-Fi + HTTP client code will build and send this same GET request using real sensor readings.

7. What's Next?

What you have built so far is a "bare-bones" IoT project — no hardware, no sensors, just a channel that accepts numbers. The next step is to replace the manually-typed browser URL with real code running on the ESP32, reading live values from sensors (such as a DHT11/DHT22 for temperature and humidity) and automatically sending them to ThingSpeak over Wi-Fi using HTTP, and later, MQTT.

Coming Up

  • Wiring a temperature/humidity sensor to the ESP32
  • Writing Arduino/ESP-IDF code to connect to Wi-Fi
  • Sending sensor readings automatically via HTTP GET
  • Switching to MQTT for faster, lighter updates
  • Visualizing data with ThingSpeak widgets and apps