I have a function that lists files on an Arduino, SD card as url links the client can select and then download. I am new to the ESP8266 SPIFFS file system; this is the existing function:
///////////////////////////////////////////////////////////////////////////
char ListFiles(Adafruit_CC3000_ClientRef client, uint8_t flags, SdFile dir)
{
// This code is just copied from SdFile.cpp in the SDFat library
// and tweaked to print to the client output in html!
dir_t p;
dir.rewind();
client.println("<ul>");
while (dir.readDir(&p) > 0)
{
// done if past last used entry
if (p.name[0] == DIR_NAME_FREE) break;
// skip deleted entry and entries for . and ..
if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.') continue;
// only list subdirectories and files
if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
// print any indent spaces
client.print("<li><a href=\"");
for (uint8_t i = 0; i < 11; i++)
{
if (p.name[i] == ' ') continue;
if (i == 8)
{
client.print('.');
}
client.print((char)p.name[i]);
}
if (DIR_IS_SUBDIR(&p))
{
client.print('/');
}
client.print("\">");
// print file name with possible blank fill
for (uint8_t i = 0; i < 11; i++)
{
if (p.name[i] == ' ') continue;
if (i == 8)
{
client.print('.');
}
client.print((char)p.name[i]);
}
if (DIR_IS_SUBDIR(&p))
{
client.print('/');
}
client.print("</a>");
// print modify date/time if requested
if (flags & LS_DATE)
{
dir.printFatDate(p.lastWriteDate);
client.print(' ');
dir.printFatTime(p.lastWriteTime);
}
// print size if requested
if (!DIR_IS_SUBDIR(&p) && (flags & LS_SIZE))
{
client.print(' ');
client.print(p.fileSize);
}
client.println("</li>");
}
client.println("</ul>");
}
How would "char ListFiles(Adafruit_CC3000_ClientRef client, uint8_t flags, SdFile dir)" convert to the ESP8266 Wifi client environment? I have only found little documentation Googling "SPIFFS," just covering basic usage of the SPIFFS system.
I am aware there are limited writes cycles to flash. Development board I am using is the low cost, WeMOS D1, Release 2.1 which is claimed to be Arduino compatible. I have already moved most of my project to this Dev. Board. The above function is the last part of the SdBrowse_CC3000_Webserver.ino; project to move to the new WeMOS D1 board.
Project Webpage Based on the TI CC3000.
CC3000_SDWebBrowser.zip (3.97 KB)