Skip to content

mA4rK0/IoT-Temperature-Humidity-Monitoring-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

29 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌑️ IoT Temperature & Humidity Monitoring System

ESP32 β†’ Next.js API β†’ Supabase Realtime β†’ Telegram Alerts β†’ Mobile Dashboard

A production-ready IoT monitoring system for real-world temperature & humidity tracking. Built with a secure ingestion pipeline, realtime dashboard, device heartbeat, alerting system, and mobile-friendly responsive UI.


πŸš€ Live Demo

Realtime Dashboard: https://io-t-temperature-humidity-monitorin.vercel.app/
Repository: https://github.com/mA4rK0/IoT-Temperature-Humidity-Monitoring-System


🧩 System Architecture

flowchart TD
  %% Device layer
  subgraph DEVICE["Edge Device"]
    ESP32["ESP32 (esp32-01) + DHT22<br/>β€’ Read temp & humidity<br/>β€’ Heartbeat (periodic POST)"]
    DEVTOOLS["Serial / USB / OTA<br/>(development & debug)"]
  end

  %% Network
  WIFI["Wi-Fi / Internet<br/>(ESP32 β†’ Vercel API)"]

  %% Server layer
  subgraph VERCEL["Vercel β€” Next.js API"]
    API["/api/ingest<br/>β€’ Validate Authorization header<br/>β€’ Sanitize payload<br/>β€’ Insert β†’ Supabase (sensor_data)<br/>β€’ Trigger alerts & record β†’ alerts table"]
  end

  %% Database & realtime
  subgraph SUPABASE["Supabase"]
    DB["Postgres: sensor_data table<br/>& alerts table"]
    RT["Realtime: broadcast INSERT events"]
  end

  %% Frontend & clients
  DASH["Next.js Dashboard<br/>β€’ Realtime subscribe (Supabase)<br/>β€’ Charts, recent readings, device status<br/>β€’ Mobile-optimized UI"]
  CLIENT["Client: Browser / Mobile"]

  %% Alerting
  TELE["Telegram Bot (Bot API)<br/>β€’ Send alert messages to chat"]

  %% Flow connections (top β†’ bottom)
  ESP32 -->|POST JSON βœ“| WIFI
  WIFI --> API
  API -->|write| DB
  DB -->|broadcast| RT
  RT --> DASH
  DASH --> CLIENT
  API -->|trigger alert| TELE
  DEVTOOLS --> ESP32
Loading

Flow Summary

  1. ESP32 reads temperature & humidity from a DHT22 sensor.
  2. Device sends a secure HTTP POST (JSON) to a Next.js API endpoint using a Authorization header.
  3. API validates the device β†’ inserts the data into Supabase PostgreSQL.
  4. Supabase Realtime instantly broadcasts new rows to the dashboard.
  5. Next.js Dashboard updates charts + tables + device status in realtime.
  6. Alerting engine triggers Telegram messages when thresholds exceed limits.
  7. Heartbeat system automatically marks device as Online or Offline.

✨ Features

πŸ”§ Core Features

  • πŸ“‘ Realtime temperature & humidity monitoring
  • πŸš€ ESP32 β†’ Next.js ingestion pipeline
  • πŸ—„οΈ Supabase PostgreSQL storage
  • ⚑ Supabase Realtime push updates
  • πŸ›‘οΈ Secure device authentication (Authorization)
  • 🎨 Modern, animated dashboard UI (Next.js + Tailwind + Framer Motion)

πŸ“± Mobile Features

  • Fully responsive
  • Touch-friendly charts
  • Compact data layout for phones
  • Mobile status widgets

πŸ”” Alerting & Monitoring

  • Telegram Alerts for high/low temperature or humidity
  • Threshold-based warnings
  • Timestamp included in alert payload
  • Optional silent mode

🟒 Device Heartbeat

  • Device marked Online if last data < X seconds
  • Marked Offline automatically
  • Visual indicator on dashboard
  • Useful for cold storage, greenhouse, lab monitoring

πŸ“Š Data Visualization

  • 24-hour charts for temperature & humidity
  • Animated line charts (Recharts)
  • Recent 10 readings table
  • Local time formatting

πŸ”Œ Hardware Requirements

  • ESP32 DevKit
  • DHT22 Sensor (or DS18B20 alternative)
  • Jumper wires
  • Breadboard (optional)
  • WiFi network

Wiring (ESP32 β†’ DHT22)

ESP32 Board               DHT22 Module (3-pin)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 β”‚       β”‚              β”‚
β”‚          [3V3]  β”œβ”€β”€β”€β”€β”€β”€β”€β”€ VCC (Pin 1)  β”‚
β”‚                 β”‚       β”‚              β”‚
β”‚          [GND]  β”œβ”€β”€β”€β”€β”€β”€β”€β”€ GND (Pin 3)  β”‚
β”‚                 β”‚       β”‚              β”‚
β”‚          [GPIO4]β”œβ”€β”€β”€β”€β”€β”€β”€β”€ DATA (Pin 2) β”‚
β”‚                 β”‚       β”‚              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
DHT22 VCC β†’ 3.3V  
DHT22 GND β†’ GND  
DHT22 Data β†’ GPIO 4  

🧠 Technology Stack

Device

  • ESP32
  • DHT22
  • Arduino Framework

Cloud Backend

  • Next.js 14 API Route
  • Supabase PostgreSQL
  • Supabase Realtime
  • Supabase Auth

Frontend

  • Next.js 14
  • TailwindCSS
  • Recharts
  • Framer Motion
  • Responsive Mobile Layout

