This project contains two components:
- IoT Sensor Simulator (
sensor_simulator.py): Generates and uploads random temperature data to a Supabase PostgreSQL database every 5 seconds. - 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.
- Python 3.8+
- A Supabase account and project.
- Create a new project in your Supabase dashboard.
- Navigate to the SQL Editor on the left sidebar.
- 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
);- For simplicity in testing, disable Row Level Security (RLS) on the
temperature_readingstable, or set up appropriate policies allowinginsertandselectforanonusers.
- Install the required Python packages using pip:
pip install -r requirements.txt- Create a
.envfile by copying the example:
cp .env.example .env- Open
.envand fill in your Supabase project URL and anon public key:
SUPABASE_URL=your_actual_supabase_url
SUPABASE_KEY=your_actual_supabase_anon_keyOpen a terminal and run the sensor script. This script will run continuously until you press Ctrl+C.
python sensor_simulator.pyYou should see logs indicating data is being uploaded successfully.
In a second terminal window, start the Flask app:
python app.pyOpen 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.
- Real-time polling
/api/dataevery 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.