LittleFS not showing uploaded files

I am trying to plaback mp3 files from flash LittleFS file system..

I can upload all the files no problem--looks like that works--

[LittleFS] data : /home/jack/Documents/sketchbook/PlayMP3FromLittleFS/data
[LittleFS] size : 2024
[LittleFS] page : 256
[LittleFS] block : 8192
/pno-cs.mp3
/chimes.mp3
/chimes/pno-cs.mp3
/chimes/chimes.mp3
/sounds/pno-cs.mp3
/sounds/chimes.mp3
[LittleFS] upload : /tmp/arduino_build_525998/PlayMP3FromLittleFS.mklittlefs.bin
[LittleFS] address : 0x200000
[LittleFS] reset : --before default_reset --after hard_reset
[LittleFS] port : /dev/ttyUSB1
[LittleFS] speed : 115200
[LittleFS] python : /home/jack/snap/arduino/50/.arduino15/packages/esp8266/tools/python3/3.7.2-post1/python3
[LittleFS] uploader : /home/jack/snap/arduino/50/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/tools/upload.py

esptool.py v2.8
Serial port /dev/ttyUSB1
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 8c:aa:b5:7b:09:1f
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 2072576 bytes to 1002033...
Wrote 2072576 bytes (1002033 compressed) at 0x00200000 in 92.2 seconds (effective 179.8 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

then I try to verify the files are there-- and I get:

File sistem info.
Total space: 2072576 bytes
Total space used: 16384 bytes
Block size: 8192 bytes
Page size: 2072576 bytes
Max open files: 5
Max path lenght: 32

Sample MP3 playback begins...
MP3 source file not open
MP3 done

I doubled up on the files uploaded to make them combined to be pretty large, but it only shows a couple blocks and doesnt list any of the .mp3 files..

here is the code:

#include <Arduino.h>
#include <LittleFS.h>
//#include <FS.h>
 
#include <ESP8266WiFi.h>
#include "AudioFileSourceSPIFFS.h"
#include "AudioFileSourceID3.h"
#include "AudioGeneratorMP3.h"
#include "AudioOutputI2S.h"

// To run, set your ESP8266 build to 160MHz, and include a SPIFFS of 512KB or greater.
// Use the "Tools->ESP8266/ESP32 Sketch Data Upload" menu to write the MP3 to SPIFFS
// Then upload the sketch normally.  

// pno_cs from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html

AudioGeneratorMP3 *mp3;
AudioFileSourceSPIFFS *file;
AudioOutputI2S *out;
AudioFileSourceID3 *id3;


// Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc.
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string)
{
  (void)cbData;
  Serial.printf("ID3 callback for: %s = '", type);

  if (isUnicode) {
    string += 2;
  }
  
  while (*string) {
    char a = *(string++);
    if (isUnicode) {
      string++;
    }
    Serial.printf("%c", a);
  }
  Serial.printf("'\n");
  Serial.flush();
}


 




void setup()
{
  WiFi.mode(WIFI_OFF); 
  Serial.begin(115200);
  delay(1000);
  //SPIFFS.begin();
   if (LittleFS.begin()) Serial.println("LittleFS mounted");

 //  if(LittleFS.format())Serial.println("formatted");


 // Get all information of your LittleFS
    FSInfo fs_info;
    LittleFS.info(fs_info);
 
    Serial.println("File sistem info.");
 
    Serial.print("Total space:      ");
    Serial.print(fs_info.totalBytes);
    Serial.println(" bytes");
 
    Serial.print("Total space used: ");
    Serial.print(fs_info.usedBytes);
    Serial.println(" bytes");
 
    Serial.print("Block size:       ");
    Serial.print(fs_info.blockSize);
    Serial.println(" bytes");
 
    Serial.print("Page size:        ");
    Serial.print(fs_info.totalBytes);
    Serial.println(" bytes");
 
    Serial.print("Max open files:   ");
    Serial.println(fs_info.maxOpenFiles);
 
    Serial.print("Max path lenght:  ");
    Serial.println(fs_info.maxPathLength);
 
    Serial.println();
 
    // Open dir folder
    Dir dir = LittleFS.openDir("/");
   // Serial.print("dir=");Serial.println(dir.name());
    // Cycle all the content
    while (dir.next()) {
        // get filename
        Serial.print(dir.fileName());
        Serial.print(" - ");
        // If element have a size display It else write 0
        if(dir.fileSize()) {
            File f = dir.openFile("r");
            Serial.println(f.size());
            f.close();
        }else{
            Serial.println("0");
        }
    }





   
  Serial.printf("Sample MP3 playback begins...\n");
  if(LittleFS.exists("/pno-cs.mp3"))Serial.println("file exists");

  audioLogger = &Serial;
  file = new AudioFileSourceSPIFFS("/pno-cs.mp3");
  id3 = new AudioFileSourceID3(file);
  id3->RegisterMetadataCB(MDCallback, (void*)"ID3TAG");
  out = new AudioOutputI2S();
  mp3 = new AudioGeneratorMP3();
  mp3->begin(id3, out);
}

void loop()
{
  if (mp3->isRunning()) {
    if (!mp3->loop()) mp3->stop();
  } else {
    Serial.printf("MP3 done\n");
    
   
  }

 
while(1){wdt_reset();}
  
}

everything compiles and uploads, got me beat.. geeez
this is my first time trying to use LittleFS..
maybe someone has been here dun that.. hope

PlayMP3FromLittleFS.zip (986 KB)

SOLVED!!!!

I had to open the directory first.. apparently SPIFFS doesnt require that..
here is a nice function that opens a directory and lists files --works with LittleFS.h!!!

void littleFsListDir(const char * dirname)
{
Serial.printf("Listing directory: %s\n", dirname);

Dir root = LittleFS.openDir(dirname);

while (root.next())
{
File file = root.openFile("r");
Serial.print(" FILE: ");
Serial.print(root.fileName());
Serial.print(" SIZE: ");
Serial.println(file.size());
time_t cr = file.getCreationTime();
time_t lw = file.getLastWrite();
file.close();
struct tm * tmstruct = localtime(&cr);
//Serial.printf(" CREATION: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
tmstruct = localtime(&lw);
//Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
}
Serial.println("");}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.