Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
683 commits
Select commit Hold shift + click to select a range
84dad3c
Merge pull request #647 from doudar/revert-646-ArduinoAsAComponent
doudar Jun 25, 2025
ecc4d22
Changes from @h2zero
doudar Jun 26, 2025
2c77c17
Revert "Changes from @h2zero"
doudar Jun 26, 2025
1fea7c7
builds in pio
doudar Jun 26, 2025
e529fbf
updated github build. Updated max connections.
doudar Jun 26, 2025
e9c8084
changed computation timeout and maintenance loop priority
doudar Jun 27, 2025
c8a5cac
updated connection params
doudar Jun 30, 2025
250ec95
fixed reboot on firmware update page load. Fixed BLE connections bein…
doudar Jul 2, 2025
cbbf52b
fixed Dircon
doudar Jul 2, 2025
3b2731e
Improved BLE connection speed
doudar Jul 2, 2025
10b2584
added new fillByAverage()
doudar Jul 2, 2025
ef2333e
ptab4pwr skips reliability checks
doudar Jul 2, 2025
c1af5e8
load table faster if ptab4pwr and always provide power output if ther…
doudar Jul 2, 2025
6eb9143
bugfix
doudar Jul 2, 2025
d67268b
turned off fillbyaverage
doudar Jul 3, 2025
e3b1715
remove weighted downvoting
doudar Jul 3, 2025
897d9fc
fixed tests
doudar Jul 3, 2025
e5a42cf
Merge branch 'ArduinoAsAComponent' of https://github.com/doudar/Smart…
doudar Jul 3, 2025
9e222c0
new completePowerTable() method
doudar Jul 4, 2025
27bf41d
run fill until done. Don't enfore monotonicity on entries with readin…
doudar Jul 4, 2025
16d7d58
higher reading wins
doudar Jul 4, 2025
82245e4
0 is back
doudar Jul 4, 2025
a4088c9
Allow more change
doudar Jul 4, 2025
92c046f
operator change
doudar Jul 4, 2025
2fd52e4
Give fill some cadence to always work with
doudar Jul 4, 2025
9fbb22a
give cadence a chance
doudar Jul 5, 2025
b85ad4b
attempting to fill all columns and rows.
doudar Jul 5, 2025
258017f
Added second cadence pass
doudar Jul 5, 2025
f136b0e
only add readings on first order guesses
doudar Jul 5, 2025
3c76d85
bugfix
doudar Jul 10, 2025
4e917b8
Test now creates a power table that you can scroll through time on by…
doudar Jul 13, 2025
b25fd1d
code cleanup
doudar Jul 13, 2025
e5d145a
sliders both work in test mode
doudar Jul 13, 2025
1e31cc5
Drastic table changes
doudar Jul 14, 2025
28b733c
added timeout to homing. Fixed bug with hmin and hmax not being set o…
doudar Jul 17, 2025
341d4ed
added fillGaps().
doudar Jul 17, 2025
0526b57
homing required to save and load tables.
doudar Jul 18, 2025
a7de057
added another ride log
doudar Jul 19, 2025
cd383eb
always set connected PM, CD and Speed to false when a PM disconnects.
doudar Jul 22, 2025
1d36b62
Homing communication with client fixed
doudar Jul 29, 2025
ed3245d
These files didn't change, but it makes me try it...
doudar Jul 29, 2025
f06b99f
Merge branch 'develop' into ArduinoAsAComponent
doudar Jul 29, 2025
3ea4359
Update changelog for version 25.5.31
actions-user Jul 29, 2025
99e92d2
Merge pull request #649 from doudar/ArduinoAsAComponent
doudar Jul 29, 2025
7ffa18e
removed data_helpers.h
doudar Jul 29, 2025
78e3024
updated changelog
doudar Jul 29, 2025
e981a50
added license
doudar Jul 29, 2025
6ba0d96
Merge pull request #650 from doudar/ArduinoAsAComponent
doudar Jul 29, 2025
07adc8a
Fixed unterminated comment
doudar Jul 29, 2025
8e69346
Merge pull request #651 from doudar/ArduinoAsAComponent
doudar Jul 29, 2025
00ec838
Fixed BLE and WiFI (App) updates
doudar Jul 30, 2025
6d1b96e
Update changelog for version 25.7.29
actions-user Jul 30, 2025
737afba
Updated Changelog
doudar Jul 30, 2025
fbee391
Merge branch 'UpdatesFix' of https://github.com/doudar/SmartSpin2k in…
doudar Jul 30, 2025
5440eda
Merge pull request #652 from doudar/UpdatesFix
doudar Jul 30, 2025
377786b
Improves power table handling and homing
doudar Jul 31, 2025
38d9d7b
- Fixed edge cases of pTab4Pwr causing runaways.
doudar Jul 31, 2025
90b15e7
Update changelog for version 25.7.30
actions-user Jul 31, 2025
fb1bbd0
Update settings.h
doudar Jul 31, 2025
430a10f
Merge pull request #653 from doudar/pTab4Pwr-Improvements
doudar Jul 31, 2025
810f122
Power without table now 1/2 of cadence.
doudar Jul 31, 2025
8797f9d
Merge branch 'pTab4Pwr-Improvements' of https://github.com/doudar/Sma…
doudar Jul 31, 2025
54c3c56
updated changelog
doudar Aug 1, 2025
3fa68a9
Merge pull request #654 from doudar/pTab4Pwr-Improvements
doudar Aug 2, 2025
0624984
Fixed MyWoosh Dircon
doudar Aug 3, 2025
6f3d656
Merge pull request #655 from doudar/pTab4Pwr-Improvements
doudar Aug 3, 2025
ee33601
Bump actions/download-artifact from 4 to 5
dependabot[bot] Aug 5, 2025
9325062
Update changelog for version 25.8.3
actions-user Aug 5, 2025
db95625
debounce rework - faster shifting
doudar Aug 7, 2025
8e4a7b9
Increased delay.
doudar Aug 9, 2025
7e49848
Switched to state machine
doudar Aug 9, 2025
726cd9c
refined homing procedure
doudar Aug 10, 2025
47ba283
Bump actions/checkout from 4 to 5
dependabot[bot] Aug 12, 2025
d7246b6
Update changelog for version 25.8.3
actions-user Aug 12, 2025
5b67394
Fixed many timings
doudar Aug 16, 2025
67956b7
updated changelog.md
doudar Aug 16, 2025
6fb654c
updated changelog
doudar Aug 16, 2025
9ec229d
Update changelog for version 25.8.3
actions-user Aug 16, 2025
1e5d300
fixed homing logging
doudar Aug 16, 2025
eb64e39
Merge pull request #658 from doudar/Debounce-Rework
doudar Aug 16, 2025
977ddcd
bugfix for rare crash while scanning
doudar Aug 17, 2025
e98381d
updated changelog.
doudar Aug 17, 2025
45aeafd
Merge pull request #659 from doudar/Debounce-Rework
doudar Aug 17, 2025
7f9bdc7
Better OTA reliability
doudar Aug 17, 2025
62a7046
increased webserver delay
doudar Aug 18, 2025
8436258
Update changelog for version 25.8.16
actions-user Aug 18, 2025
dac0519
Update src/HTTP_Server_Basic.cpp
doudar Aug 18, 2025
804de4d
Merge pull request #660 from doudar/Update-reliability
doudar Aug 18, 2025
276d3f0
Fixed Echelon connections.
doudar Aug 24, 2025
ecc4f78
Update changelog for version 25.8.18
actions-user Aug 24, 2025
9db8dc2
Echelon connection is working
doudar Aug 24, 2025
bb9f7ef
Update src/BLE_Client.cpp
doudar Aug 26, 2025
faed3e6
Merge pull request #661 from doudar/EchelonConnectFix
doudar Aug 26, 2025
4d7576c
Bump actions/setup-python from 5 to 6
dependabot[bot] Sep 4, 2025
a65f7a0
Bump actions/github-script from 7 to 8
dependabot[bot] Sep 4, 2025
75718c1
Update changelog for version 25.8.26
actions-user Sep 4, 2025
10eacb5
Update changelog for version 25.8.26
actions-user Sep 4, 2025
446ee12
Initial plan
Copilot Sep 6, 2025
06e935b
Implement Android BLE unique name generation enhancement
Copilot Sep 6, 2025
6b3db4e
Add clarifying comments for Android BLE unique name behavior
Copilot Sep 6, 2025
b06920a
BLE client: Stable unique names for private random addresses
doudar Sep 8, 2025
c7f6c9e
Update changelog for version 25.8.26
actions-user Sep 8, 2025
bbdb795
Initial plan
Copilot Sep 8, 2025
fa909e7
Implement WiFi OTA recovery with build version tracking
Copilot Sep 8, 2025
a2032f8
updated changelog
doudar Sep 8, 2025
fe0a312
Merge pull request #666 from doudar/copilot/fix-9679f638-4219-4431-a9…
doudar Sep 8, 2025
bd2309a
chore(ci): skip actions for Dependabot PR #665 [skip actions]
doudar Sep 9, 2025
d4ff81f
[skip actions]
doudar Sep 9, 2025
07927fe
[skip actions]
doudar Sep 9, 2025
02c65f9
[skip actions]
doudar Sep 9, 2025
d3fbb07
Merge branch 'develop' into dependabot/github_actions/actions/downloa…
doudar Sep 9, 2025
4b7485c
Merge pull request #656 from doudar/dependabot/github_actions/actions…
doudar Sep 9, 2025
2e5fbc5
Merge pull request #657 from doudar/dependabot/github_actions/actions…
doudar Sep 9, 2025
b374b63
Merge pull request #664 from doudar/dependabot/github_actions/actions…
doudar Sep 9, 2025
b73d75c
Merge pull request #665 from doudar/dependabot/github_actions/actions…
doudar Sep 9, 2025
607697e
added NVS check in addition to config file. This is belt + suspenders…
doudar Sep 10, 2025
280bdc5
Update changelog for version 25.8.26
actions-user Sep 10, 2025
3c347f9
updated changelog.md
doudar Sep 10, 2025
371f2fd
Merge branch 'copilot/handle-wifi-issues-after-ota-update' of https:/…
doudar Sep 10, 2025
ab69c77
Merge branch 'develop' into copilot/handle-wifi-issues-after-ota-update
doudar Sep 15, 2025
8582d52
Update changelog for version 25.9.8
actions-user Sep 15, 2025
0080a41
moved ridelog.txt so tests complete
doudar Sep 15, 2025
1d783ee
Initial plan
Copilot Sep 16, 2025
14f7c84
Initial plan
Copilot Sep 16, 2025
7f9ef10
Implement resistance calculation for non-resistance reporting bikes
Copilot Sep 16, 2025
ad1878a
Improve resistance detection logic for better compatibility
Copilot Sep 16, 2025
9c1689c
Add comprehensive GitHub Copilot instructions for SmartSpin2k develop…
Copilot Sep 16, 2025
d036d54
Removed 5 minute battery update to test fix for tempo power meter.
doudar Sep 16, 2025
415c935
Update changelog for version 25.9.8
actions-user Sep 16, 2025
319e1c5
Initial plan
Copilot Sep 16, 2025
96ce743
Add uniqueName field to SpinBLEAdvertisedDevice for stable device ide…
Copilot Sep 16, 2025
acf273f
Add comprehensive tests and fix assignment bug in remote device matching
Copilot Sep 16, 2025
3492015
Moved battery information to the SpinBLEAdvertisedDevice class.
doudar Sep 16, 2025
1c41de1
[actions skip]
doudar Sep 16, 2025
4603784
Update changelog for version 25.9.8
actions-user Sep 16, 2025
37d51c0
[skip actions] Merge pull request #673 from doudar/copilot/fix-672
doudar Sep 16, 2025
e1b6fa4
Merge branch 'develop' into Tempo-Drop-Fix
doudar Sep 17, 2025
5c89512
[skip actions] Merge pull request #674 from doudar/Tempo-Drop-Fix
doudar Sep 17, 2025
a6bfc6e
Merge branch 'develop' into copilot/fix-675
doudar Sep 17, 2025
2ec9fa3
updated changelog
doudar Sep 17, 2025
4c3c9f1
Stopped reusing BLE clients for better connection reliability.
doudar Sep 17, 2025
1b64b40
Merge pull request #676 from doudar/copilot/fix-675
doudar Sep 17, 2025
4921a89
Merge branch 'develop' into copilot/fix-573
doudar Sep 17, 2025
d4df7e8
better log in scan callback
doudar Sep 18, 2025
ff321c4
Merge branch 'develop' into copilot/fix-573
doudar Sep 18, 2025
a8efd34
Update changelog for version 25.9.17
actions-user Sep 18, 2025
8cb5b9c
More stable connect/reconnect
doudar Sep 18, 2025
ce3a420
Update platformio.ini
doudar Sep 19, 2025
aa5ad45
Add BLE client disconnect detection timeout mechanism
Copilot Sep 19, 2025
70d3067
Fix parentheses in comment causing syntax validation issue
Copilot Sep 19, 2025
718d831
onDisconnect working
doudar Sep 19, 2025
126d68d
Cleaned up pelotonIsConnected flag usage
doudar Sep 20, 2025
2797ba2
fix exchange mtu bug.
doudar Sep 20, 2025
6995f5f
Cleanup unused function, tested resistance mode.
doudar Sep 20, 2025
23bb21f
faster BLE connections
doudar Sep 21, 2025
4bd6cbd
added the timeout check back because there are still some disconnects…
doudar Sep 22, 2025
1127c31
removed double definition
doudar Sep 22, 2025
34f7aa4
removed client checking for "rebooting due to inactivity."
doudar Sep 22, 2025
61e4a72
automatic reboot fixes. Improved scan reliability.
doudar Sep 22, 2025
aa3d2db
Update src/BLE_Fitness_Machine_Service.cpp
doudar Sep 22, 2025
f0a801e
Update src/BLE_Common.cpp
doudar Sep 22, 2025
6d749ea
Update src/BLE_Client.cpp
doudar Sep 22, 2025
d25fb31
Merge pull request #670 from doudar/copilot/fix-573
doudar Sep 22, 2025
b7441b0
Fixed incline mode handling negative numbers.
doudar Sep 30, 2025
341ac7d
Merge branch 'develop' into copilot/handle-wifi-issues-after-ota-update
doudar Oct 11, 2025
64eed91
Update changelog for version 25.9.30
actions-user Oct 11, 2025
1d80d56
BLE advertisement data reworked and optimized.
doudar Oct 19, 2025
4a5300c
Merge pull request #668 from doudar/copilot/handle-wifi-issues-after-…
doudar Oct 19, 2025
3e6ddb6
Update CHANGELOG.md
doudar Oct 19, 2025
bf2957d
Merge branch 'develop' of https://github.com/doudar/SmartSpin2k into …
doudar Oct 19, 2025
c6e31d9
Resolved merge conflicts
doudar Oct 19, 2025
bcdd6cb
Fixed Rouvy Connection 25-10-18 caused.
doudar Oct 19, 2025
7b19d39
Added Merach bike
doudar Oct 31, 2025
9a1a5d7
Update Merach.AD_PRT
doudar Oct 31, 2025
12a4b4f
Update changelog for version 25.10.19
actions-user Oct 31, 2025
3a2a6d2
Testing
doudar Nov 2, 2025
6245b2b
Update changelog for version 25.10.19
actions-user Nov 2, 2025
89b8c78
Added Merach Small for testing
doudar Nov 2, 2025
5d75468
Fixed Rouvy Dircon
doudar Nov 2, 2025
0059bba
Logging fixes and data length fixes
doudar Nov 3, 2025
671ff2b
Connecting to Rouvy
doudar Nov 3, 2025
03fde07
set logging back to normal.
doudar Nov 3, 2025
2f6bcad
Update changelog for version 25.10.19
actions-user Nov 3, 2025
c383689
Update src/DirConMessage.cpp
doudar Nov 3, 2025
99b7871
Merge pull request #687 from doudar/Rouvy_Dircon_2
doudar Nov 3, 2025
af099c6
Updated build scripts
doudar Nov 3, 2025
b0babb8
Merge branch 'develop' into ble_debug
doudar Nov 3, 2025
943a39b
Update changelog for version 25.11.3
actions-user Nov 3, 2025
4c4d2b2
Update src/BLE_Client.cpp
doudar Nov 3, 2025
083bc10
Update src/BLE_Client.cpp
doudar Nov 4, 2025
ba4c7fc
Fixed String Comparison
doudar Nov 4, 2025
982b5dc
Merge pull request #686 from doudar/ble_debug
doudar Nov 4, 2025
e0a654e
updated size
doudar Nov 12, 2025
4f8f553
Merge branch 'develop' into Merach
doudar Nov 13, 2025
6260ba9
Merge pull request #685 from doudar/Merach
doudar Nov 13, 2025
fe40112
Supported resistance level updated.
doudar Nov 17, 2025
cad0ed8
Faster response
doudar Nov 17, 2025
50f941a
Update changelog for version 25.11.4
actions-user Nov 18, 2025
076e20c
Added fallback to ERG while in resistance mode if we have no position…
doudar Nov 18, 2025
7010d7b
Merge branch 'Resistance_level_fix' of https://github.com/doudar/Smar…
doudar Nov 18, 2025
b32c3ea
comments and changelog updated.
doudar Nov 18, 2025
5cfa349
tweaked response in Resistance Mode
doudar Nov 18, 2025
0268b63
Merge pull request #698 from doudar/Resistance_level_fix
doudar Nov 19, 2025
103c029
Make Zwift happy during spin down by sending "stop pedaling" every 1 …
doudar Nov 21, 2025
531c472
Add power scalers for stepper hold and homing; update driver settings…
doudar Nov 24, 2025
2f13394
Update changelog for version 25.11.21
actions-user Nov 24, 2025
6b8b6f1
Cadence needs to be >5 to initiate homing.
doudar Nov 24, 2025
34b064b
added ftms homing user abort
doudar Nov 24, 2025
f6fb53f
Minor text changes
doudar Nov 24, 2025
f7eca62
divide by 4 for resistance homing
doudar Nov 24, 2025
a7de037
Added test to make sure cadence is detected multiple times before hom…
doudar Nov 30, 2025
47d1340
require cadence for 2 seconds before homing
doudar Dec 1, 2025
25b41f5
reduced delay to power down.
doudar Dec 1, 2025
82ae6ee
More homing refinements
doudar Dec 2, 2025
693f161
Merge pull request #703 from doudar/Resistance_Home_Control
doudar Dec 2, 2025
9a0a858
Update links card
ikishk Dec 3, 2025
8247c2f
Update CHANGELOG.md
ikishk Dec 11, 2025
9ab43e8
Merge pull request #705 from ikishk/develop
doudar Dec 11, 2025
5b10d66
Fix for Zwift On Android.
doudar Dec 17, 2025
172450b
IC4 reported HR won't override other HRM.
doudar Dec 18, 2025
f59ae77
Improved ERG response for homed tables.
doudar Dec 18, 2025
0370672
Update changelog for version 25.12.17
actions-user Dec 18, 2025
e1b7c84
Minor changes before merge
doudar Dec 18, 2025
1b8b970
updated default settings
doudar Dec 18, 2025
c06bf67
Merge pull request #708 from doudar/IC4_HR_Override
doudar Dec 19, 2025
0556ac4
- Removed >0 watts requirement to compute ERG.
doudar Dec 25, 2025
b1f11fc
bugfixes
doudar Dec 28, 2025
48a00fb
Working with Mark Roy to tune PID
doudar Dec 30, 2025
143c791
Merged Mark Roy with Marc Roy
doudar Dec 31, 2025
48914a7
Update changelog for version 25.12.28
actions-user Dec 31, 2025
42de858
Update src/ERG_Mode.cpp
doudar Dec 31, 2025
711cf25
Update src/SensorCollector.cpp
doudar Dec 31, 2025
25ba34b
- Added feed forward, disabled PowerTable for ERG lookup.
doudar Dec 31, 2025
7a4d78d
Added tests and removal of duplicates in pt column.
doudar Jan 1, 2026
2b6b4a5
cleanup
doudar Jan 2, 2026
b09376b
Set gear 8 after startup homing
doudar Jan 2, 2026
e64c726
After startup homing, set gear 8.
doudar Jan 2, 2026
fab06c2
Merge pull request #711 from doudar/Marc_Roy
doudar Jan 2, 2026
bc8ac33
experimental lookup methods
doudar Jan 2, 2026
f734aa2
before removing monotonicity in favor of regression
doudar Jan 3, 2026
e58e547
Ready to test again.
doudar Jan 4, 2026
656394c
added y-axis lock to testing
doudar Jan 4, 2026
808c554
Load power table if not yet loaded during session
doudar Jan 4, 2026
9a681ce
working great. needs cleanup.
doudar Jan 5, 2026
453c969
Cleanup
doudar Jan 5, 2026
698bc28
Refactor ERG mode logic and improve cadence calculations; add mode st…
doudar Jan 8, 2026
55995e7
testing complete
doudar Jan 10, 2026
e6ce99d
Merge pull request #713 from doudar/Marc_Roy
doudar Jan 10, 2026
d419854
Merge pull request #4 from doudar/develop
jrbarrick Jan 11, 2026
a0d99df
Merge branch 'joroto' into develop-joroto-merge-testing
jrbarrick Jan 11, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .actrc
Empty file.
130 changes: 130 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# SmartSpin2k - ESP32 Smart Trainer Firmware

