A complete smart lock control system powered by ESP8266 microcontroller with Over-The-Air (OTA) firmware updates, automated CI/CD pipeline, Kubernetes deployment, and UDP remote control interface.
- Smart Lock Control: Remote control of electrical locks via UDP commands
- Automated OTA Updates: ESP8266 devices automatically check for and install firmware updates
- CI/CD Pipeline: GitHub Actions automatically builds and deploys firmware on code changes
- Kubernetes Deployment: Scalable OTA server running on Kubernetes
- UDP Command Interface: Remote lock control via network commands
- OLED Display: Real-time status display showing lock state and system info
- Web Interface: HTTP endpoints for device status and manual updates
- Security: SSL/TLS enabled with automatic certificate management
-
ESP8266 Smart Lock Controller (
sketch/sketch.ino)- WiFi-enabled microcontroller controlling electrical lock
- Listens for UDP unlock commands on port 2333
- OLED display shows lock status and system information
- Automatically checks for OTA updates every hour
- Web server for status monitoring and manual control
-
OTA Server (
ota_server/main.go)- Go-based HTTP server for firmware management
- Handles firmware uploads and downloads
- Version management and integrity checking
- RESTful API for device management
-
Kubernetes Deployment (
k8s-ota-server/)- Production-ready deployment manifests
- Ingress with SSL termination
- Health checks and monitoring
-
Client Script (
client.py)- Python UDP client for sending unlock commands to ESP8266
- Used for remote lock control over network
-
CI/CD Pipeline (
.github/workflows/build.yml)- Automated firmware compilation
- Version management with build numbers
- Automatic deployment to OTA server
- ESP8266 development board (NodeMCU v2 recommended)
- Electrical lock or relay module for lock control
- Arduino IDE or Arduino CLI
- Python 3.x
- Kubernetes cluster (for production deployment)
- Go 1.22+ (for local OTA server development)
Required Components:
- ESP8266 NodeMCU v2
- SSD1306 OLED display (128x64)
- Electrical lock or relay module
- 5V/12V power supply (depending on lock requirements)
- Breadboard and jumper wires
- Transistor or relay driver circuit (if needed)
Wiring:
ESP8266 NodeMCU v2 -> OLED Display
D6 (GPIO12) -> SCL
D5 (GPIO14) -> SDA
3V3 -> VCC
GND -> GND
ESP8266 NodeMCU v2 -> Lock Control
D2 (GPIO4) -> Relay/Lock Control Pin
(through appropriate driver circuit)
VIN/5V -> Lock Power Supply (+)
GND -> Lock Power Supply (-)
Note: Use appropriate relay or transistor driver circuit
between ESP8266 and electrical lock for proper isolation
and current handling.
Edit sketch/sketch.ino and update WiFi credentials:
const char* ssid = "your_wifi_network"; // Your WiFi SSID
const char* password = "your_wifi_password"; // Your WiFi password- Apply Kubernetes manifests:
kubectl apply -f k8s-ota-server/ota-esp8622/- Update ingress host in
04.ingress.yamlto your domain:
- host: your-domain.com # Change this to your domain- Build and run the OTA server:
cd ota_server
go run main.goThe server will start on http://localhost:8080
- Fork the ESP Smart Lock repository
- Update the OTA server URL in
.github/workflows/build.yml:
SERVER_URL: https://your-domain.com/upload # Change to your server- Push changes to trigger automatic build and deployment
- Compile the sketch using Arduino IDE or CLI
- Upload firmware manually:
curl -X POST \
-F "firmware=@build/sketch.ino.bin" \
-F "version=1.0.0" \
http://your-server.com/upload- Open
sketch/sketch.inoin Arduino IDE - Select board: "NodeMCU 1.0 (ESP-12E Module)"
- Upload the sketch to your ESP8266
Update the IP address in client.py to match your ESP8266's IP:
server_address = ('192.168.1.100', 2333) # ESP8266's IP addressRun the client to unlock the door:
python client.pyThe ESP8266 will receive the unlock command and activate the electrical lock.
Send UDP commands to unlock the electrical lock:
# Send unlock command to open the lock
python client.py # Sends "unlock" command
# Custom commands can be added by modifying client.pyAvailable Commands:
unlock: Opens the electrical lock and displays "T - ON" messagef_pressed: Alternative trigger command for lock control
The system operates as follows:
- Send UDP packet with "unlock" command to ESP8266
- ESP8266 receives command and activates lock control pin (GPIO4)
- Electrical lock opens for configured duration
- OLED display shows lock status and operation count
- Lock automatically re-engages after timeout
The OTA server provides several HTTP endpoints:
Get Current Version:
curl https://your-server.com/versionList All Firmware Versions:
curl https://your-server.com/listUpload New Firmware:
curl -X POST \
-F "firmware=@firmware.bin" \
-F "version=1.2.3" \
https://your-server.com/uploadDownload Firmware:
curl -O https://your-server.com/firmware
curl -O https://your-server.com/firmware?version=1.2.3Each ESP8266 smart lock controller runs a web server accessible at its IP address:
Lock Status:
curl http://192.168.1.100/Manual Lock Control:
curl -X POST http://192.168.1.100/update- Edit
sketch/sketch.ino - Test locally using Arduino IDE
- Commit and push changes
- GitHub Actions will automatically build and deploy
- Add command handling in
sketch/sketch.ino:
else if (strcmp(packetBuffer, "lock_status") == 0) {
// Handle lock status request
printDisplay("Lock Status", "Secure");
}- Update
client.pyto send the new command:
message = b'lock_status'- Make changes to
ota_server/main.go - Test locally:
cd ota_server
go run main.go- Build Docker image:
docker build -t your-registry/ota-server:latest .- WiFi Security: Use WPA3/WPA2 with strong passwords
- OTA Updates: HTTPS endpoints with valid SSL certificates
- Network Isolation: Place smart lock devices on separate VLAN
- Access Control: Implement IP whitelisting for lock commands
- Firmware Validation: Server validates firmware integrity using MD5 checksums
- Physical Security: Secure the ESP8266 controller in tamper-resistant enclosure
- Lock Failsafe: Ensure lock fails to secure state on power loss
- Check WiFi credentials in
sketch.ino - Ensure 2.4GHz WiFi is available (ESP8266 doesn't support 5GHz)
- Check serial monitor for connection status
- Verify OTA server is accessible from ESP8266
- Check server logs for upload/download errors
- Ensure firmware size doesn't exceed ESP8266 memory limits
- Verify version formatting is correct
- Confirm ESP8266 and client are on the same network
- Check firewall settings on network
- Verify correct IP address in
client.py - Use serial monitor to debug UDP packet reception
- Check electrical connections between ESP8266 and lock
- Verify power supply specifications match lock requirements
- Test lock control pin output with multimeter
- Ensure relay/driver circuit is functioning properly
- Check lock mechanism for mechanical issues
- Verify I2C connections (SDA/SCL)
- Check power supply (3.3V)
- Scan for I2C devices to confirm OLED address
Each smart lock controller provides status information via HTTP:
{
"status": "running",
"device": "ESP8266_SmartLock",
"ip": "192.168.1.100",
"ssid": "your_network",
"rssi": -45,
"uptime": 3600000,
"unlock_commands_received": 15,
"lock_status": "secure",
"free_heap": 25000,
"chip_id": "12345678",
"firmware_version": "1.2.3",
"ota_url": "https://ota.example.com/firmware",
"ota_server_online": true
}Monitor OTA server health:
- HTTP
/versionendpoint for health checks - Kubernetes probes for availability
- Log aggregation for debugging
- Fork the ESP Smart Lock Repository
- Create Feature Branch
git checkout -b feature/amazing-feature
- Make Changes
- Follow existing code style
- Add comments for complex logic
- Update documentation if needed
- Test Changes
- Test firmware changes on actual hardware
- Verify OTA server functionality
- Check CI/CD pipeline passes
- Submit Pull Request
- Describe changes clearly
- Include testing steps
- Reference any related issues
- Code Style: Follow existing formatting and naming conventions
- Documentation: Update README and inline comments
- Testing: Test on actual hardware when possible
- Security: Consider security implications of changes
- Backwards Compatibility: Maintain compatibility when possible
ESP Smart Lock is open source. Please check the license file for details.
- GitHub Issues: Report bugs and request features on the ESP Smart Lock repository
- Documentation: Check this README and inline code comments
- Community: Share experiences and solutions with the ESP Smart Lock community
- Development: Edit
sketch/sketch.inowith new lock control features - Automated Build: GitHub Actions compiles firmware with version
1.2.{build_number} - Deployment: Firmware automatically uploaded to OTA server
- Update: ESP8266 smart lock controllers check for updates every hour and install automatically
- Control: Use
client.pyto send unlock commands to doors - Monitor: Check lock status via web interface or server API
ESP Smart Lock provides a complete IoT smart lock solution with automated updates, remote control, and production-ready deployment capabilities for secure access control.