First, why this combination?
- The web server is fast and easy to use, and doesn't slow down other processes noticeably. I have already written a lot of code using it.
- SD.h is buggy. It randomly decides that I have no SD card, any time from just after boot to after a few hundred thousand reads and writes. Repeating SD.begin doesn't help, and often a reboot doesn't help either.
- SdFat is working first time, every time on the Nano ESP32.
When I was happy with microSD tests using SdFat I converted my main project which includes the web server. Everything went sideways. ESP32AsyncWebSrv includes FS.h and uses File objects. These conflict with similar definitions in SdFat.h. There are also conflicting #defines for things like FILE_WRITE, though I'm happy to use the primitives and skip the shorthand names.
Just one example of the problem is
server.serveStatic("/", SD, "/htdocs").setCacheControl("max-age=3600");
where I have SD defined based on SdFat.h but the server code expects the FS from FS.h.
The compiler output for this (amid many other warnings and errors) is
D:\GitHub\CBASS-ESP32-Sketch\CBASS_WiFi_Async\Server.ino: In function 'void defineWebCallbacks()':
D:\GitHub\CBASS-ESP32-Sketch\CBASS_WiFi_Async\Server.ino:64:40: error: no matching function for call to 'AsyncWebServer::serveStatic(const char [2], SdFat32&, const char [8])'
server.serveStatic("/", SD, "/htdocs").setCacheControl("max-age=3600"); // for a full day: 86400");
^
In file included from D:\GitHub\CBASS-ESP32-Sketch\CBASS_WiFi_Async\CBASS_WiFi_Async.ino:61:
C:\Users\list\Documents\Arduino\libraries\ESPAsyncWebSrv\src/ESPAsyncWebSrv.h:428:28: note: candidate: 'AsyncStaticWebHandler& AsyncWebServer::serveStatic(const char*, fs::FS&, const char*, const char*)'
AsyncStaticWebHandler& serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_control = NULL);
^~~~~~~~~~~
C:\Users\list\Documents\Arduino\libraries\ESPAsyncWebSrv\src/ESPAsyncWebSrv.h:428:28: note: no known conversion for argument 2 from 'SdFat32' to 'fs::FS&'
Obviously this can't work, but I'm at a loss for how to proceed from here. I could try to edit the web server to use SdFat. I'm okay with modifying hundreds of lines of code, but it feels like asking for trouble as new versions come along.
Some people seem to have had success with explicit namespaces (SD.h uses fs, but I haven't spotted such a name in SdFat). One thing I do NOT want to do is use both SdFat.h and SD.h. Given recent experiences, the built-in SD.h is simply dangerous.
There are other forum posts with similar issues, but they seem to be 2 to 12 years old. I'm hoping that there is some new knowledge out there that I can build on.
What do you suggest I do next?
Some details:
- Arduino IDE 2.3.2
- Board definition 2.0.13
- SdFat by Bill Greiman, 2.2.2
- ESPAsyncWebSrv by dvarrle, 1.2.7
- There are two SPI devices. The other is a TFT display. The display was included in my successful SdFat tests.
- Running on Arduino Nano ESP32
- Compiling on Windows 11 Pro
- The problem SD.h I'm trying to avoid is this one: C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\hardware\esp32\2.0.13\libraries\SD\src\SD.h
- microSD read/write speed is not important. I'm only logging a hundred bytes or so once per second, and reading only a few small files per run. Web use will be light.
- I can post all 4,000 lines of code or put it on GitHub, but I'm hoping that an general response will get me going. I'll post my results.
Things I tried with SD.h before going to SdFat:
- More than one copy of my custom PCB where the sdCard slot lives.
- Different brands and sizes of microSD card.
- Rebooting with the reset button or by physically removing power. Times of at least 20 seconds seemed better, but not consistently.
- Voltage on the Nano consistently tests at 3.24 or 3.25 with or without a card installed. This is with a basic hobbyist-level digital meter, and could be off a bit.
- Adding extra pullup resistors.
- Catching and retrying failed SD operations.
- Changing the SPI clock divider.
Those last few items had no effect or made things worse, so they are all back at defaults.
Thanks for anything!