SmartSpin2k is an ESP32-based DIY smart trainer project that converts any spin bike into a connected fitness device compatible with Zwift, TrainerRoad, and other training apps. The firmware controls stepper motor resistance, handles BLE communication, serves a web interface, and manages sensor data.

Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.

## Working Effectively

### Bootstrap Environment
Install required tools and dependencies:
- `sudo apt-get update && sudo apt-get install -y build-essential git python3 python3-pip`
- `pip install platformio pre-commit`
- `pre-commit install --hook-type pre-push`

### Build the Firmware
- **CRITICAL**: Build takes 15-45 minutes depending on network connectivity. NEVER CANCEL. Set timeout to 60+ minutes.
- `pio run --environment release` -- builds ESP32 firmware. NEVER CANCEL: Build takes 15-45 minutes on first run due to platform/toolchain downloads.
- `pio run --target buildfs` -- builds filesystem. Takes 2-5 minutes.
- **Network Issues**: If platform downloads fail with HTTPClientError, this is due to firewall/network restrictions. The build cannot proceed without internet access to download ESP32 toolchain.

### Testing
- **CRITICAL**: Native tests take 5-15 minutes. NEVER CANCEL. Set timeout to 30+ minutes.
- `pio test --environment native` -- runs unit tests using Unity framework. NEVER CANCEL: Takes 5-15 minutes on first run.
- Tests validate sensor data parsing, power calculations, BLE communication, and stepper motor control.
- **Network Issues**: Native platform download may fail with HTTPClientError due to firewall restrictions.

