Enable Time stamp on FatFs SD card

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Enable Time stamp on FatFs SD card

Postby snahmad75 » Tue Sep 11, 2018 6:32 pm

Hi,

Does any one knows how can enable current time stamp for files which gets created and update on SD card File system.

I can pass current time stamp from windows to Esp32 via http post.
Thanks,
Naeem

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: Enable Time stamp on FatFs SD card

Postby snahmad75 » Wed Sep 12, 2018 3:45 pm

Can any one reply to this thread please. waiting.

At the end my Http Web server mongoose need to return time stamp for each file. I guess using file stats function to return file time stamp in order to tell web browser to cache file and do to get reloaded/read again from SD card file system.

I know current time stamp. I set file stamp during file creation or updating file.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: Enable Time stamp on FatFs SD card

Postby loboris » Wed Sep 12, 2018 7:47 pm

Why do you think files on SD Card do not have timestamp?

Here is simple example, the result printed from this simple loop:

Code: Select all

    vTaskDelay(5000 / portTICK_RATE_MS);
    for (int n=1; n<5; n++) {
        ESP_LOGI(TAG, "Opening file");
        f = fopen("/sdcard/hello.txt", "w");
        if (f == NULL) {
            ESP_LOGE(TAG, "Failed to open file for writing");
            return;
        }
        fprintf(f, "Hello %s!\n", card->cid.name);
        fclose(f);
        ESP_LOGI(TAG, "File written");
        if (stat("/sdcard/hello.txt", &st) == 0) {
            strftime(date, 20, "%d-%m-%y %H:%M:%S", gmtime(&(st.st_mtime)));
            ESP_LOGI(TAG, "=== hello.txt created ===");
            ESP_LOGI(TAG, "File Size: %d bytes",(int)st.st_size);
            ESP_LOGI(TAG, "File Time: %d [%s]",(int)st.st_mtime, date);
        }
        ESP_LOGI(TAG, "Waiting 5 seconds");
        vTaskDelay(5000 / portTICK_RATE_MS);
    }
Log:

Code: Select all

I (396) example: Initializing SD card
I (400) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
Name: SL08G
Type: SDHC/SDXC
Speed: 20 MHz
Size: 7580MB
I (10476) example: Opening file
I (10486) example: File written
I (10487) example: === hello.txt created ===
I (10487) example: File Size: 13 bytes
I (10488) example: File Time: 315532810 [01-01-80 00:00:10]
I (10494) example: Waiting 5 seconds
I (15499) example: Opening file
I (15510) example: File written
I (15511) example: === hello.txt created ===
I (15511) example: File Size: 13 bytes
I (15512) example: File Time: 315532814 [01-01-80 00:00:14]
I (15518) example: Waiting 5 seconds
I (20522) example: Opening file
I (20533) example: File written
I (20533) example: === hello.txt created ===
I (20534) example: File Size: 13 bytes
I (20535) example: File Time: 315532820 [01-01-80 00:00:20]
I (20541) example: Waiting 5 seconds
I (25545) example: Opening file
I (25556) example: File written
I (25557) example: === hello.txt created ===
I (25557) example: File Size: 13 bytes
I (25558) example: File Time: 315532824 [01-01-80 00:00:24]
I (25564) example: Waiting 5 seconds

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: Enable Time stamp on FatFs SD card

Postby snahmad75 » Wed Sep 12, 2018 8:26 pm

ok, this is reading time stamp of file. If I put my SD card to read in my Windows machine. Time stamp columns was blank in windows explorer.

I will try your code. How can I set/update time stamp of file. current time it is showing 1980.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: Enable Time stamp on FatFs SD card

Postby loboris » Wed Sep 12, 2018 10:08 pm

Just set the right system time using SNTP or otherwise. The file timestamp is set when file is created or modified.
The code was executed after boot with no time set.

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: Enable Time stamp on FatFs SD card

Postby snahmad75 » Sun Sep 16, 2018 11:57 am

I want to provide my own time stamp.

How can I override fatfs get_fattime to return my own file time stamp.

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: Enable Time stamp on FatFs SD card

Postby snahmad75 » Sun Sep 16, 2018 12:23 pm

I am trying f_utime to st time stamp for file.

http://www.elm-chan.org/fsw/ff/doc/utime.html


not working for me.

I am getting FR_NO_PATH error.


Any idea?

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: Enable Time stamp on FatFs SD card

Postby ESP_igrr » Sun Sep 16, 2018 1:42 pm

What path are you passing to this function, can you give an example? And what is the actual path of the same file on SD card?

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: Enable Time stamp on FatFs SD card

Postby snahmad75 » Sun Sep 16, 2018 6:47 pm

I am sure my file path is correct.

Can you try yourself.

Also I used this fatfs library. I manged to override get_fattime function and return my own date and time. but i cannot do on esp32. esp32 fatfs does not allow. compilers says it is already define.

http://elm-chan.org/fsw/ff/doc/fattime.html

kindly do try this two options as your end. let me know results.

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: Enable Time stamp on FatFs SD card

Postby ESP_igrr » Mon Sep 17, 2018 3:07 pm

Well, you say above that you are getting FR_NO_PATH error, and then you say that the path is certainly correct... but if it was correct, FATFS would not be returning this error, right?

get_fattime function is implemented in fatfs component of ESP-IDF, if you implement another copy in your application you will get a duplicate definition error. To override a function implemented in IDF you may copy the whole fatfs component to your project components directory, and do modifications there.

Who is online

Users browsing this forum: Baidu [Spider], HighVoltage and 103 guests