IOT_Shadow_Display_UnixFinal is a Unix course final project that simulates the operation of AWS IoT Shadow. It implements a complete IoT control architecture, including:
- Central control via web interface
- Local gateway operation and override logic
- Device status synchronization through a custom Shadow system
The system uses Flask and JSON files to manage device state, eliminating the need for cloud services or databases, making it lightweight and suitable for offline or embedded environments.
- Device Shadow mechanism (desired / reported / delta)
- RESTful API with API key authentication
- Frontend web interface for control and monitoring
- Local gateway emergency override support
- Support for multiple devices via per-device JSON files
- Backend:
- Python (Flask)
- ESP32 (PlatformIO)
- Frontend:
- HTML / JavaScript (AJAX)
- Apache2 web server
- Storage:
- JSON files (one per device)
- Local file system
- System:
- Debian 12 (Linux)
- ESP32 microcontroller
- Security:
- API key authentication
- Web-based login system
IOT_Shadow_Display_UnixFinal/
├── LocalGateway_ESP-32S/ # ESP32 Gateway implementation
│ ├── src/ # ESP32 source code
│ └── platformio.ini # PlatformIO configuration
├── frontend/ # Web interface
│ ├── index.html # Main control interface
│ ├── login.html # Authentication page
│ └── apache2/ # Web server configuration
├── auth/ # Authentication system
├── shadow/ # Shadow JSON files
└── main/ # Core system components
- IoT device control and monitoring
- Local edge computing scenarios
- Systems requiring emergency fallback control
- Educational use or embedded system prototyping
- ESP32-based gateway implementations
- Secure web-based device management
- Albert Wang(王建葦) – System Architecture, Backend, Shadow Logic
- Andy Chen(陳稚翔) – Frontend Interface Design
This project is provided for educational use only. Free to modify and extend.
- Debian 12 (Linux) or compatible system
- Python 3.x
- Apache2 web server
- ESP32 development board (for gateway)
- PlatformIO or Arduino IDE (for ESP32 development)
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install required packages
pip install flask
pip install flask-cors- Navigate to the shadow directory:
cd shadow - Configure tokens in
src/main.py:TOKENS = { "admin-token-123": "admin", "user-token-456": "user", "device-token-789": "device" }
- Start the shadow server:
python src/main.py
- Navigate to the auth directory:
cd auth - Start the authentication server:
python src/main.py
-
Install Apache2:
sudo apt update sudo apt install apache2
-
Enable required modules:
sudo a2enmod proxy sudo a2enmod proxy_http sudo a2enmod ssl
-
Configure SSL virtual host:
sudo nano /etc/apache2/sites-available/www-le-ssl.conf
Add the following configuration:
ProxyPreserveHost On ProxyPass "/api/" "http://127.0.0.1:5000/" ProxyPassReverse "/api/" "http://127.0.0.1:5000/" ProxyPass "/authapi/" "http://127.0.0.1:6000/" ProxyPassReverse "/authapi/" "http://127.0.0.1:6000/"
-
Deploy frontend files:
sudo cp frontend/*.html /var/www/html/ sudo cp frontend/LED.jpg /var/www/html/
-
Install PlatformIO:
- Follow instructions at https://platformio.org/install
-
Configure ESP32 project:
cd LocalGateway_ESP-32S -
Edit
src/main.cppto set your network credentials:const char *SSID = "your-wifi-name"; const char *PASSWORD = "your-wifi-password"; const char *TOKEN = "device-token-789";
-
Build and upload:
pio run -t upload
-
Verify backend services:
- Shadow server should be running on port 5000
- Auth server should be running on port 6000
- Check logs for any errors
-
Verify frontend:
- Access https://your-domain.com/login.html
- Test login with credentials
- Verify device control interface
-
Verify ESP32 gateway:
- Check serial monitor for connection status
- Verify WiFi connection
- Test local and cloud mode switching
- Change default tokens and passwords
- Enable HTTPS for all communications
- Implement proper user authentication
- Set up firewall rules
- Regular security updates
- Monitor system logs
Common issues and solutions:
-
Port conflicts:
- Check if ports 5000 and 6000 are available
- Use
netstat -tulpn | grep LISTEN
-
Apache configuration:
- Check syntax:
sudo apache2ctl configtest - View logs:
sudo tail -f /var/log/apache2/error.log
- Check syntax:
-
ESP32 connection:
- Verify WiFi credentials
- Check server accessibility
- Monitor serial output
-
Shadow synchronization:
- Verify JSON file permissions
- Check API endpoint accessibility
- Monitor server logs