Another date/time question

How often does ntp on the Linino connect to the ntp server?
It obviously connects at boot, but when it is running, does it connect

  1. Once an hour
  2. Once a day
  3. Some other schedule
  4. Every time a 'date' command is executed
  5. Some combination of the above

The reason I ask is, that in my sketch I query time with the 'date' command in every iteration of loop(). Today where we switched to PDT, I noticed that it immediately was aware of the new time at 2:00 am, so either it queries very often, or it computationally know when PDT starts.

So I got to think that in 4 above, I would be hitting the ntp server several times a second, and I think that is not very polite :slight_smile:

On a related subject, I have noticed that after boot of the Linino and until the first successful ntp query, the 'date' command returns a specific date every time (in my case 2013-10-20). I use that in my sketch getTime() routine to determine if the time is valid, and block until I get a valid time. I call this in setup() to wait for ntp to have synced since my loop() processing is time based. I know it is somewhat of a hack, but it seems very reliable, even I don't know where the specific date comes from, maybe the build date of the Linino image?

How often does ntp on the Linino connect to the ntp server?

The ntp update interval :600 Seconds (default value) to pause between measurements, i.e. 10 minutes. It is usually neither necessary not helpful to reduce this number.

if you still like to change it:

nano /etc/config/ucitrack
config 'ntpclient'
...
        option 'interval' '300'
...

http://wiki.openwrt.org/doc/uci/ntpclient

Today where we switched to PDT, I noticed that it immediately was aware of the new time at 2:00 am, so either it queries very often, or it computationally know when PDT starts.

It take care by timezone.

nano /etc/config/system
...
option timezone 'EST5EDT,M3.2.0,M11.1.0'
...

M3.2.0:second Sunday in March.
M11.1.0:first Sunday in November.

Thanks.

On a related subject, I have noticed that after boot of the Linino and until the first successful ntp query, the 'date' command returns a specific date every time (in my case 2013-10-20). I use that in my sketch getTime() routine to determine if the time is valid, and block until I get a valid time. I call this in setup() to wait for ntp to have synced since my loop() processing is time based. I know it is somewhat of a hack, but it seems very reliable, even I don't know where the specific date comes from, maybe the build date of the Linino image?

The getTime is widely use at datalogger, if logger is database based. Neither Arduino nor Linono should provide date/time . Correct way should be database time stamp. It is not application layer job but database layer job.

Sorry if I confused the issue, getTime() is my own routine, which uses the 'date' command to get the time via a process. Now that I realize that there is a system function getTime(), I might rename my own function to avoid confusion.

I am using time both for scheduling tasks in my loop(), and for time stamping entries in a csv file.

Edit: After searching, I have not been able to find the getTime sonnyyu is talking about, am I missing something?

Use str(datetime.now())

touch /mnt/sda1/datalog.csv
nano /mnt/sda1/datalog.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from datetime import datetime
data_rcv=sys.argv[1] +"," + sys.argv[2] +"," + str(datetime.now())
f = open('/mnt/sda1/datalog.csv','a')
f.write(data_rcv)
f.write('\n')
f.close()
chmod 755 /mnt/sda1/datalog.py

Testing:

/mnt/sda1/datalog.py '1' '2'
#include <Process.h>

void setup() {
  // Initialize Bridge
  Bridge.begin();
}

void loop() {
  Process p;              
  p.begin("/mnt/sda1/datalog.py");      
  p.addParameter("1"); 
  p.addParameter("2"); 
  p.run();
  delay(10000);
}