### Code Quality and Validation
- `pre-commit run --all-files` -- runs license header insertion. Takes 1-2 minutes.
- `pio check -e debug` -- runs cppcheck static analysis on debug environment. Takes 2-5 minutes. **Network Issues**: May fail with HTTPClientError due to platform download restrictions.
- Python build scripts (always work):
- `python git_tag_macro.py` -- generates firmware version from git tags
- `python build_date_macro.py` -- generates build timestamp
- `python cert_updater.py` -- updates SSL certificates (may fail with network issues)

### Run the Application
- **Build First**: Always complete the bootstrap and build steps before attempting to run.
- The application runs on ESP32 hardware - cannot be executed in the sandbox environment.
- Web interface available at device IP on port 80 when running on hardware.
- BLE services broadcast as "SmartSpin2k" when running on hardware.

## Validation

### Manual Testing Scenarios
After making code changes, always validate:
1. **Build Validation**: Ensure `pio run --environment release` completes successfully.
2. **Test Validation**: Ensure `pio test --environment native` passes all Unity tests.
3. **Code Quality**: Run `pre-commit run --all-files` and fix any license header issues.
4. **BLE Service Changes**: When modifying BLE services, verify characteristic UUIDs match the CustomCharacteristic.md specification.
5. **Power Calculations**: When changing power table or ERG mode code, run tests in test_pt_lookup_*.cpp files.
6. **Sensor Data**: When modifying sensor parsing, validate with tests in test_*Data.cpp files.

