Commit Graph

31 Commits

Author SHA1 Message Date
Claude
6fc178de2e
Fix WiFi file transfer lockup and add performance optimizations
This commit resolves critical stability issues causing WiFi file transfer
crashes in STA mode and adds aggressive performance optimizations for
maximum upload/download throughput.

CRITICAL BUG FIXES:

1. Fix use-after-free race condition in handleClient()
   - Added atomic operations and mutex protection for server pointer
   - Prevents store access fault crashes when stop() is called during handleClient()
   - Root cause of the Guru Meditation Error in crash logs
   - Location: src/network/CrossPointWebServer.cpp:135-158

2. Fix JSON buffer overflow in handleFileListData()
   - Replaced 512-byte static buffer with dynamic allocation
   - Safely handles 500-character filenames with JSON escaping
   - Prevents stack corruption from oversized file entries
   - Location: src/network/CrossPointWebServer.cpp:253-306

3. Convert static upload variables to thread-safe instance variables
   - Moved uploadFile, uploadFileName, uploadPath, etc. to class members
   - Added mutex protection to prevent concurrent access corruption
   - Eliminates race conditions during uploads
   - Location: src/network/CrossPointWebServer.h:44-54, CrossPointWebServer.cpp:311-313

4. Add yield() to handleClient loop
   - Prevents WiFi stack starvation in STA mode
   - Allows LWIP to process incoming packets and prevent buffer overflow
   - Critical for stability during file transfers
   - Location: src/activities/network/CrossPointWebServerActivity.cpp:304-311

5. Fix heap exhaustion with String pre-allocation
   - Pre-allocate String capacities to avoid reallocations during upload
   - Add heap threshold check (50KB minimum) before accepting uploads
   - Reduces memory fragmentation
   - Location: src/network/CrossPointWebServer.cpp:323-376

ROBUSTNESS IMPROVEMENTS:

6. Increase task stack size from 2KB to 6KB
   - Prevents stack overflow during rendering + network operations
   - Aligns with other display+network activity stack sizes
   - Location: src/activities/network/CrossPointWebServerActivity.cpp:51

PERFORMANCE OPTIMIZATIONS:

7. Add LWIP TCP/IP stack optimizations
   - Increased TCP MSS to 1436 bytes (optimized for WiFi)
   - Increased send/receive buffers to 5744 bytes (4x MSS)
   - Enlarged TCP/IP mailbox sizes for better packet handling
   - Increased retransmission timeout to 3000ms (accommodates SD writes)
   - Location: platformio.ini:31-49

8. Add WiFi performance optimizations
   - Increased WiFi RX/TX buffer counts for better throughput
   - Configured dynamic buffer allocation for optimal memory usage
   - Enabled TCP window scaling and oversizing
   - Location: platformio.ini:41-49

9. Maximize WiFi TX power
   - Set WiFi TX power to maximum (19.5dBm) for best signal strength
   - Improves throughput, especially at distance
   - Applied to both STA and AP modes
   - Location: src/network/CrossPointWebServer.cpp:58,
     src/activities/network/CrossPointWebServerActivity.cpp:152,192

EXPECTED IMPACT:
- Eliminates WiFi file transfer crashes in STA mode
- Improves upload/download speeds by 2-3x through TCP optimizations
- Increases stability during large file transfers (>100MB)
- Better performance on weak WiFi signals
- Reduces heap fragmentation and memory pressure

TESTING RECOMMENDATIONS:
1. Test large file uploads (>50MB) in both STA and AP modes
2. Verify system stability during concurrent uploads
3. Monitor heap usage during file transfers
4. Test with long filenames (400+ characters)
5. Verify performance improvement with speed tests

