ESP-NOW Pairing
How LYNXcats connect to LYNXtower via ESP-NOW MAC address pairing.
Overview
The tower maintains a list of paired MAC addresses. Only frames from these addresses are accepted. Pairing mode allows new devices to register.
Operating Modes
Normal:
- Only accept frames from paired MAC addresses
- Reject all other senders
- Default state after boot
Pairing:
- Accept any valid InputFrame
- Auto-add new MAC addresses to paired list
- 60-second timeout → auto-return to Normal
- Max 8 devices
Button Events
Physical button on tower GPIO controls pairing:
| Press Duration | Action |
|---|---|
| Short (<3s) | Toggle between Normal ↔ Pairing |
| Long (≥3s) | Clear all paired devices + enter Pairing |
LED Feedback
WS2812B RGB LED indicates tower state:
| Pattern | Meaning |
|---|---|
| Off | Normal operation |
| Solid violet | Pairing mode active |
| Blinking violet | Pairing mode after clear-all |
| Green flash (1s) | New device paired |
| Triple cyan blink | Device already paired (duplicate) |
Flash Storage
Paired MAC addresses persist across reboots in ESP32-S3 flash.
Location: 0x0035_0000 (4KB partition)
Format: PairingConfig struct
- Magic bytes: 0xA5A5 (header validation)
- Version: u16 (format compatibility)
- Devices: Array of MAC addresses (max 8)
- Checksum: CRC32 (data integrity)
Operations:
- Read on boot → restore paired devices
- Write on add/remove → async flash erase + write
- Clear on long press → erase partition
Source Files
| File | Purpose |
|---|---|
pairing.rs | PairingManager core logic, OperatingMode enum |
pairing_controller.rs | State machine lifecycle, mode transitions |
button_monitor.rs | GPIO polling, short/long press detection |
led_feedback_task.rs | WS2812B RGB control, blink patterns |
flash_manager.rs | Async flash read/write/erase |
storage.rs | PairingConfig serialization, checksum |
Flow Diagram
User presses button
↓
button_monitor.rs detects press duration
↓
pairing_controller.rs transitions OperatingMode
↓
led_feedback_task.rs updates LED pattern
↓
pairing.rs accepts new frames (if Pairing mode)
↓
flash_manager.rs saves PairingConfig
↓
Timeout (60s) → auto-return to Normal
Implementation Notes
Boot sequence:
- flash_manager reads PairingConfig from 0x0035_0000
- PairingManager restores paired MACs
- Start in Normal mode
- LED off
Frame reception (Pairing mode):
- ESP-NOW receiver extracts sender MAC
- PairingManager checks if MAC exists
- If new → add to list, flash save, green LED
- If duplicate → triple cyan blink
Button long press:
- Clear all paired devices
- Erase flash partition
- Enter Pairing mode
- Blinking violet LED
Timeout:
- Embassy Timer fires after 60s
- Auto-transition Pairing → Normal
- LED off