### Critical Areas to Test
- **Power Table**: Always validate power lookup and resistance calculations after changes to Power_Table.cpp or PowerTable_Helpers.cpp
- **BLE Services**: Test characteristic read/write operations when modifying BLE_*_Service.cpp files
- **ERG Mode**: Validate resistance control when changing ERG_Mode.cpp
- **Stepper Control**: Test motor control when modifying stepper-related code in Main.cpp

## Common Tasks

### Repository Structure
Key directories and their purpose:
```
/src -- Main ESP32 firmware source code
/lib/SS2K/src -- Core library with sensor parsing and data structures
/include -- Header files and configuration
/test -- Unity unit tests for native environment
/data -- Web interface HTML/CSS files
/Hardware -- 3D printing files and PCB designs
/.github/workflows -- CI/CD pipeline definitions
```

### Important Files
- `platformio.ini` -- Build configuration for ESP32 and native environments
- `include/settings.h` -- Hardware pin definitions and configuration constants
- `CustomCharacteristic.md` -- BLE characteristic specification and usage
- `src/Main.cpp` -- Main firmware entry point and setup
- `lib/SS2K/src/sensors/` -- Sensor data parsing classes

### Build Dependencies
External libraries loaded automatically by PlatformIO:
- NimBLE-ESP32 for Bluetooth Low Energy
- TMCStepper for stepper motor control
- FastAccelStepper for smooth motor movement
- ArduinoJson for configuration and web API
- ArduinoWebsockets for real-time web communication