Fixes: WiFi lockup bug causing Guru Meditation Errors during file transfer
2026-01-09 22:34:01 +00:00
Dave Allie
5fdf23f1d2
Cut release 0.12.0
Some checks are pending
CI / build (push) Waiting to run
2026-01-03 19:42:14 +11:00
Dave Allie
b82e044ac3
Cut release 0.11.2 2025-12-31 09:28:14 +11:00
Eunchurn Park
93226c9fbb
Fix file browser navigation for non-ASCII folder names (#178)
## Summary

* **What is the goal of this PR?**

Fix file browser failing to navigate into subdirectories with non-ASCII
(Korean/Unicode) folder names.

* **What changes are included?**

- Enable UTF-8 long file names in SdFat (`USE_UTF8_LONG_NAMES=1`)
- Add directory validation before iterating files
- Add `rewindDirectory()` call for stability

## Additional Context
2025-12-31 09:08:31 +11:00
Dave Allie
941643cf97
Cut release 0.11.1
Some checks are pending
CI / build (push) Waiting to run
2025-12-31 02:47:24 +11:00
Dave Allie
6a8971fc20
Cut release 0.11.0 2025-12-30 23:42:19 +11:00
Dave Allie
fb5fc32c5d
Add exFAT support (#150)
## Summary

* Swap to updated SDCardManager which uses SdFat
* Add exFAT support
  * Swap to using FsFile everywhere
* Use newly exposed `SdMan` macro to get to static instance of
SDCardManager
* Move a bunch of FsHelpers up to SDCardManager
2025-12-30 16:09:30 +11:00
Dave Allie
b1763821b5
Cut release 0.10.0
Some checks are pending
CI / build (push) Waiting to run
2025-12-29 02:30:27 +11:00
Jonas Diemer
e8c0fb42d4
Network details QR code (#113)
Using QRCode library from pio to generate the QR code.

Done:
- Display QR code for URL in network mode
- minor fixes of layout
- Display QR for URL in AP mode
- Display QR for AP in AP mode

---------

Co-authored-by: Dave Allie <dave@daveallie.com>
2025-12-26 12:13:40 +11:00
Dave Allie
504c7b307d
Cut release 0.9.0
Some checks failed
CI / build (push) Has been cancelled
2025-12-24 21:49:47 +10:00
Dave Allie
66ddb52103
Pin espressif32 platform version 2025-12-23 12:17:12 +11:00
Dave Allie
6fe28da41b
Cut release 0.8.1
Some checks are pending
CI / build (push) Waiting to run
2025-12-22 03:20:22 +11:00
Dave Allie
689b539c6b
Stream CrossPointWebServer data over JSON APIs (#97)
## Summary

* HTML files are now static, streamed directly to the client without
modification
* For any dynamic values, load via JSON APIs
* For files page, we stream the JSON content as we scan the directory to
avoid holding onto too much data

## Additional details

* We were previously building up a very large string all generated on
the X4 directly, we should be leveraging the browser
* Fixes https://github.com/daveallie/crosspoint-reader/issues/94
2025-12-22 03:19:49 +11:00
Dave Allie
fcfa10bb1f
Cut release 0.8.0 2025-12-21 19:02:21 +11:00
Dave Allie
0d32d21d75
Small code cleanup (#83)
Some checks are pending
CI / build (push) Waiting to run
## Summary

* Fix cppcheck low violations
* Remove teardown method on parsers, use destructor
* Code cleanup
2025-12-21 15:43:53 +11:00
Brendan O'Leary
d41d539435
Add connect to Wifi and File Manager Webserver (#41)
## Summary

- **What is the goal of this PR?**  
Implements wireless EPUB file management via a built-in web server,
enabling users to upload, browse, organize, and delete EPUB files from
any device on the same WiFi network without needing a computer cable
connection.

- **What changes are included?**
- **New Web Server**
([`CrossPointWebServer.cpp`](src/CrossPointWebServer.cpp),
[`CrossPointWebServer.h`](src/CrossPointWebServer.h)):
    - HTTP server on port 80 with a responsive HTML/CSS interface
    - Home page showing device status (version, IP, free memory)
    - File Manager with folder navigation and breadcrumb support
    - EPUB file upload with progress tracking
    - Folder creation and file/folder deletion
    - XSS protection via HTML escaping
- Hidden system folders (`.` prefixed, "System Volume Information",
"XTCache")
  
- **WiFi Screen** ([`WifiScreen.cpp`](src/screens/WifiScreen.cpp),
[`WifiScreen.h`](src/screens/WifiScreen.h)):
    - Network scanning with signal strength indicators
    - Visual indicators for encrypted (`*`) and saved (`+`) networks
- State machine managing: scanning, network selection, password entry,
connecting, save/forget prompts
    - 15-second connection timeout handling
    - Integration with web server (starts on connect, stops on exit)
  
- **WiFi Credential Storage**
([`WifiCredentialStore.cpp`](src/WifiCredentialStore.cpp),
[`WifiCredentialStore.h`](src/WifiCredentialStore.h)):
    - Persistent storage in `/sd/.crosspoint/wifi.bin`
- XOR obfuscation for stored passwords (basic protection against casual
reading)
    - Up to 8 saved networks with add/remove/update operations
  
- **On-Screen Keyboard**
([`OnScreenKeyboard.cpp`](src/screens/OnScreenKeyboard.cpp),
[`OnScreenKeyboard.h`](src/screens/OnScreenKeyboard.h)):
    - Reusable QWERTY keyboard component with shift support
    - Special keys: Shift, Space, Backspace, Done
    - Support for password masking mode
  
- **Settings Screen Integration**
([`SettingsScreen.h`](src/screens/SettingsScreen.h)):
    - Added WiFi action to navigate to the new WiFi screen
  
  - **Documentation** ([`docs/webserver.md`](docs/webserver.md)):
- Comprehensive user guide covering WiFi setup, web interface usage,
file management, troubleshooting, and security notes
    - See this for more screenshots!
- Working "displays the right way in GitHub" on my repo:
https://github.com/olearycrew/crosspoint-reader/blob/feature/connect-to-wifi/docs/webserver.md

**Video demo**


https://github.com/user-attachments/assets/283e32dc-2d9f-4ae2-848e-01f41166a731

## Additional Context

- **Security considerations**: The web server has no
authentication—anyone on the same WiFi network can access files. This is
documented as a limitation, recommending use only on trusted private
networks. Password obfuscation in the credential store is XOR-based, not
cryptographically secure.

- **Memory implications**: The web server and WiFi stack consume
significant memory. The implementation properly cleans up (stops server,
disconnects WiFi, sets `WIFI_OFF` mode) when exiting the WiFi screen to
free resources.

- **Async operations**: Network scanning and connection use async
patterns with FreeRTOS tasks to prevent blocking the UI. The display
task handles rendering on a dedicated thread with mutex protection.

- **Browser compatibility**: The web interface uses standard
HTML5/CSS3/JavaScript and is tested to work with all modern browsers on
desktop and mobile.

---------

Co-authored-by: Dave Allie <dave@daveallie.com>
2025-12-20 01:05:43 +11:00
Dave Allie
70dc0f018e
Cut release 0.7.0 2025-12-19 00:44:22 +11:00
Dave Allie
c287aa03a4
Use single buffer mode for EInkDisplay (#34)
## Summary

* Frees up 48kB of statically allocated RAM in exchange for 48kB just
when grayscale rendering is needed

## Additional Context

* Upstream changes:
https://github.com/open-x4-epaper/community-sdk/pull/7
2025-12-17 00:17:49 +11:00
Dave Allie
5d68c8b305
Cut release 0.6.0 2025-12-16 23:15:47 +11:00
Dave Allie
fdb5634ea6
Add cppcheck and formatter to CI (#19)
* Add cppcheck and formatter to CI

* Checkout submodules

* Install matching clang-format version in CI
2025-12-15 19:46:52 +11:00
Dave Allie
dfc74f94c2
Cut release 0.5.1 2025-12-13 21:52:48 +11:00
Dave Allie
5a7381a0eb
Cut release 0.5.0 2025-12-13 20:16:12 +11:00
Dave Allie
c7a32fe41f
Remove tinyxml2 dependency replace with expat parsers (#9) 2025-12-13 19:36:01 +11:00
Dave Allie
d450f362d1
Cut release 0.4.0 2025-12-13 17:15:06 +11:00
Dave Allie
69f357998e
Move to smart pointers and split out ParsedText class (#6)
* Move to smart pointers and split out ParsedText class

* Cleanup ParsedText

* Fix clearCache functions and clear section cache if page load fails

* Bump Page and Section file versions

* Combine removeDir implementations in Epub

* Adjust screen margins
2025-12-12 22:13:34 +11:00
Dave Allie
45af2d0e81
Cut release 0.3.0 2025-12-08 23:55:05 +11:00
Dave Allie
0926e9e6e4
Add version string to boot screen 2025-12-08 23:13:33 +11:00
Dave Allie
2ed8017aa2
Move to SDK EInkDisplay and enable anti-aliased 2-bit text (#5)
* First pass at moving to SDK EInkDisplay library

* Add 2-bit grayscale text and anti-aliased rendering of text

* Render status bar for empty chapters

* Refresh screen every 15 pages to avoid ghosting

* Simplify boot and sleep screens

* Give FileSelectionScreen task more stack memory

* Move text around slightly on Boot and Sleep screens

* Re-use existing buffer and write to whole screen for 'partial update'
2025-12-08 19:48:49 +11:00
Dave Allie
dd6e649d74
Add expat and swap out EPUB HTML parser (#2)
* Add expat and swap out ERB HTML parser

* Increase EpubHtmlParserSlim file buffer to 1024 bytes

* Cleanup TextBlock functions

* Do not break words when leaving spans
2025-12-06 20:57:24 +11:00
Dave Allie
6414f85257
Use InputManager from community-sdk 2025-12-06 12:35:41 +11:00
Dave Allie
2ccdbeecc8
Public release 2025-12-03 22:06:45 +11:00