Building a ThingSpeak weather dashboard with ESP32 and sensor data upload is one of the best ways for Indian makers to visualise and share environmental monitoring data online for free. ThingSpeak is MathWorks’ IoT analytics platform that offers free hosting for up to 8 channels, with MATLAB-powered visualisation and built-in alerts. This tutorial shows you how to connect an ESP32 reading BME280 weather data to ThingSpeak, create live dashboards, and set up email alerts when temperature or humidity crosses critical thresholds.
Table of Contents
- What is ThingSpeak and Why Use It?
- Setting Up Your ThingSpeak Channel
- Hardware Components Required
- ESP32 Code for ThingSpeak Upload
- Creating a Weather Dashboard
- Setting Up ThingTweet and Email Alerts
- MATLAB Analysis for Weather Data
- Frequently Asked Questions
What is ThingSpeak and Why Use It?
ThingSpeak (thingspeak.com) is a free IoT platform owned by MathWorks that allows devices to send sensor data over HTTP or MQTT and visualise it on customisable dashboards. Unlike Blynk or Cayenne, ThingSpeak is particularly powerful because of its integrated MATLAB analytics capabilities, allowing you to perform statistical analysis, create MATLAB Visualisations, and run automated analysis scripts on your weather data.
Free tier limitations to be aware of:
- Maximum 8 channels per account
- Minimum 15-second interval between data updates
- 3 million messages per year (approximately 6 messages per minute on average)
- Data stored indefinitely (previously 60 days; now unlimited for free accounts)
For most Indian hobbyist weather stations logging every minute or every 5 minutes, the free tier is more than adequate.
Setting Up Your ThingSpeak Channel
- Go to thingspeak.com and create a free account using your email
- Click Channels → New Channel
- Name your channel (e.g., “Bangalore Rooftop Weather Station”)
- Enable the fields you want to log:
- Field 1: Temperature (°C)
- Field 2: Humidity (%)
- Field 3: Pressure (hPa)
- Field 4: Heat Index (°C)
- Click Save Channel
- Note your Channel ID and Write API Key from the API Keys tab
Your Write API Key is a 16-character alphanumeric string like XXXXXXXXXXXXXXXX. Keep this private—anyone with this key can write data to your channel.
Hardware Components Required
- ESP32 development board
- BME280 sensor (I2C version)
- Jumper wires
- USB power supply or 5V adapter
- Wi-Fi network with internet access (2.4GHz; ESP32 does not support 5GHz Wi-Fi)
ESP32 Code for ThingSpeak Upload
Install the following libraries via Arduino IDE Library Manager:
- Adafruit BME280 Library
- Adafruit Unified Sensor
- ThingSpeak (by MathWorks)
#include <WiFi.h>
#include <Wire.h>
#include <Adafruit_BME280.h>
#include "ThingSpeak.h"
// WiFi credentials
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
// ThingSpeak settings
unsigned long channelID = 1234567; // Replace with your channel ID
const char* writeAPIKey = "XXXXXXXXXXXXXXXX"; // Replace with your Write API Key
Adafruit_BME280 bme;
WiFiClient client;
float calculateHeatIndex(float temp, float humidity) {
// Steadman's heat index formula
return -8.78469475556 + 1.61139411 * temp + 2.33854883889 * humidity
- 0.14611605 * temp * humidity - 0.012308094 * temp * temp
- 0.016424828 * humidity * humidity + 0.002211732 * temp * temp * humidity
+ 0.00072546 * temp * humidity * humidity
- 0.000003582 * temp * temp * humidity * humidity;
}
void setup() {
Serial.begin(115200);
Wire.begin();
if (!bme.begin(0x76)) {
Serial.println("BME280 not found!");
while (1);
}
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("nConnected! IP: " + WiFi.localIP().toString());
ThingSpeak.begin(client);
}
void loop() {
float temp = bme.readTemperature();
float humidity = bme.readHumidity();
float pressure = bme.readPressure() / 100.0F;
float heatIndex = calculateHeatIndex(temp, humidity);
ThingSpeak.setField(1, temp);
ThingSpeak.setField(2, humidity);
ThingSpeak.setField(3, pressure);
ThingSpeak.setField(4, heatIndex);
int responseCode = ThingSpeak.writeFields(channelID, writeAPIKey);
if (responseCode == 200) {
Serial.printf("Uploaded: T=%.1f°C H=%.1f%% P=%.1fhPa HI=%.1f°Cn",
temp, humidity, pressure, heatIndex);
} else {
Serial.println("Error: " + String(responseCode));
}
delay(60000); // Upload every 60 seconds
}
Creating a Weather Dashboard
ThingSpeak offers several widget types for dashboard creation:
- Line Chart: Show temperature or humidity trends over time. Go to your channel, click Add Widgets → Chart → select your field. Configure the time range (last hour, day, week) and styling.
- Gauge: Show current value as a circular gauge. Ideal for humidity (0–100%) and temperature. Set min/max and colour zones for visual alerts.
- Numeric Display: Show the latest reading as a large number. Good for pressure readings.
- Maps: Show your station’s location on a map (requires latitude/longitude upload).
To make your dashboard public (shareable), go to Channel Settings → check “Make Public” → save. You can then share the URL thingspeak.com/channels/YOUR_CHANNEL_ID with anyone without them needing a ThingSpeak account.
Setting Up ThingTweet and Email Alerts
ThingSpeak’s React feature runs conditions when data arrives and triggers actions:
- Click Apps → React → New React
- Set Condition Type: Numeric
- Test Frequency: On Data Insertion
- Condition: Channel 1234567, Field 1 (Temperature), > 40
- Action: ThingHTTP (send to an email webhook) or ThingTweet (post to Twitter)
- Options: Run action each time condition is met
For email alerts in India, using ThingHTTP to call an IFTTT webhook connected to Gmail is the most reliable approach, as ThingSpeak’s native email functionality has been inconsistent for some Indian email providers.
MATLAB Analysis for Weather Data
ThingSpeak’s MATLAB integration is its most powerful feature. Create MATLAB Visualisations that run in ThingSpeak’s cloud to analyse your data:
% MATLAB code for ThingSpeak Analysis
% Calculate daily average temperature
channelID = 1234567;
readAPIKey = 'XXXXXXXXXXXXXXXX';
% Read last 7 days of data
[data, time] = thingSpeakRead(channelID, 'Fields', 1, ...
'DateRange', [datetime('now')-7, datetime('now')], ...
'ReadKey', readAPIKey);
% Calculate daily averages
dailyAvg = groupsummary(data, time, 'day', 'mean');
% Plot
bar(dailyAvg)
title('Daily Average Temperature (Last 7 Days)')
ylabel('Temperature (°C)')
xlabel('Day')
Frequently Asked Questions
Why is my ESP32 failing to upload to ThingSpeak intermittently?
The most common causes are: (1) Wi-Fi disconnection—add reconnect logic to your loop; (2) Uploading faster than 15-second minimum interval—ThingSpeak returns error 401 for rate-exceeded uploads; (3) ISP blocking port 80—try using ThingSpeak’s MQTT API on port 1883 instead of HTTP. Also check your router’s DHCP lease—if the ESP32’s IP address changes and it doesn’t reconnect properly, uploads will fail.
Can I access ThingSpeak data in India on a slow connection?
ThingSpeak loads reasonably well on 4G connections but can be slow on 2G/3G. The API itself is lightweight—data upload via HTTP GET or MQTT is just a few hundred bytes. The dashboard web interface may be slow to load on slow connections due to JavaScript charting libraries. Consider using the REST API to fetch data and display it on your own lightweight webpage.
How do I handle Wi-Fi reconnection in ESP32 code?
Add this check at the beginning of your loop: if (WiFi.status() != WL_CONNECTED) { WiFi.reconnect(); delay(5000); return; }. For more robust reconnection, use WiFi.setAutoReconnect(true) in setup(). In areas with frequent power outages common in rural India, also configure the ESP32 to save Wi-Fi credentials in NVS (non-volatile storage) so it reconnects automatically after power restoration.
Is there a free alternative to ThingSpeak for IoT weather dashboards?
Yes, several alternatives exist: Grafana Cloud (free tier with generous limits), InfluxDB Cloud (free tier), Adafruit IO (10 feeds free), and Node-RED with a self-hosted dashboard. For Indian makers wanting to self-host to avoid international data upload latency, running InfluxDB + Grafana on an old Android phone or Raspberry Pi is a popular approach that gives you unlimited data storage and zero recurring cost.
How do I add multiple ESP32 weather stations to one ThingSpeak account?
Create a separate channel for each station. ThingSpeak allows 8 channels on the free tier. Each ESP32 uses its own Write API Key (from its respective channel’s API Keys tab). Use MATLAB Analysis to merge data from multiple channels for comparative dashboards. If you need more than 8 channels, consider upgrading to ThingSpeak Commercial or migrating to InfluxDB which has no channel limits.
Add comment