A comprehensive smart city data collection, analysis, and visualization platform based on Hong Kong Open Data.
Course: COMP7503 Multimedia Technologies Submission Deadline: November 29, 2025, 23:55 Project Type: Smart City Programming Assignment
- Project Overview
- Features
- Tech Stack
- Quick Start
- Project Structure
- Usage Guide
- Data Visualization
- Database Management
- Troubleshooting
- Performance Optimization
- Project Submission
This project implements a smart city data platform that:
- Collects real-time data from Hong Kong Open Data Portal (data.gov.hk)
- Processes and analyzes multiple data sources (air quality, weather, traffic)
- Stores historical data in MongoDB for time-series analysis
- Visualizes data through interactive dashboards
- Correlates data across different domains to extract insights
- Air Quality Monitoring: Real-time AQI tracking across Hong Kong districts
- Weather Data Analysis: Temperature and humidity trends by location
- Traffic Flow Analysis: Traffic density, speed, and volume monitoring
✅ Real-time Data Collection
- Air quality data: Every 1.5 minutes
- Weather data: Every 3 minutes
- Traffic data: Every 1 minute
✅ Advanced Visualization
- Interactive dashboards with multiple chart types
- Real-time updates
- Responsive design
✅ Data Analysis
- Correlation analysis
- Trend detection
- Anomaly identification
✅ Containerized Deployment
- Docker-based architecture
- Isolated environments
- Easy scaling
| Component | Technology | Purpose |
|---|---|---|
| Data Collection | Node-RED | Visual flow-based programming |
| Database | MongoDB | Time-series data storage |
| Visualization | Node-RED Dashboard | Real-time charts and gauges |
| Containerization | Docker | Environment isolation |
| Data Source | data.gov.hk APIs | Open government data |
Ensure you have installed:
- Docker: 20.10+ (Download)
- 8GB+ RAM recommended
- 10GB+ free disk space
Verify installation:
docker --version
docker psdocker network create my-app-networkdocker run -d --name mymongo --network my-app-network \
-p 27017:27017 \
-v /Users/zijiancai/Desktop/hkucsfiles/comp7503/hw/mongo:/data/db \
-e MONGO_INITDB_ROOT_USERNAME=admin \
-e MONGO_INITDB_ROOT_PASSWORD=1234 \
mongo:latest --authNote: Update the volume path to match your local directory.
docker run -d --name nodered --network my-app-network \
-p 1880:1880 \
-v /Users/zijiancai/Desktop/hkucsfiles/comp7503/hw/nodered:/data \
nodered/node-red:latest# Install required Node-RED packages
docker exec nodered npm install node-red-contrib-mongodb3
docker restart noderedWait 10 seconds for Node-RED to restart.
Open your browser and navigate to: http://localhost:1880
- Click the menu (≡) → Import
- Click select a file to import
- Choose
SmartCity.Flow.json - Click Import
Click the Deploy button (top right, red color).
Open a new tab: http://localhost:1880/ui
You should see the Smart City Dashboard with:
- Air Quality Monitoring
- Weather Data
- Traffic Analysis
hw/
├── SmartCity.Flow.json # Core Node-RED flow definition
├── HKO.Flow.json # Weather data flow (optional)
├── README.md # This file
├── Project_Report.md # Detailed project report
├── Dockerfile # Custom Node-RED image (optional)
├── .gitignore # Git ignore rules
├── mongo/ # MongoDB data directory
│ └── (auto-generated files)
└── nodered/ # Node-RED data directory
├── flows.json # Active flows
├── flows_cred.json # Credentials (encrypted)
└── package.json # Installed packages
| File | Size | Description |
|---|---|---|
SmartCity.Flow.json |
~21 KB | Main flow with air quality, weather, and traffic data collection |
README.md |
~15 KB | Quick start guide and usage instructions |
Project_Report.md |
~40 KB | Comprehensive project documentation |
mongo/ |
Dynamic | MongoDB data files (auto-generated) |
nodered/ |
Dynamic | Node-RED configuration and flows |
Manual Trigger:
- In Node-RED editor, click the small button on the left side of any inject node
Automatic Trigger:
- Air quality: Every 1.5 minutes
- Weather: Every 3 minutes
- Traffic: Every 1 minute
-
Dashboard: http://localhost:1880/ui
- Real-time charts update automatically
- No refresh needed
-
Debug Panel (in Node-RED):
- Click the bug icon (🐛) on the right sidebar
- View raw data flowing through the system
Change Collection Frequency:
- Double-click an inject node
- Modify the Repeat field (in seconds)
- Current: 90s (1.5min), 180s (3min), 60s (1min)
- Click Done
- Click Deploy
Add New Data Sources:
- Drag an
http requestnode from the palette - Configure the API endpoint
- Add a
functionnode to parse data - Connect to a
mongodb3 innode for storage - Add dashboard nodes for visualization
-
City Average AQI (Gauge)
- Range: 0-100
- Color-coded: Green (0-50), Yellow (50-75), Red (75-100)
-
AQI by District (Bar Chart)
- Shows: Current AQI for each district
- Districts: Central & Western, Eastern, Kwun Tong, Sham Shui Po, Kwai Tsing
- Temperature by Location (Line Chart)
- Range: 10-35°C
- Multiple locations displayed simultaneously
- 24-hour data retention
-
Traffic Density Status (Pie Chart)
- Categories: Smooth, Slow, Congested
- Color-coded by severity
-
Average Traffic Speed (Bar Chart)
- Range: 0-80 km/h
- By location
-
Vehicle Count by Location (Bar Chart)
- Range: 0-200 vehicles
- Shows current traffic volume
docker exec -it mymongo mongosh -u admin -p 1234 --authenticationDatabase admin// Switch to smartcity database
use smartcity
// View all collections
show collections
// Count documents
db.air_quality.countDocuments()
db.weather_data.countDocuments()
db.traffic_flow.countDocuments()
// Query latest records
db.air_quality.find().sort({timestamp: -1}).limit(5)
// Query by station
db.air_quality.find({station: "Central & Western"})
// Aggregate data
db.air_quality.aggregate([
{$match: {timestamp: {$gte: new Date(Date.now() - 3600000)}}},
{$group: {_id: "$station", avgAQI: {$avg: "$aqi"}}}
])# Create backup
docker exec mymongo mongodump -u admin -p 1234 \
--authenticationDatabase admin --db=smartcity --out=/data/backup
# Copy to local
docker cp mymongo:/data/backup ./backup
# Compress
zip -r mongodb_backup.zip backup/# Copy backup to container
docker cp ./backup mymongo:/data/backup
# Restore data
docker exec mymongo mongorestore -u admin -p 1234 \
--authenticationDatabase admin --db=smartcity /data/backup/smartcitySymptoms: Browser shows "Unable to connect"
Solutions:
# Check container status
docker ps | grep nodered
# View logs
docker logs nodered
# Restart container
docker restart noderedCauses:
- Database empty (just started)
- MongoDB connection failed
- Incorrect node configuration
Solutions:
# Check if data exists
docker exec -it mymongo mongosh -u admin -p 1234 --eval \
"use smartcity; db.air_quality.countDocuments()"
# Manually trigger data collection
# In Node-RED, click inject nodes
# Check debug panel for errorsError: MongoError: Authentication failed
Solution:
- Double-click any MongoDB node in Node-RED
- Click the pencil icon next to "Server"
- Verify credentials:
- Host:
mymongo - Username:
admin - Password:
1234 - Auth Source:
admin
- Host:
Error: Bind for 0.0.0.0:1880 failed: port is already allocated
Solution:
Option 1 - Stop conflicting service:
# macOS/Linux
lsof -i :1880
kill -9 <PID>Option 2 - Use different port:
docker stop nodered && docker rm nodered
docker run -d --name nodered --network my-app-network \
-p 1881:1880 \
-v /Users/zijiancai/Desktop/hkucsfiles/comp7503/hw/nodered:/data \
nodered/node-red:latestThen access: http://localhost:1881
# Check logs for errors
docker logs nodered --tail 50
# Check MongoDB connection
docker exec nodered ping mymongo
# Verify network
docker network inspect my-app-networkIf system is slow, increase intervals:
- Air quality: 90s → 300s (5 min)
- Weather: 180s → 600s (10 min)
- Traffic: 60s → 300s (5 min)
In chart nodes, set removeOlder:
{
"removeOlder": 24, // Keep only 24 hours
"removeOlderUnit": "3600" // In seconds
}// In MongoDB
db.air_quality.createIndex({timestamp: -1})
db.air_quality.createIndex({station: 1, timestamp: -1})
db.traffic_flow.createIndex({timestamp: -1})// Delete data older than 30 days
db.air_quality.deleteMany({
timestamp: {$lt: new Date(Date.now() - 30*24*3600000)}
})docker stop nodered mymongodocker start mymongo nodereddocker stop nodered mymongo
docker rm nodered mymongoData is preserved in mongo/ and nodered/ directories.
# WARNING: This deletes all data!
docker stop nodered mymongo
docker rm nodered mymongo
rm -rf mongo/* nodered/*
docker network rm my-app-network- ✅
SmartCity.Flow.json- Core flow definition - ✅
README.md- This documentation - ✅
Project_Report.pdf- Converted from Project_Report.md - ✅
DockerfileOR Docker Hub link
Create a ZIP file:
# Include only source files, not data
zip -r StudentID_Name_COMP7503.zip \
SmartCity.Flow.json \
README.md \
Project_Report.pdf \
Dockerfile
# Example: 3035123456_JohnDoe_COMP7503.zipDo NOT include:
mongo/directorynodered/directorynode_modules/.DS_Store,.git/
Method 1: Using Pandoc
pandoc Project_Report.md -o Project_Report.pdf \
--pdf-engine=xelatex --tocMethod 2: Using Typora
- Open
Project_Report.mdin Typora - File → Export → PDF
Method 3: Online
- All containers start successfully
- Flow imports without errors
- Dashboard displays data correctly
- MongoDB connections work
- README.md is complete
- Project report converted to PDF
- File size < 10MB (excluding data)
- Proper naming convention used
node-red-dashboard- Dashboard UI componentsnode-red-contrib-mongodb3- MongoDB integration
- Air Quality: HK EPD Air Quality Health Index
- Weather: HK Observatory Weather API
- Traffic: Simulated (for demonstration)
- Check this README's troubleshooting section
- Review Node-RED debug panel
- Check Docker container logs
- Verify network connectivity
Course: COMP7503 Multimedia Technologies Institution: The University of Hong Kong
This project is for educational purposes as part of COMP7503 coursework.
- Hong Kong Government Data Portal for open data APIs
- Node-RED community for excellent tools
- MongoDB for robust time-series data storage
Last Updated: November 2025 Version: 2.0 (English Edition)
Good luck with your project! 🎉