LittleFS and setting timestamp with new files & directories

arjen1
Posts: 10
Joined: Sun Aug 06, 2023 4:48 pm

LittleFS and setting timestamp with new files & directories

Postby arjen1 » Wed Mar 27, 2024 5:53 pm

Dear forum

Got a really hard time figuring this out.

Setup is an ESP8266 with NO internet connection.
It serves a webserver with a lot of javascript.

At start I 'get' the date/time from the client and store it in the ESP. It will show the right date.
At some point I do a httprequest to make a new directory. This will all work but the timestamp is always 1-1-1970.

I tried several things, but I am at a loss now. It appears the timestamp from now() in the esp is in seconds while the timestamp from JavaScript is in milliseconds. Pretty confusing.

Can someone direct me to an example? I could go from there.

some snippets:

Code: Select all

    Serial.printf("getall paramsnr %i\n", paramsNr);
    for(i=0;i<paramsNr;i++){
      AsyncWebParameter* p = request->getParam(i);
      today_esp[i] = p->value().toInt();
      Serial.printf("%u ", today_esp[i]);
    }
    Serial.println();
    Serial.print(now());
    Serial.print("\n");

    setTime(12,00,00,today_esp[2],today_esp[1],today_esp[0]);

Code: Select all

time_t myTimeCallback() {
//  setTime(9, 43, 21, 7, 8, 2020);
  Serial.printf("mytimecallback NOW = %llu\n"+now());
  return now();
}
In the last snippet I never get a serial.print output.

I can (and do) send an xmlrequest from kavascript to the ESP with the current date (number form 1-1-1970) is it simply possible to use that to set the timestamp on a new directory.

Why is this so hard to grasp... Sigh.
Thanks.

hobby_guy
Posts: 18
Joined: Sat Jan 29, 2022 3:29 pm

Re: LittleFS and setting timestamp with new files & directories

Postby hobby_guy » Wed May 15, 2024 8:27 am

I'm a bit confused on some things with your post :)

What is `now()` in the ESP code? The ESP doesn't have a wall/real time clock. As far as I know, you can only get the milliseconds elapsed since boot time. It would be helpful to see some more code; I also don't know what the `setTime` function is, and how/when the `myTimeCallback` is called...

If I understand correctly, you submit a timestamp from a web page (javascript) but you receive it as 1-1-1970. Could you try printing out the values received in the HTTP request, `p->value()` before casting it to an int?

Who is online

Users browsing this forum: No registered users and 5 guests