Fatigue Test ESP-NOW System Documentation
Overview
This directory contains the fatigue test unit firmware that communicates with a remote controller via ESP-NOW. The system implements secure mutual authentication for device pairing and efficient bounds caching for improved test workflow.
Documentation Index
| Document | Description |
|---|---|
| PAIRING_PROTOCOL.md | Secure ESP-NOW pairing with HMAC-SHA256 authentication |
| BOUNDS_CACHING.md | Bounds finding cache system for efficient test workflow |
Architecture
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β REMOTE CONTROLLER β
β βββββββββββββββ βββββββββββββββββββ ββββββββββββββββββ β
β β Display β β Encoder/Buttons β β ESP-NOW TX/RX β β
β βββββββββββββββ βββββββββββββββββββ βββββββββ¬βββββββββ β
β β β
β Pairing Manager β β
β Peer Store (NVS) β β
ββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββ
β
β ESP-NOW (2.4 GHz)
β - Config messages
β - Commands
β - Status updates
β - Pairing protocol
β
ββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββ
β FATIGUE TEST UNIT β β
β β β
β ββββββββββββββββββ βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ β
β β UART Console β β ESP-NOW Receiver β β
β β - commands β β - Pairing responder β β
β β - status β β - Message validation β β
β β - config β β - Peer store (NVS) β β
β βββββββββ¬βββββββββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β ββββββββββββΊβ Motion Controller β β
β β - Bounds finding (StallGuard/Encoder) β β
β β - Point-to-point motion β β
β β - Cycle counting β β
β β - Bounds cache (2 min validity) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β TMC5160 Driver β β
β β - SPI communication β β
β β - StallGuard2 β β
β β - Ramp generator β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Quick Start
1. Hardware Setup
Connect the TMC5160 driver to the ESP32 using the configured SPI pins (see esp32_tmc51x0_test_config.hpp).
2. First-Time Pairing
On Fatigue Test Unit (UART):
1
2
3
4
> pair
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Pairing mode enabled for 30 seconds. β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
On Remote Controller:
- Navigate to Settings β Pair Device
- Press to initiate pairing
- Wait for βPairing Successfulβ message
3. Running a Test
Quick workflow:
1
2
3
4
5
6
7
8
# Configure test parameters
> set -f 0.5 -c 1000 -b -60 60
# Start test (auto-finds bounds)
> start
# Monitor status
> status
Optimized workflow (with bounds cache):
1
2
3
4
5
6
7
8
# Pre-find bounds
> bounds
# Adjust settings as needed
> set -f 0.7
# Start immediately (skips bounds finding)
> start
UART Commands
| Command | Description |
|---|---|
set [options] |
Configure test parameters |
start |
Start fatigue test |
stop |
Stop fatigue test |
pause |
Pause (motor de-energized) |
resume |
Resume from pause |
bounds |
Run bounds finding independently |
reset |
Reset cycle counter |
status |
Show current status |
pair |
Enter pairing mode (30 sec) |
help [cmd] |
Show help |
SET Options
| Option | Description | Range |
|---|---|---|
-f, --frequency <Hz> |
Motion frequency | 0.01 - 10.0 |
-d, --dwell <min> <max> |
Dwell times (ms) | 0 - 60000 |
-b, --bounds <min> <max> |
Angle bounds (Β°) | -180 to 180 |
-c, --cycles <count> |
Target cycles | 0 = infinite |
Security
Pairing Secret Configuration
The pairing secret is not hardcoded in the source code. Itβs injected at build time for security.
Quick Setup:
1
2
3
4
5
6
7
8
9
10
11
# 1. Generate a secret
openssl rand -hex 16
# 2. Copy the template (in each project directory)
cp secrets.template.yml secrets.local.yml
# 3. Edit secrets.local.yml with your secret
# espnow_pairing_secret: "your_32_char_hex_secret"
# 4. Build (secret is automatically loaded)
./scripts/build_app.sh fatigue_test_espnow_unit Release
Alternative Methods:
1
2
3
4
5
6
# Via command line
./scripts/build_app.sh fatigue_test_espnow_unit Release --secret abc123...
# Via environment variable
export ESPNOW_PAIRING_SECRET="abc123..."
./scripts/build_app.sh fatigue_test_espnow_unit Release
IMPORTANT: Both devices must use the same secret!
Approved Peers
- Stored in NVS (survives reboot)
- Maximum 4 peers per device
- Pre-configured MAC addresses automatically approved
Troubleshooting
βNot in pairing modeβ error
- Run
pairon the fatigue test unit first - Then initiate pairing from the remote within 30 seconds
βHMAC verification failedβ
Devices have different PAIRING_SECRET. Ensure both are compiled with identical espnow_security.hpp.
Bounds finding fails
- Check mechanical limits are reachable
- Verify StallGuard threshold is appropriate
- Try encoder-based bounds finding
Motor overheats
- Reduce test frequency
- Add dwell time between directions
- Check bounds cache timeout settings
File Structure
1
2
3
4
5
6
7
8
9
10
11
fatigue_test_espnow/
βββ main.cpp # Application entry point, UART command handler
βββ espnow_receiver.cpp/hpp # ESP-NOW communication, pairing responder
βββ espnow_protocol.hpp # Protocol message definitions
βββ espnow_security.hpp # Security constants, HMAC functions
βββ espnow_peer_store.cpp/hpp # NVS-based peer storage
βββ fatigue_motion.cpp/hpp # Motion controller, bounds finding
βββ docs/
βββ README.md # This file
βββ PAIRING_PROTOCOL.md # Pairing protocol specification
βββ BOUNDS_CACHING.md # Bounds cache system documentation
Related Documentation
- TMC5160 Datasheet:
docs/docs/datasheet/TMC5160A_datasheet_rev1.18.pdf - Driver API:
docs/api_reference.md - Hardware Setup:
docs/hardware_setup.md