Hi,

I'm developing with a BeagleBoard Black (BBB) under Ubuntu using C. When the BBB is powered on I'm doing many time controlled tasks.
My problem happens when NTP changes the clock and all my counters are not valid. Normally BBB starts with no date/time set, some seconds later (if internet connection is available) the NTP daemon changes the date/time and all my internal checks are unusable. I'm using time().

I need the real time when available to write logs and send data. But I need a time() function not dependent of current date/time to know (for example) how many seconds one relay was open.

Thanks in advance!

Hello,

how to control time correctly?
You can control time correctly if you know the the basic step in controlling it...
By doing this way such as:
1. check the time of each users.
2. See if how many minutes that the users using her/his time.
3. Use your time wisely not doing others things(Multi work)
4. Time is gold that's why you need to use properly.

Before your program starts doing calculations synchronize the clock with NTP.

Imagine this scenario:

  1. Automatic power on
  2. BBB starts and load ubuntu, and finally application.
  3. App moves some valves
  4. Send data to another device
  5. Automatic power off

Ok, I need NTP for correct time date when internet connection available. I can't wait until NTP changed date/time to move the valves, it's time critical.

While I'm moving a valve I need to check the maximum time moving valvule is 10 seconds. Then I need a time() function non-dependant of time/date of the system.

use clock() instead of time(). clock() returns the number of (usually) milliseconds that have elapsed since the program started. I don't know how changing the computer's time will affect clock()

Set your system (like the rest of the world), to use UTC (aka GMT or Zulu time).

Why? Because UTC is not affected by Daylight Savings Time changes. It doesn't change for it.

[quote]
The switch to daylight saving time does not affect UTC. It refers to time on the zero or Greenwich meridian, which is not adjusted to reflect changes either to or from Daylight Saving Time.

However, you need to know what happens during daylight saving time in the United States. In short, the local time is advanced one hour during daylight saving time. As an example, the Eastern Time zone difference from UTC is -4 hours during daylight saving time rather than -5 hours as it is during standard time.

[/quote]

I would agree, but there is an external source that changes the computer's clock. Using UTC will not solve the problem. I think the only reliable solution is to use the clock on some other computer, such as one on a LAN or over the internet.

I've used UTC in a research program for 16 years. It is used worldwide for this (and many other) computing projects. It works just fine.

The time you receive over the internet, is UTC time, THEN your PC changes that with it's own offsets, to your local time zone.

My problem happens when NTP changes the clock and all my counters are not valid

The best solution is to get the time from the internet, such as from here

Thanks for all answers. The correct one for me was clock(), I'm looking the documentation for CLOCK_REALTIME and CLOCK_MONOLITIC.
For Linux this method is ok, for os/x (my devel environment) doesn't exist, but this is a minor issue.

Again, thanks to everybody.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.