Skip to content

Repository files navigation

IoT Temperature Monitoring System

This project contains two components:

  1. IoT Sensor Simulator (sensor_simulator.py): Generates and uploads random temperature data to a Supabase PostgreSQL database every 5 seconds.
  2. Flask Web Dashboard (app.py): A modern web UI to view the live incoming data, display a line chart using Chart.js, filter historical data by dates, and export data as CSV.

Prerequisites

  • Python 3.8+
  • A Supabase account and project.

Supabase Database Setup

  1. Create a new project in your Supabase dashboard.
  2. Navigate to the SQL Editor on the left sidebar.
  3. Run the following SQL to create the necessary table:
CREATE TABLE temperature_readings (
    id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    temperature NUMERIC NOT NULL,
    date DATE NOT NULL,
    time TIME NOT NULL,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now()) NOT NULL
);
  1. For simplicity in testing, disable Row Level Security (RLS) on the temperature_readings table, or set up appropriate policies allowing insert and select for anon users.

Installation

  1. Install the required Python packages using pip:
pip install -r requirements.txt
  1. Create a .env file by copying the example:
cp .env.example .env
  1. Open .env and fill in your Supabase project URL and anon public key:
SUPABASE_URL=your_actual_supabase_url
SUPABASE_KEY=your_actual_supabase_anon_key

Running the Project

1. Start the Sensor Simulator

Open a terminal and run the sensor script. This script will run continuously until you press Ctrl+C.

python sensor_simulator.py

You should see logs indicating data is being uploaded successfully.

2. Start the Web Dashboard

In a second terminal window, start the Flask app:

python app.py

Open your web browser and go to http://127.0.0.1:5000 to view the dashboard. The chart and table will automatically fetch new readings every 5 seconds.

Features Included

  • Real-time polling /api/data every 5 seconds updating DOM + Chart without page reloads.
  • Date range filtering (automatically stops live polling when viewing historical slices).
  • CSV export capability to download filtered or all available records.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages