This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Get a timestamp in nRF51822 BLUETOOTH SMART BEACON KIT

Hi,

I'm trying to get a time stamp using that kit, but I'm having problems doing it because always I upload the code to the kit, it stops working.

I add here the code related with the time stamp:

//funcion declaration code
    void getConcatTimestamp(char **year){
   time_t rawtime;
   struct tm * timeinfo;
	 //char *buffer; I don't use this because a developer talked me some issues with the dynamic //memory
	static char buffer[10]; 

   time ( &rawtime );
   timeinfo = localtime ( &rawtime );
	
		 strftime (buffer,10,"%y",timeinfo);

	*year=buffer;
	
}

And in the main:

    char *anio=NULL;
getConcatTimestamp(&anio);

As I upload the code to the device it stops working. Any idea about how can I fix this?

Regards.

Iván

Parents
  • Your code is ok from a C point of view (compiled with gcc on a mac or linux the result is 2 digit year = 14) , but with nRF51 you need a RTC/CALENDAR. See this about RTC/CALENDAR, sfrtime not works with nRF51822.

  • At the moment I find some difficulties in using timers, prescalers without a clear example, but if I have no other options I'd have to. I get the time stamps using strftime but the time goes really fast, the hours behavior is similar to a second in real time, why is it like this? Because that function should return the right time, the only problem I thought I could have was the fact that I haven't set the time, so it could start from 01/01/01 00:00:00 for example. But I didn't expect that the time behavior was so different compared to a real time one.

Reply
  • At the moment I find some difficulties in using timers, prescalers without a clear example, but if I have no other options I'd have to. I get the time stamps using strftime but the time goes really fast, the hours behavior is similar to a second in real time, why is it like this? Because that function should return the right time, the only problem I thought I could have was the fact that I haven't set the time, so it could start from 01/01/01 00:00:00 for example. But I didn't expect that the time behavior was so different compared to a real time one.

Children
No Data
Related