A real-time IoT telemetry monitoring platform that simulates sensor devices publishing temperature and humidity data, processes the telemetry through an MQTT broker, and visualizes it on an interactive dashboard with intelligent alerting.
The Mini IoT Telemetry Platform is an end-to-end solution for monitoring simulated IoT devices in real-time. It demonstrates best practices in IoT architecture, including message queuing (MQTT), RESTful API design, real-time data processing, and responsive frontend visualization.
The platform simulates multiple IoT sensor devices that publish telemetry data (temperature and humidity) every second. This data flows through an MQTT broker to a Django backend that persists the information, generates intelligent alerts based on configurable rules, and serves everything through a REST API to a React-based dashboard.
Use Cases:
- IoT device monitoring and management
- Real-time telemetry data visualization
- Alert-based anomaly detection
- Educational demonstration of IoT architecture patterns
- Real-Time Telemetry Ingestion: Continuous data collection from multiple simulated devices
- MQTT Communication: Efficient pub/sub messaging using Eclipse Mosquitto broker
- Intelligent Alert System:
- HIGH_TEMP alerts when temperature exceeds 30°C
- OFFLINE alerts when devices stop sending data for 10+ seconds
- ONLINE alerts when devices reconnect after being offline
- RESTful API: Comprehensive endpoints for devices, telemetry, statistics, and alerts
- Live Dashboard: React-based UI with auto-refresh for real-time monitoring
- Rolling Statistics: Calculate average temperature/humidity over configurable time windows
- Message Drop Simulation: Realistic network conditions (1 in 30 messages dropped)
- Device Status Tracking: Automatic online/offline detection
- Background Task Processing: Celery-powered asynchronous alert generation
- Historical Data Analysis: Query past telemetry with filtering and pagination
- Health Monitoring: Service health check endpoint for system status
- Framework: Django 5.x with Django REST Framework
- Message Broker: Eclipse Mosquitto (MQTT)
- Database: SQLite (development)
- MQTT Client: paho-mqtt
- Task Queue: Django Background Tasks
- Framework: React 18.x
- Styling: Tailwind CSS
- HTTP Client: Axios
- Charting: Chart.js
- State Management: React Hooks (Context API)
- Version Control: Git with feature branch workflow
┌────────────────────────┐ MQTT ┌──────────────────────────┐ REST / WS ┌──────────────────────────┐
│ Telemetry Simulator(s) │ ──────────▶ │ MQTT Broker (Mosquitto) │ ────────────────▶ │ Django REST Backend API │
└────────────────────────┘ └──────────────────────────┘ └──────────────┬───────────┘
│
┌────────▼─────────┐
│ SQLite Database │
└────────┬─────────┘
│
┌─────────▼──────────┐
│ React Dashboard │
└────────────────────┘
- Simulator publishes JSON telemetry to
devices/{deviceId}/telemetrytopic - MQTT Broker routes messages to subscribed clients
- Django Backend receives messages, validates, and persists to database
- Alert Engine evaluates rules and generates alerts
- REST API exposes data to frontend
- React Dashboard polls API and displays real-time updates
mini-iot-telemetry-Abdullah-Butt/
│
├── backend/ # Django application
│ ├── api/ # REST API endpoints
│ ├── handler/ # Core logic (Device, Telemetry, Alert)
│ ├── telemetry/ # Service Management
│ ├── db.sqlite3 # Database storage
│ ├── manage.py
│ └── requirements.txt
│
├── frontend/ # React application
│ ├── node_modules/
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── pages/ # Page components
│ │ ├── api/ # API service layer
│ │ ├── routes/
│ │ ├── utils/
│ │ └── App.js
│ ├── package.json
│ └── vite.config.js
│
├── simulator/ # Device simulator
│ ├── simulator.py # Main simulator script
│ └── requirements.txt
│
├── README.md # This file
└── Software Requirements Specification (SRS).md
Before you begin, ensure you have the following installed:
- OS: Windows 10/11, macOS 10.15+, or Linux (Ubuntu 20.04+)
- RAM: 4GB minimum (8GB recommended)
- Disk Space: 2GB free space
git clone https://github.com/yourusername/mini-iot-telemetry-Abdullah-Butt.git
cd mini-iot-telemetry-Abdullah-Butt-
Download Mosquitto:
- Visit https://mosquitto.org/download/
- Download the Windows installer (64-bit recommended)
- Run the installer and install to
C:\Program Files\mosquitto
-
Add to System PATH:
- Open System Properties → Advanced → Environment Variables
- Under "System Variables", find
Pathand click "Edit" - Click "New" and add:
C:\Program Files\mosquitto - Click "OK" to save
-
Verify Installation:
mosquitto -h
# Using Homebrew
brew install mosquitto
# Start as a service
brew services start mosquittosudo apt-get update
sudo apt-get install mosquitto mosquitto-clients
# Enable and start service
sudo systemctl enable mosquitto
sudo systemctl start mosquitto-
Navigate to backend directory:
cd backend -
Create virtual environment:
python -m venv venv # Activate virtual environment # Windows: venv\Scripts\activate # macOS/Linux: source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Run migrations:
python manage.py makemigrations python manage.py migrate
-
Create superuser (optional):
python manage.py createsuperuser
-
Navigate to frontend directory:
cd ../frontend -
Install dependencies:
npm install
-
Navigate to simulator directory:
cd ../simulator -
Install dependencies:
pip install paho-mqtt
You need to run FOUR separate services in different terminal windows:
# Navigate to Mosquitto installation directory
cd "C:\Program Files\mosquitto" # Windows
# or just run if in PATH
mosquitto -vExpected Output:
1234567890: mosquitto version 2.x starting
1234567890: Opening ipv4 listen socket on port 1883.
1234567890: Opening ipv6 listen socket on port 1883.
cd backend
# Activate virtual environment first
python manage.py runserverExpected Output:
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
cd backend
# Activate virtual environment first
python manage.py process_tasks --duration=0 --sleep=1Expected Output:
Starting background task processor...
Checking for tasks every 1 second(s)...
This service monitors device activity and generates OFFLINE/ONLINE alerts.
cd simulator
python simulator.pyRun multiple devices:
python simulator.py --device-id device-001
python simulator.py --device-id device-002
python simulator.py --device-id device-003Expected Output:
Connected to MQTT Broker at localhost:1883
Publishing telemetry for device-001...
[2025-10-09 14:23:45] Published: {"deviceId": "device-001", "ts": 1728481425000, "temperature": 26.3, "humidity": 47.9}
cd frontend
npm startExpected Output:
Compiled successfully!
You can now view the app in the browser.
Local: http://localhost:5173
You can manually publish a test message without running the simulator:
-
Create
payload.json:{ "deviceId": "test-device-123", "ts": 1714041600000, "temperature": 28.5, "humidity": 55.2 } -
Publish using mosquitto_pub:
mosquitto_pub -h localhost -t devices/test-device-123/telemetry -f payload.json
-
Verify in Django admin or API:
curl http://localhost:8000/api/telemetry/?deviceId=test-device-123
http://localhost:8000/api
GET /health/Response:
{
"status": "healthy",
"database": "connected",
"mqtt": "connected",
"timestamp": "2025-10-09T14:23:45Z"
}GET /devices/Response:
[
{
"device_id": "device-001",
"status": "ONLINE",
"last_seen": "2025-10-09T14:23:45Z"
},
{
"device_id": "device-002",
"status": "OFFLINE",
"last_seen": "2025-10-09T14:20:30Z"
}
]GET /telemetry/?deviceId=device-001&limit=100Query Parameters:
deviceId(required): Device identifierlimit(optional, default=100): Number of records to return
Response:
[
{
"id": 1234,
"device_id": "device-001",
"ts": "2025-10-09T14:23:45Z",
"temperature": 26.3,
"humidity": 47.9
}
]GET /stats/avg/?deviceId=device-001&window=5mQuery Parameters:
deviceId(required): Device identifierwindow(required): Time window (e.g., "5m", "1h", "24h")
Response:
{
"device_id": "device-001",
"window": "5m",
"avg_temperature": 26.8,
"avg_humidity": 48.2,
"data_points": 300
}GET /alerts/?limit=50Query Parameters:
limit(optional, default=50): Number of alerts to returndeviceId(optional): Filter by devicealert_type(optional): Filter by type (HIGH_TEMP, OFFLINE, ONLINE)
Response:
[
{
"id": 42,
"device_id": "device-001",
"alert_type": "HIGH_TEMP",
"ts": "2025-10-09T14:23:45Z",
"payload": {
"temperature": 32.1,
"threshold": 30.0
}
}
]Purpose: Simulates IoT sensor devices publishing telemetry data.
Features:
- Publishes JSON telemetry every 1 second
- Randomly varies temperature (20-35°C) and humidity (30-70%)
- Drops 1 in every 30 messages to simulate network issues
- Supports multiple device instances with unique IDs
Configuration:
MQTT_BROKER = "localhost"
MQTT_PORT = 1883
PUBLISH_INTERVAL = 1 # seconds
DROP_RATE = 30 # 1 in 30 messagesPurpose: Subscribes to MQTT topics and ingests telemetry data.
Features:
- Connects to Mosquitto broker
- Subscribes to
devices/+/telemetrywildcard topic - Validates incoming JSON payloads
- Persists data to database
- Updates device last_seen timestamp
Purpose: Monitors telemetry and generates alerts based on rules.
Alert Rules:
- HIGH_TEMP: Triggered when temperature > 30°C
- OFFLINE: Triggered when no data received for 10+ seconds
- ONLINE: Triggered when device reconnects after offline period
Implementation:
- Background task runs every 1 second
- Checks all device last_seen timestamps
- Generates alerts and stores in database
Purpose: Exposes telemetry data and alerts through RESTful endpoints.
Features:
- Django REST Framework powered
- Pagination support
- Query parameter filtering
- JSON response format
- CORS enabled for frontend access
Purpose: Visualizes telemetry data and alerts in real-time.
Pages:
- Device Overview: List of all devices with status indicators
- Telemetry Charts: Line graphs showing temperature/humidity trends
- Alerts Table: Recent alerts with filtering options
Features:
- Auto-refresh every 3 seconds
- Responsive design with Tailwind CSS
- Interactive charts with Recharts
- Device filtering and selection
Error: Address already in use
Solution: Another service is using port 1883
# Windows
netstat -ano | findstr :1883
taskkill /PID <PID> /F
# Linux/Mac
lsof -i :1883
kill -9 <PID>Error: Connection refused [Errno 111]
Solution: Ensure Mosquitto is running
mosquitto -vError: Network Error
Solution: Check Django server is running and CORS is enabled
# settings.py
CORS_ALLOWED_ORIGINS = [
"http://localhost:5173",
]No alerts being generated
Solution: Ensure process_tasks is running
python manage.py process_tasks --duration=0 --sleep=1cd backend
pytestcd frontend
npm test# Start all services, then:
python tests/integration_test.py- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'feat: add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
Commit Message Format:
feat(component): add new feature
fix(component): resolve bug
docs(readme): update documentation
refactor(api): improve code structure
Abdullah Butt
- GitHub: @AbdullahButt2611
- Email: abutt2210@gmail.com
- Eclipse Mosquitto for MQTT broker
- Django & DRF communities
- React & Tailwind CSS teams
- All contributors and reviewers
For questions or issues:
- Check the Troubleshooting section
- Open an issue on GitHub
- Contact the author
Built with ❤️ for IoT enthusiasts
