Topic: Difference between elapsed real time and elapsed time with TimeLib's now() (Read 228 times)previous topic - next topic

I've been using TimeLib to track elapsed seconds with my Arduino Micro.

My goal is to send a Sigfox message (using a serial port and another card) every 12 minutes. I store data from the softwareSerial port every 2 minutes. Once I stored data 6 times, I print a timestamp and send a Sigfox message.

My problem is that the messages are received [Edit: by Sigfox] around every 13 minutes, so they must be sent at the same rate.

My usage of the serial ports are Serial1 for the Sigfox card, and SoftwareSerial for the device that gives me the data I need to send. The softwareSerial port is used very often (about 70 characters per second).

You are trying to synchronise messages which you send from your Arduino with messages which are sent from Sigfox. Is that right ?You are sending messages at the rate of 1 message every 12 minutes and receiving messages at the rate of 1 message every 13 minutes. You want to now adjust the schedule of activities on the Arduino so you can match the rate at which you are receiving these messages. And you are having trouble achieving this using the TimeLib ?

TimeLib is not actually tracking elapsed time. Well technically it is but not the way you may be thinking.TimeLib is based on the unix time tracking method which tracks the number of seconds since Jan 1, 1970 12:00am GMT.That point in time is called the epoch.This type of tracking is very useful when you want to keep things in sync between things that may cross timezones since timezones are irrelevant when tracking time in this way.It is also very useful if wanting a timestamp that is immune to timezones and DST type adjustments.

You only have to deal with timezones or DST adjustments when converting the time_t value to a human readable format and the human wants to see the local time in some other timezone than GMT.Other than that the raw time_t value *is* the timestamp.

If you don't initialize the time_t counter inside TimeLib it starts from 0 which can look like an elapsed time but is really allowing the time tracking to start counting from Jan 1, 1970 12:00am GMT.

If you were to wait a while, you would notice that hour() will start over each time 24 hours elapses.

If all you need to do is track elapsed time are not concerned about the actual time, then simply use millis()Just subtract a saved value of millis() from the current value of millis() and you will know how many milliseconds have elapsed since the saved value of millis() was done.You can do some simple math to convert that to hour, mins, etc...

[00:10:00.790] DATA GOT TO NEXT ID: 5[00:12:00.391] DATA GOT TO NEXT ID: 6SENT TO BRKWS01: AT$SF=030a020e0000000007050000RECIEVED FROM BRKWS01: OK\n[00:14:00.800] DATA GOT TO NEXT ID: 1[00:16:00.375] DATA GOT TO NEXT ID: 2[00:18:00.805] DATA GOT TO NEXT ID: 3[00:20:00.347] DATA GOT TO NEXT ID: 4[00:22:00.785] DATA GOT TO NEXT ID: 5[00:24:00.391] DATA GOT TO NEXT ID: 6SENT TO BRKWS01: AT$SF=000000000000000000000000RECIEVED FROM BRKWS01: OK\n[00:26:00.001] DATA GOT TO NEXT ID: 1[00:28:00.457] DATA GOT TO NEXT ID: 2[00:30:00.081] DATA GOT TO NEXT ID: 3[00:32:00.541] DATA GOT TO NEXT ID: 4[00:34:00.140] DATA GOT TO NEXT ID: 5[00:36:00.569] DATA GOT TO NEXT ID: 6SENT TO BRKWS01: AT$SF=000000000000000000000000RECIEVED FROM BRKWS01: OK\n[00:38:00.109] DATA GOT TO NEXT ID: 1[00:40:00.489] DATA GOT TO NEXT ID: 2