### Configuration
- Default device name: "SmartSpin2k"
- Default WiFi password: "password"
- Web interface served on port 80
- BLE service UUID: "77776277-7877-7774-4466-896665500000"
- Over-the-air update URL: configured in settings.h

### Hardware Compatibility
- ESP32 DevKit v1 board (primary target)
- TMC2209 stepper motor driver
- Custom PCB designs in Hardware/ directory
- Support for multiple bike mount configurations

### Known Issues and Limitations
- **Network Connectivity**: Platform and toolchain downloads may fail due to firewall restrictions. All build commands (`pio run`, `pio test`, `pio check`) require internet access on first run.
- **SSL Certificates**: cert_updater.py may fail to fetch current certificates due to network restrictions
- **Hardware Testing**: Cannot test actual motor control or BLE communication without physical hardware
- **Build Times**: Initial builds require internet access and take 15-45 minutes due to large platform downloads

### Troubleshooting Common Issues
- **HTTPClientError during build**: This indicates network/firewall restrictions preventing platform downloads. No workaround available in restricted environments.
- **Platform not found**: Run `pio platform install espressif32` to manually install the ESP32 platform (requires internet).
- **Test failures**: Ensure you're running tests in native environment: `pio test -e native`
- **SSL certificate warnings**: Update certificates with `python cert_updater.py` or manually update `include/cert.h`
- **Build flag errors**: The Python scripts in build_flags must execute successfully. Test them individually if build fails.

