The server now supports server-side command storage, giving you complete freedom over how and when commands are sent to the Arduino. Instead of directly queuing commands, you can now:
- Save frequently-used commands with custom names
- Build a library of commands
- Execute saved commands at any time with one click
- Manage (view, send, delete) all saved commands from the web UI
- Added
saved_commandsdictionary tofirmware_server.py - Commands are stored on the PC server (not on the NodeMCU)
- Persistent during server runtime (in-memory storage)
- Full control: save, list, execute, delete
Save a command with a custom name.
Request:
{
"name": "fast_blink",
"command": {"type": "blink", "duration": 100}
}
Response:
{
"success": true,
"message": "Command 'fast_blink' saved successfully"
}Get all saved commands.
Response:
{
"commands": {
"fast_blink": {"type": "blink", "duration": 100},
"slow_blink": {"type": "blink", "duration": 2000},
"led_on": {"type": "led_on"}
}
}Execute a saved command by name (adds to queue).
Request:
{
"name": "fast_blink"
}
Response:
{
"success": true,
"message": "Command 'fast_blink' added to queue",
"queue_size": 1
}Delete a saved command.
Request:
{
"name": "fast_blink"
}
Response:
{
"success": true,
"message": "Command 'fast_blink' deleted successfully"
}The web interface now has a new section: 💾 Saved Commands
Features:
- Save Current Command: After sending any command (e.g., blink, LED on/off), you can save it with a custom name
- Saved Commands List: Shows all saved commands in a table with:
- Command name
- Full command JSON
- Action buttons: Send | Delete
- Auto-refresh: The saved commands list refreshes every 5 seconds
- Instant Execution: Click "Send" on any saved command to add it to the queue immediately
cd server
python3 firmware_server.pyOpen your browser to: http://localhost:5000
Method A - Save after sending:
- Use any button to send a command (e.g., "Very Fast (100ms)")
- Enter a name in "Command Name" field (e.g.,
very_fast) - Click "Save Last Command"
- ✅ Command is now saved!
Method B - Save via API:
curl -X POST http://localhost:5000/api/command/save \
-H "Content-Type: application/json" \
-d '{"name":"my_pattern","command":{"type":"blink","duration":750}}'- Click the "Send" button next to any saved command in the list
- The command will be added to the queue and sent to Arduino
- You'll see the confirmation in the logs
- Click the "Delete" button next to any saved command
- Confirm the deletion
- Command is removed from the library
1. Test different blink speeds using preset buttons
2. Find the perfect timing (e.g., 350ms)
3. Use Custom Speed to set 350ms, click "Set Custom Speed"
4. Name it "perfect_blink" and save
5. Later: click "Send" on "perfect_blink" to run it again
6. Build a library: "startup_sequence", "alert_pattern", "idle_blink", etc.
┌─────────────────────────────────────────────┐
│ PC (Flask Server) │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ Command │ │ Saved │ │
│ │ Queue │◄───│ Commands │ │
│ │ (immediate) │ │ (library) │ │
│ └──────┬───────┘ └──────▲───────┘ │
│ │ │ │
│ │ │ │
└─────────┼───────────────────┼──────────────┘
│ │
│ (poll) │ (web UI)
▼ │
┌──────────┐ │
│ ESP8266 │ │
│ (bridge) │◄─────────────┘
└────┬─────┘
│ (serial)
▼
┌──────────┐
│ Arduino │
│ R4 │
└──────────┘
Key Points:
- Saved Commands = Your command library (stored on PC)
- Command Queue = Commands waiting to be sent to Arduino
- Execute a saved command → Copies it to the queue → ESP8266 polls and gets it → Arduino executes
-
Testing & Development
- Save different configurations
- Quickly test variations
- Build a test suite
-
Complex Sequences
- Save individual steps
- Execute in sequence manually or via scripts
- Mix and match saved commands
-
Remote Control
- Build a command library
- Use from any device on the network
- API-driven automation
-
Production Patterns
- Save validated commands
- Ensure consistency
- Quick deployment
- Storage: In-memory Python dictionary (runtime only)
- Persistence: Commands lost when server restarts (add file save if needed)
- Capacity: Limited only by RAM
- Thread Safety: Flask handles requests sequentially by default
- Auto-refresh: UI polls saved commands list every 5 seconds
- Persist saved commands to JSON file
- Import/export command libraries
- Command categories/tags
- Macro support (execute multiple commands in sequence)
- Scheduled command execution
- Command versioning
import requests
# Save a command
requests.post('http://localhost:5000/api/command/save',
json={'name': 'alert', 'command': {'type': 'blink', 'duration': 100}})
# List all commands
resp = requests.get('http://localhost:5000/api/command/list')
print(resp.json())
# Execute a saved command
requests.post('http://localhost:5000/api/command/execute',
json={'name': 'alert'})
# Delete a command
requests.post('http://localhost:5000/api/command/delete',
json={'name': 'alert'})// Save command
fetch('/api/command/save', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'test_blink',
command: {type: 'blink', duration: 500}
})
});
// Execute
fetch('/api/command/execute', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({name: 'test_blink'})
});# Save
curl -X POST http://localhost:5000/api/command/save \
-H "Content-Type: application/json" \
-d '{"name":"my_cmd","command":{"type":"led_on"}}'
# List
curl http://localhost:5000/api/command/list
# Execute
curl -X POST http://localhost:5000/api/command/execute \
-H "Content-Type: application/json" \
-d '{"name":"my_cmd"}'
# Delete
curl -X POST http://localhost:5000/api/command/delete \
-H "Content-Type: application/json" \
-d '{"name":"my_cmd"}'✅ Complete server-side control - Commands stored on PC, not ESP8266
✅ Full CRUD operations - Save, List, Execute, Delete
✅ User-friendly web UI - Visual command management
✅ REST API - Programmable access
✅ Auto-refresh - Real-time updates
✅ Logging - All operations logged
You now have complete freedom over how commands are stored and transmitted to your Arduino! 🎉