Read timestamp with arduino

My question is about getting a timestamp from a request with arduino. I added this code to “Example1_NotecardBasics.ino”:

  JTIME ncTime = 0;
    rsp = notecard.requestAndResponse(notecard.newRequest("card.time"));
    if (rsp != NULL) {
        ncTime = JGetNumber(rsp, "time");
        notecard.deleteResponse(rsp);
    }
  Serial.print("time: ");
  Serial.println(ncTime);

and I’m getting this results (loop of 15 seconds):

 {"req":"card.time"}
 {"minutes":-,"lat":-,"lon":-,"area":"-","country":"-","zone":"-","time":1614435657}
 time: 1614435584

 {"req":"card.time"}
 {"minutes":-,"lat":-,"lon":-,"area":"-","country":"-","zone":"-","time":1614435673}
 time: 1614435584

 {"req":"card.time"}
 {"minutes":-,"lat":-,"lon":-,"area":"-","country":"-","zone":"-","time":1614435689}
 time: 1614435712

 {"req":"card.time"}
 {"minutes":-,"lat":-,"lon":-,"area":"-","country":"-","zone":"-","time":1614435705}
 time: 1614435712

The result is truncated with a resolution of 128. JGetNumber returns a data type JNumber. The hardware I’m using is an AVR 8bits and JNumber seems to be a float of 4 bytes. The significant precision of a float could explain the behavior I get.

My question is how I can extract correctly a timestamp using the arduino notecard library (1.2.9)?

Thanks

Hi Alec,
Welcome to the community. And thanks very much for posting your question to the public forum.

Can you try replacing the use of JGetNumber with JGetInt?

This returns an integer type instead of a float. Here is the function signature:

int JGetInt(J *rsp, const char *field)

Let me know if that helps!

Hi @gwolff,

Using JGetInt is not working since in Arduino with 8bits MCU, an INT has 16 bits.

Thanks Alec for letting us know. We are working to see if we can get a fix in place.