πŸ› οΈ ESP32 Firmware (Excerpt)

http.begin(SERVER_URL);
http.addHeader("Content-Type", "application/json");
http.addHeader("Authorization", String("Bearer ") + DEVICE_SECRET);

String json = "{\"device_id\":\"esp32-01\",\"temperature\":";
json += temp;
json += ",\"humidity\":";
json += humidity;
json += "}";

Full firmware: iot_code.ino


πŸ› οΈ Next.js API β€” Secure Ingestion Route

Path: /api/ingest

const headerSecret =
  req.headers.get("Authorization") ||
  req.headers.get("x-Authorization") ||
  req.headers.get("authorization");

const expected = `Bearer ${DEVICE_SECRET}`;
if (!headerSecret || headerSecret !== expected) {
  return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
  • Validates device
  • Sanitizes incoming payload
  • Inserts data to Supabase
  • Returns inserted row

File: /app/api/ingest/route.ts


πŸ“ˆ Dashboard Preview

Dashboard Screenshot

Includes:

  • Temperature + humidity cards
  • Device status indicator
  • 24-hour animated charts
  • Recent readings table
  • Last update time
  • Mobile optimization
  • Smooth transitions

πŸ”” Telegram Alert System

Trigger Conditions:

  • temperature > TEMP_MAX
  • humidity > HUM_MAX

Alert Format:

ALERT
Device: esp32-01
Type: humidity_high
Value: 82.5
Time (Asia/Jakarta): 12/01/2025, 01:04:26 PM
Timestamp (UTC): 2025-12-01T06:04:26.085791+00:00

URL: https://io-t-temperature-humidity-monitorin.vercel.app/

Implemented Via:

  • Telegram Bot API
  • Next.js server-side alert dispatcher
  • Integrated inside ingestion route

🟒 Device Status System (Online / Offline)

Method:

  • Each ingestion updates a last_seen timestamp
  • Dashboard calculates:
    • If now - last_seen < 60s β†’ Online
    • Else β†’ Offline

UI:

Green dot = Online
Red dot = Offline


πŸ”‘ Environment Variables

Server (Vercel)

SUPABASE_SERVICE_KEY=YOUR_SUPABASE_SERVICE_KEY
DEVICE_SECRET=YOUR_CUSTOM_DEVICE_SECRET
TELEGRAM_TOKEN=YOUR_TELEGRAM_BOT_TOKEN
TELEGRAM_CHAT_ID=YOUR_TELEGRAM_CHAT_ID_API

Client

NEXT_PUBLIC_SUPABASE_URL=YOUR_SUPABASE_PROJECT_URL
NEXT_PUBLIC_SUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEY
NEXT_PUBLIC_SITE_URL=YOUR_PUBLIC_SITE_URL
ALERT_TEMP_THRESHOLD=YOUR_TEMP_THRESHOLD
ALERT_HUM_THRESHOLD=YOUR_HUM_THRESHOLD
ALERT_MINUTES_BETWEEN=YOUR_MINUTES_BETWEEN
TIMEZONE=YOUR_TIMEZONE

πŸ§ͺ Run Locally

npm install
cp .env.example .env.local
npm run dev

Local dashboard:
http://localhost:3000/


πŸš€ Deployment (Vercel + Supabase)

Steps:

  1. Deploy to Vercel
  2. Add all environment variables
  3. Enable Supabase Realtime:
select * from supabase_realtime.add_realtime_publication('sensor_data');
  1. Flash ESP32 with correct
    • SERVER_URL
    • DEVICE_SECRET
  2. Data will appear instantly on dashboard
  3. Alerts will fire automatically

πŸ“¦ Folder Structure

IoT-Temperature-Humidity-Monitoring-System
β”œβ”€β”€ LICENCE
β”œβ”€β”€ README.md
β”œβ”€β”€ config.example.h
β”œβ”€β”€ config.h
β”œβ”€β”€ docs/
β”‚   └── iot-temperature-humidity-dashboard.png
β”œβ”€β”€ iot_code.ino
└── front-end/
    β”œβ”€β”€ eslint.config.mjs
    β”œβ”€β”€ example.env
    β”œβ”€β”€ next-env.d.ts
    β”œβ”€β”€ next.config.ts
    β”œβ”€β”€ package.json
    β”œβ”€β”€ pnpm-lock.yaml
    β”œβ”€β”€ postcss.config.mjs
    β”œβ”€β”€ tsconfig.json
    β”œβ”€β”€ public/
    β”‚   └── vercel.svg
    └── src/
        β”œβ”€β”€ app/
        β”‚   β”œβ”€β”€ api/
        β”‚   β”‚   └── ingest/
        β”‚   β”‚       └── route.ts
        β”‚   β”œβ”€β”€ favicon.ico
        β”‚   β”œβ”€β”€ globals.css
        β”‚   β”œβ”€β”€ layout.tsx
        β”‚   └── page.tsx
        └── lib/
            β”œβ”€β”€ useSensorRealtime.ts
            └── useSupabaseClient.ts

🧭 Future Enhancements

  • Multi-device support
  • MQTT ingestion mode
  • Multi-user access control
  • CSV/Excel export
  • Long-term (30-day) analytics
  • Chart smoothing + anomaly detection

πŸ‘€ Author

Marko
IoT β€’ Embedded Systems β€’ Robotics β€’ Cloud Integration

Building real-world systems that connect hardware, cloud, and people.


πŸ“ License

MIT License β€” free to use & modify.

Releases

No releases published

Packages

No packages published