Go Down

Topic: ListFiles() shows the list of files in Serial Monitor but not in a browser (Read 3743 times) previous topic - next topic

cschristiana

Good afternoon.

I started working with an Arduino Mega1280 in order to make a datalogger system. I use Arduino IDE 1.0.1 and, thanks to this forum and the open-source examples, I managed to make it work. So, a number of sensors measure some parameters, the information is stored in .csv files and the list of files is presented both in the serial monitor and a browser. :)

After everything worked as I wanted, I constructed my own Arduino, as I needed specific pins and my own reset circuit for remote management. It was based on Atmega1280 schematic, but, instead, I put an Atmega2560 microcontroller for more memory. I also use the Ethernet-to-Serial module WIZ812MJ and the USB-to-Serial UM232R.

When the contruction completed and the bootloader for Atmega2560 was loaded, I managed to upload sketches and everything worked OK. Finally, I tried to load my code that I had alreday written on the Arduino Mega 1280.

The problem is here... On Arduino Mega 1280, the list of files is presented on the Serial monitor and the browser as well (the ListFiles() function worked fine). On my own board, the list of files is presented on the Serial monitor only and not on the browser. :~

Any idea why this is happening?
Thank you in advance.

PaulS

Quote
On my own board, the list of files is presented on the Serial monitor only and not on the browser.

Strange.

Quote
Any idea why this is happening?

I'd venture to guess that there is something wrong with your code.
The art of getting good answers lies in asking good questions.

cschristiana

Thank you PaulS for your quick response.

Quote

I'd venture to guess that there is something wrong with your code.


If there was something wrong with my code, wouldn't I have the same problem when I run the sketch on the Arduino Mega 1280? Is there any possibility that the difference in memory between Atmega1280 and Atmega2560 microcontrollers causes this problem? 

The function I use in order to see the files listed on a browser is the following:
Code: [Select]
void ListFiles(Client client, uint8_t flags) {
  // 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;

  root.rewind();
  while (root.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 file name with possible blank fill
    //root.printDirName(*p, flags & (LS_DATE | LS_SIZE) ? 14 : 0);


    for (uint8_t i = 0; i < 11; i++) {
      if (p.name[i] == ' ') continue;
      if (i == 8) {
        client.print('.');
      }
      client.print(p.name[i]);
    }
    if (DIR_IS_SUBDIR(&p)) {
      client.print('/');
    }

    // print modify date/time if requested
    if (flags & LS_DATE) {
       root.printFatDate(p.lastWriteDate);
       client.print(' ');
       root.printFatTime(p.lastWriteTime);
    }
    // print size if requested
    if (!DIR_IS_SUBDIR(&p) && (flags & LS_SIZE)) {
      client.print(' ');
      client.print(p.fileSize);
    }
    client.println("<br>");
  }
}


I tried to debug entering Serial.print() messages and I realized that in while loop
Code: [Select]
while (root.readDir(p) > 0) { ..... }
the code does nothing. Really strange..  :~

Nishant_Sood

AS you have got your own flavoured Arduino there may have been most probably a problem in circuit , as always double check your connections most probably this is happening due to floating connections or connections gone wrong or perhaps connections not at all done.
"Real Men can Accomplish  Anything"

- skype : nishants5  
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

GoForSmoke

Code: [Select]
void ListFiles(Client client, uint8_t flags) {
  // 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;

  root.rewind();
  while (root.readDir(p) > 0) {
    // done if past last used entry
    if (p.name[0] == DIR_NAME_FREE) break;


What is p.name[0]?

1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

cschristiana


AS you have got your own flavoured Arduino there may have been most probably a problem in circuit , as always double check your connections most probably this is happening due to floating connections or connections gone wrong or perhaps connections not at all done.


I checked the connections and everything looks fine. I am using the WIZ812MJ for ethernet to serial conversion and a microSD. I made the same connections as the connections on Arduino Ethernet Shield.


Code: [Select]
void ListFiles(Client client, uint8_t flags) {
  // 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;

  root.rewind();
  while (root.readDir(p) > 0) {
    // done if past last used entry
    if (p.name[0] == DIR_NAME_FREE) break;


What is p.name[0]?



p.name[0] indicates the first character of the file name

cschristiana

On the part of function ListFiles()
Code: [Select]
....
  root.rewind();
  while (root.readDir(&p) > 0) {
    .....

I put a message Serial.println() to see the returning value of root.readDir. It returns negative. After searching, I found that possible errors include readDir() called before a directory has been opened, this is not a directory file or an I/O error occured.

Could the SPI cause this problem? (both Ethernet module WIZ812MJ and microSD use SPI)
Any help would be appreciated.  :)

Go Up