### Environment Verification
Before working on the project, verify your environment:
```bash
# Check tools are installed
which python3 pio pre-commit
# Verify project configuration
pio project config
# Test build scripts
python git_tag_macro.py && python build_date_macro.py
```

### Debugging Tips
- Use `pio device monitor` to view serial output when connected to ESP32 hardware
- Check `include/cert.h` if experiencing SSL errors during firmware updates
- Monitor memory usage with DEBUG_STACK enabled in settings.h
- BLE debugging available through web interface at `/develop.html`

Always run `pre-commit run --all-files` before completing changes to ensure code meets project standards.
46 changes: 38 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,29 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Cache PlatformIO
uses: actions/cache@v4
with:
path: ~/.platformio
key: ${{ runner.os }}-platformio-${{ hashFiles('platformio.ini') }}
restore-keys: |
${{ runner.os }}-platformio-
- name: Ensure changelog is updated
uses: dangoslen/changelog-enforcer@v3.6.1
- name: Set up python
uses: actions/setup-python@v5
uses: actions/setup-python@v6
with:
python-version: '3.x'
python-version: '3.11'
architecture: 'x64'
- name: Upgrade pip tooling
run: |
python -m pip install --upgrade pip setuptools wheel
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%y.%-m.%-d')"
run: echo "date=$(date +'%y.%-m.%-d')" >> $GITHUB_OUTPUT
- name: Test with environment variables
run: echo $TAG_NAME - $RELEASE_NAME
env:
Expand All @@ -43,12 +53,32 @@ jobs:
run: python --version
- name: Install PlatformIO
run: python -m pip install platformio
- name: Pre-install PlatformIO packages (release env)
run: platformio pkg install -e release
- name: Ensure ESP-IDF component manager is available
shell: bash
run: |
set -euo pipefail
PIO_HOME="$HOME/.platformio"
# Try to locate PlatformIO-managed ESP-IDF virtualenv
ESPIDF_VENV=$(ls -d "$PIO_HOME/penv/.espidf-"* 2>/dev/null | head -n 1 || true)
if [ -z "$ESPIDF_VENV" ]; then
# Trigger framework fetch which usually creates the venv
platformio platform show espressif32 || true
ESPIDF_VENV=$(ls -d "$PIO_HOME/penv/.espidf-"* 2>/dev/null | head -n 1 || true)
fi
if [ -n "$ESPIDF_VENV" ] && [ -x "$ESPIDF_VENV/bin/python" ]; then
"$ESPIDF_VENV/bin/python" -m pip install --upgrade pip setuptools wheel
"$ESPIDF_VENV/bin/python" -m pip install --upgrade idf-component-manager
else
echo "ESP-IDF venv not found yet; proceeding. PlatformIO should install deps during build."
fi
- name: Check pre-commit hooks
uses: pre-commit/action@v3.0.1
- name: Build firmware
run: platformio run
run: platformio run -e release
- name: Build filesystem
run: platformio run --target buildfs
run: platformio run -e release --target buildfs
- name: Create artifacts
run: |
7z a SmartSpin2kFirmware-${{ steps.date.outputs.date }}.bin.zip ./.pio/build/release/*.bin
Expand All @@ -58,12 +88,12 @@ jobs:
name: all-artifacts
path: SmartSpin2kFirmware-${{ steps.date.outputs.date }}.bin.zip
- name: Download Artifacts
uses: actions/download-artifact@v4
uses: actions/download-artifact@v5
with:
name: all-artifacts
- name: Get tag info
id: tag_info
run: echo ::set-output name=SOURCE_TAG::${{ steps.date.outputs.date }}
run: echo "SOURCE_TAG=${{ steps.date.outputs.date }}" >> $GITHUB_OUTPUT
- name: Create release
uses: softprops/action-gh-release@v2
env:
Expand Down
92 changes: 92 additions & 0 deletions .github/workflows/copilot-setup-steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: "Copilot Setup Steps"

on:
workflow_dispatch:
push:
paths:
- .github/workflows/copilot-setup-steps.yml
pull_request:
paths:
- .github/workflows/copilot-setup-steps.yml

jobs:
# IMPORTANT: Job name must be exactly this.
copilot-setup-steps:
# You can upgrade to a larger Ubuntu runner label later if needed (e.g. ubuntu-4-core)
runs-on: ubuntu-latest
timeout-minutes: 40

# Minimize permissions; Copilot will get its own token later.
permissions:
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
# fetch-depth overridden internally for Copilot anyway; keep explicit for normal runs
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.x'

- name: Cache PlatformIO core and packages
uses: actions/cache@v4
with:
path: |
~/.platformio
key: pio-${{ runner.os }}-${{ hashFiles('platformio.ini', 'dependencies.lock') }}
restore-keys: |
pio-${{ runner.os }}-

- name: Install PlatformIO Core
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio

- name: Show PlatformIO info
run: |
platformio --version
platformio system info

- name: Pre-download native test dependencies
run: |
platformio pkg install -e native || echo "Native env install attempted"

- name: Pre-download ESP32 toolchains and libraries (release env)
run: |
# Only install packages (faster + ensures offline availability later)
platformio pkg install -e release

- name: Warm build cache (lightweight compile) for release env
run: |
# A full build ensures toolchains, frameworks, and libs are all present
# If this becomes too slow, you can remove this step and rely on pkg install only.
platformio run -e release || exit 0

- name: Warm build cache for native env (tests)
run: |
platformio run -e native || exit 0

- name: Validate native tests (non-blocking)
run: |
set +e
platformio test -e native
# Do not fail setup if tests fail; Copilot will handle fixes.
exit 0

- name: Summarize cached packages
run: |
du -sh ~/.platformio/packages/* || true
du -sh ~/.platformio/platforms/* || true

- name: Guidance for future adjustments
shell: bash
run: |
echo "Setup steps completed. You can:"
echo " - Upgrade runner: change runs-on to ubuntu-4-core if builds are slow." \
"\n - Enable LFS: add 'with: lfs: true' to checkout step if using Git LFS." \
"\n - Trim steps: remove warm build steps if time exceeds limits." \
"\n - Add more pkg installs for other environments if created later."
4 changes: 2 additions & 2 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: dorny/paths-filter@v3
Expand All @@ -21,6 +21,6 @@ jobs:
- name: Ensure changelog is updated
uses: dangoslen/changelog-enforcer@v3.6.1
- name: Setup python
uses: actions/setup-python@v5
uses: actions/setup-python@v6
- name: Check pre-commit hooks
uses: pre-commit/action@v3.0.1
63 changes: 63 additions & 0 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Update Changelog

on:
pull_request:
branches:
- develop
types: [opened, synchronize, reopened]

jobs:
update-changelog:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}

- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.x'

- name: Update Changelog
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0")
echo "Latest tag: $LATEST_TAG"

if ! grep -q "## \[Unreleased\]" CHANGELOG.md; then
echo "No [Unreleased] section found"
exit 0
fi

FIRST_VERSION=$(grep -oP "## \[\K[0-9]+\.[0-9]+\.[0-9]+" CHANGELOG.md | head -1 || echo "0.0.0")

if [ "$LATEST_TAG" = "$FIRST_VERSION" ]; then
echo "Latest tag matches first version in changelog"
exit 0
fi

# Create temporary files
echo -e "# Changelog\n\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n## [Unreleased]\n\n### Added\n\n### Changed\n\n### Hardware\n" > header.tmp

# Update the old unreleased section
sed "0,/## \[Unreleased\]/s/## \[Unreleased\]/## [$LATEST_TAG]/" CHANGELOG.md | tail -n +7 > content.tmp

# Combine files
cat header.tmp content.tmp > CHANGELOG.md
rm header.tmp content.tmp

if git diff --quiet CHANGELOG.md; then
echo "No changes to commit"
exit 0
fi

git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add CHANGELOG.md
git commit -m "Update changelog for version $LATEST_TAG"
git push
Loading
Loading