Bridge and getTimeStamp issue

I am developing a mini datalogger and I need to time stamp each reading which is then copied into a google spreadsheet. I have one problem on initial boot the time stamp is wrong, but if I re-load the sketch the time & date is correct.

I think on start up the internet connection has not been made and the initial time stamp cannot read and defaults to a standard clock. But, on re-starting the internet connection is up and the correct time can be obtained.

There seems to be two solutions to this problem:

  1. Have something that checks the internet connection is made and then sets the time
  2. Have a different clock function which read the time from the internet i.e. change getTimeStamp for something else

The interesting item above is the sketch is running a long time before the wifi/Linux so could be good to have them synced together better to reduce the ability to lose data on the start-up.

Is it safe to assume that you are talking about a Yun? If so, the Yun forum would be a better place for your post.

What you are doing is not entirely clear. If you are feeding the data live to a terminal, timestamping is usually taken care of at the other end.

brendonshaw:
I think on start up the internet connection has not been made and the initial time stamp cannot read and defaults to a standard clock. But, on re-starting the internet connection is up and the correct time can be obtained.

  1. Have a different clock function which read the time from the internet i.e. change getTimeStamp for something else

I had to track down your getTimeStamp function to find out what you meant but yes.

#define Y2K 946684800    //Y2K unix time stamp
void setup (void) {
	Bridge.begin();
	do {
	  //wait for host and internet
	  digitalWrite(13, !digitalRead(13));
	  delay(500);
	} while (getHostTimeT () < Y2K);
}

//return unix time of yun host
time_t getHostTimeT(void) {
	time_t t = 0;
	Process p;
	p.begin("date");
	p.addParameter("+%s");
	p.run();
	if( p.available() > 10) {
		t = p.parseInt();
	}
	p.close();
	return t;
}

Sorry I did not see the forum for the Yun, but as there is a couple of replies I will add some more details.

There was a post regarding updating google spread sheet from the Yun, which uses the bridge to send data from the sketch to the linux which in turn updates the google spread sheet.

My code is based off this, but I want to add a timestamp from the sketch which is sent via the bridge to the linux which is sent to the google spreadsheet. There is a sketch which is communicating to a python code, which updates the spread-sheet.

The problems seems to be on initial power up of the Yun the timestamp is always wrong day behind, clock really out. When I relfash sketch the date & time is correct.

It’s just really odd behavior, but I will try the solution above and let you know the outcome.

Nick_Pyner:
What you are doing is not entirely clear. If you are feeding the data live to a terminal, timestamping is usually taken care of at the other end.

What he's doing is logging data (from sensors) and using the Yún to insert the data in a GSpreadsheet.. I don't think GSpreadsheets timestamp on insert...

yes, I have a couple of sensors on the Yun which I read every 10 minutes and update the google spreadsheet, the problem is the Yun and timestamp on the initial power up does not work

I have found the Yun clock is not set, if you do a date from the command line you get the same wrong lock information.

I thought the Yun on start-up sync’ed it’s clock with the internet, do you need to setup a new process to get clock sync?

Hi,

I had the same problem that the yun did not synced after startup. I use the function below and call at setup():

void syncTime(){
Process p;
p.runShellCommand("ntpd -q -p 0.europe.pool.ntp.org -p 0.openwrt.pool.ntp.org");
while(p.running());
}

Maybe this helps

@brendonshaw:

Enable ntpd client and setup timezone at Yun configuration page

confirm ntpd client is work:

ps |grep ntpd
10100 root      1500 S    /usr/sbin/ntpd -n -p 0.openwrt.pool.ntp.org -p 1.openwrt.pool.ntp.org -p 2.openwrt.pool.ntp.org -p 3.openwrt.pool.ntp.org
10442 root      1496 S    grep ntpd

ping timeserver find out closed one ( 0.europe.pool.ntp.org, 0.openwrt.pool.ntp.org...)
Use Yun configuration page reconfigure timeserver.

Thanks for the feedback and I give them a go during the day, I found out if I upload a new sketch with nothing in it the date is correct. My code is a bit messy at the moment which I will tidy up and post, but there is nothing to my knowledge is affecting the system clock.