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 DurationAction
Short (<3s)Toggle between Normal ↔ Pairing
Long (≥3s)Clear all paired devices + enter Pairing

LED Feedback

WS2812B RGB LED indicates tower state:

PatternMeaning
OffNormal operation
Solid violetPairing mode active
Blinking violetPairing mode after clear-all
Green flash (1s)New device paired
Triple cyan blinkDevice 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

FilePurpose
pairing.rsPairingManager core logic, OperatingMode enum
pairing_controller.rsState machine lifecycle, mode transitions
button_monitor.rsGPIO polling, short/long press detection
led_feedback_task.rsWS2812B RGB control, blink patterns
flash_manager.rsAsync flash read/write/erase
storage.rsPairingConfig 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:

  1. flash_manager reads PairingConfig from 0x0035_0000
  2. PairingManager restores paired MACs
  3. Start in Normal mode
  4. LED off

Frame reception (Pairing mode):

  1. ESP-NOW receiver extracts sender MAC
  2. PairingManager checks if MAC exists
  3. If new → add to list, flash save, green LED
  4. If duplicate → triple cyan blink

Button long press:

  1. Clear all paired devices
  2. Erase flash partition
  3. Enter Pairing mode
  4. Blinking violet LED

Timeout:

  • Embassy Timer fires after 60s
  • Auto-transition Pairing → Normal
  • LED off