nailbuster / esp8266FTPServer

Simple FTP Server for using esp8266/esp32 SPIFFs
GNU Lesser General Public License v2.1
208 stars 126 forks source link

USING FTPSERVER with SDFat.h lib causes: error:'File' is already declared in this scope using fs::File #18

Open axfatec opened 6 years ago

axfatec commented 6 years ago

Hello. I'm a new user of esp8266, and sice few months ago I started to develop a data logger with ESP-12E module. All worked since I decided to add the FTP feature to my project (where I use library #include "SdFat.h") Now I added your library and when I compile the scketch I obtain this error:

sp8266/FS.h:136:11: error: 'File' is already declared in this scope

using fs::File; ^ I found here me-no-dev/ESPAsyncWebServer#112 , an old discussion on similar issue, but I was now able to implement to your libary and to solve the issue. Could you help me ? thanks Alessandro

tobozo commented 6 years ago

There was a breaking change on the SD library due to keywords collisions with SPIFFS. Both were using the File keyword differently.

Now old SD keywords need to be prefixed i.e. fs:: orsd::

Depending on the complexity of your other project you have two choices:

1) update your SD library to the oldest version using the Arduino library manager, you can still rollback to the newer SD library version later.

2) update your other sketch so it uses the new namespaced keywords, it's just a matter of adding sd::, fs:: or dir:: to the existing keywords, compilation errors will help you to find where it needs to be done.

axfatec commented 6 years ago

I found a working solution of SD.h lib reworked by : http://mcutry.tistory.com/47 that seems to re-addresses to SD the calls to SPIFFS. Unfortunately this lib has not been merged to ufficial one. it's a pitty. Could anyone with right experience to do this improvment? .. and furthermore, it should be better in this case to update the SDFat library.

tobozo commented 6 years ago

Well it's using the namespaced version too, and the problem has already been partially adressed (you still need to edit your sketch though) by using a define just before including SD.h: #define FS_NO_GLOBALS

axfatec commented 6 years ago

Better ! thanks. so in my case (I'm not so expert) should have I to change my calls if(!SD.begin(chipSelect)) to like this? if(!SD::SD.begin(chipSelect))

and similarly to: myFile=SD.open("DATA.txt", FILE_WRITE); in myFile=SD::SD.open("DATA.txt", FILE_WRITE); ??

tobozo commented 6 years ago

not exactly, SD syntax is unchanged so you can keep this:

myFile = SD.open( .... );

however when using SPIFFS, you'll have to use this:

fs::myFile = SPIFFS.open( ..... );

axfatec commented 6 years ago

Thank you a lot..! I will check this new lib with "ESP8266FtpServer.h", then I will report any news.

axfatec commented 6 years ago

Do you know if there is a porting to SDFat.h library in order to use it together with ESP8266FtpServer.h solving the SD card access instead of SPIFFS access ? This should be a better solution because SDFat can mange long file name (other than improved functions respect to SD.h) Thanks

tobozo commented 6 years ago

I only use SDFat.h with Atmega chips, essentially because it has a small memory footprint and can fit in a bootloader. And I always remove the library after use as it often conflicts with other non-atmega libraries (and this is probably what's happening to you).

Now you don't have to modify SD.h; this tutorial does not use a specific SD.h library other than the one you can get from your library manager: http://mcutry.tistory.com/47

The article hint you at modifying the actual esp8266FTPServer library so it calls SD methods instead of SPIFFS methods, and this implies some small changes.

If you comment out every #include "FS.h" and implement the changes from the article (marked in yellow), it should work as described, provided you selected the correct version of the library in the Arduino library manager.

axfatec commented 6 years ago

Actually, the SD.h modified by the article, with ESP8266FTPServer , works correctly. What I would do, (but I found hard) is to modify in the same way the SDFat.h library, but due to different metods adopted in this one comprare to Sd.h , it doesn't work. Most probably I did some mistakes. Could you share your SDFat.h library so I can test it with ESP8266FTPserver ? If it could works, it should be a very good achievement. Thanks Alex

tobozo commented 6 years ago

Could you share your SDFat.h library so I can test it with ESP8266FTPserver ?

It's the official SDFat.h, I haven't tried it with ESP8266

The official updated SD.h from the Arduino Library manager is better for your needs, and it does not default to 8.3 filenames, why wouldn't you use it? It does implement the changes you're talking about after all.

I just diffed the modified library from the article, and there's only one change in one file: File.cpp

#> diff File.cpp File.cpp.bak
17,19d16
< using namespace sd;
< using sd::File;
< 

If you look at ~/Arduino/libraries/SD/File.cpp from the Arduino library folder (SD Built-in by Arduino SparkFun) you'll see those changes are there too, only they're at the end of the file.

So basically you can delete the custom SD directory from your ~/Arduino/libraries folder, go to your Arduino Library manager, search "SD", select the version 1.1.1 of "SD Built-in by Arduino SparkFun", update the library, and still get the same results as in the article.

tobozo commented 6 years ago

btw from the network page it seems like somebody already did this a year ago

axfatec commented 6 years ago

But I tried and it did't work. So, something is still missing with joined use of SDFAt and ESP8266FTPServer.

Anyway, I will try your previuous suggestion. Did you furthermore told that new SD lib support long file name?? It should be great.