- Modern, responsive design using Bootstrap
- Real-time schedule updates via WebSocket
- Simple time input fields for ON/OFF scheduling
- Handles web client connections
- Maintains schedule checking (every 3 seconds)
- Publishes ON/OFF commands to MQTT at scheduled times
- Receives commands from MQTT broker
- Manages serial communication with Arduino
- Provides detailed logging of all operations
- Controls physical relay on pin 7
- LOW = Light ON, HIGH = Light OFF
- Includes debug serial output
- Arduino board
- Relay module connected to pin 7
- USB connection between Arduino and computer
- Python 3.x
- Required Python packages (install via
pip install -r requirements.txt):- paho-mqtt
- pyserial
- websockets
- Arduino IDE for uploading the sketch
- Modern web browser
- Default broker IP: 157.173.101.159
- Default port: 1883
- Topic: relay/controll
- Default port: /dev/ttyACM0
- Baud rate: 9600
- HTTP server: http://localhost:8000
- WebSocket server: ws://localhost:8765
-
Upload Arduino Sketch
# Using Arduino IDE, upload arduino/relay.ino -
Install Dependencies
pip install -r requirements.txt
-
Start WebSocket Server
python websocket_server.py
-
Start MQTT Subscriber
python subscriber.py
-
Access Web Interface
- Open http://localhost:8000 in your web browser
- Set your desired ON and OFF times
- Click Submit
- Shows schedule reception and MQTT publishing
- Logs schedule checking every 3 seconds
- Shows connection status
- Logs command reception and forwarding
- Displays Arduino responses
- Confirms command reception
- Shows relay state changes
- Reports current light status
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
The MQTT broker IP is hardcoded for demonstration purposes. In a production environment, consider:
- Using environment variables for sensitive configuration
- Implementing MQTT authentication
- Using TLS for MQTT and WebSocket connections
- Modify the web interface design in
static/style.css - Adjust schedule check frequency in
subscriber.py - Configure MQTT topics and broker settings in both Python scripts