-
Start Server:
cd server python3 firmware_server.py -
Open Browser: http://localhost:5000
-
Workflow:
- Send a command (e.g., click "Fast (250ms)")
- Enter name in "Command Name" field
- Click "Save Last Command"
- See it appear in "Saved Commands" list
- Click "Send" to execute it again anytime
POST /api/command/send- Queue a command immediatelyGET /api/command/get- ESP8266 polls for next commandPOST /api/command/ack- ESP8266 acknowledges commandPOST /api/device/report- Device status reportsGET /api/logs/get- Get recent logs
POST /api/command/save- Save a command with nameGET /api/command/list- List all saved commandsPOST /api/command/execute- Execute saved command (add to queue)POST /api/command/delete- Delete a saved command
{"type": "blink", "duration": 100} // Very fast
{"type": "blink", "duration": 500} // Normal
{"type": "blink", "duration": 2000} // Slow{"type": "led_on"} // Turn LED on
{"type": "led_off"} // Turn LED off
{"type": "stop"} // Stop blinking{"type": "ping"} // Test communication
{"type": "status"} // Get Arduino status# From web UI:
1. Click different preset speeds
2. Find the one you like
3. Save it with a memorable name
4. Execute it later with one clickimport requests
SERVER = 'http://localhost:5000'
# Save multiple commands
commands = {
'startup': {'type': 'blink', 'duration': 200},
'idle': {'type': 'blink', 'duration': 1000},
'alert': {'type': 'blink', 'duration': 50},
'off': {'type': 'led_off'}
}
for name, cmd in commands.items():
requests.post(f'{SERVER}/api/command/save',
json={'name': name, 'command': cmd})import requests
import time
SERVER = 'http://localhost:5000'
# Execute saved commands in sequence
sequence = ['startup', 'idle', 'alert', 'off']
for cmd_name in sequence:
requests.post(f'{SERVER}/api/command/execute',
json={'name': cmd_name})
time.sleep(5) # Wait 5 seconds between commands# Save from command line
curl -X POST http://192.168.1.100:5000/api/command/save \
-H "Content-Type: application/json" \
-d '{"name":"remote_blink","command":{"type":"blink","duration":300}}'
# Execute from anywhere on network
curl -X POST http://192.168.1.100:5000/api/command/execute \
-H "Content-Type: application/json" \
-d '{"name":"remote_blink"}'- Immediately adds to queue
- ESP8266 gets it on next poll (~3 seconds)
- Use for: One-time commands, testing, manual control
- Stored on server (reusable)
- Execute when needed (not automatic)
- Use for: Frequently-used commands, automation, sequences
Edit src/esp8266_programmer.cpp:
const unsigned long POLL_INTERVAL = 3000; // Change to desired msAdd to server/firmware_server.py:
import json
def save_to_file():
with open('saved_commands.json', 'w') as f:
json.dump(saved_commands, f)
def load_from_file():
try:
with open('saved_commands.json', 'r') as f:
return json.load(f)
except FileNotFoundError:
return {}
# At startup:
saved_commands = load_from_file()
# After save/delete:
save_to_file()curl http://localhost:5000/api/command/list | python3 -m json.toolcurl http://localhost:5000/api/logs/get | python3 -m json.toolThe terminal running firmware_server.py shows:
- 💾 Command saved: [name] -> [command]
▶️ Executing saved command: [name] ([type])- 🗑️ Deleted saved command: [name]
- Real-time list - Auto-refreshes every 5 seconds
- Styled table - Easy to read, hover effects
- Action buttons - Send and Delete for each command
- Save interface - Name input + save button
- Integrated logs - All operations logged below
- 🔵 Blue buttons - Normal actions (Send, Set)
- 🔴 Red buttons - Destructive actions (Delete, Stop)
- 🟢 Green accents - Success messages
- 🟡 Hover effects - Interactive feedback
- Check server logs for errors
- Verify command name exists:
GET /api/command/list - Check queue size (might be backlogged)
- Ensure ESP8266 is connected and polling
- Send a command first (click any button)
- Enter a valid name (no spaces recommended)
- Check browser console for errors
- Try via API directly (see curl examples above)
- In-memory storage: restarting server clears saved commands
- Add file persistence (see Configuration section)
- Storage: In-memory only (runtime persistence)
- Thread-safe: Flask default mode (single-threaded)
- Capacity: Unlimited (RAM is limit)
- Naming: Use alphanumeric + underscore (e.g.,
fast_blink_1) - Overwrite: Saving with same name overwrites previous command
- ✅ Basic Usage - Save and execute a few commands
- ✅ API Testing - Try curl commands
- ✅ Automation - Write a Python script to control Arduino
- 📦 Persistence - Add file saving (optional)
- 🔄 Sequences - Build command macros (future feature)
Have fun with your Arduino R4 Command Center! 🎉