RTC component

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
urchc_1533771
Level 5
Level 5
5 likes given First like received First like given

I use RTC component for alarm functionality but don`t know how  get Current Time Service (CTS) in Android and Windows.

   

Existing example (Day033_BLE_RTC) use internal iOS function and WDT instead of RTC ;(

0 Likes
1 Solution
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Well, on Android you just do a 'Date now=new Date()' and get the current time and date.

   

You can use the BLE application to see how the CTS protocol can be implemented, and the create your own BLE GATT server on Android.

View solution in original post

0 Likes
7 Replies
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is a windows C program to get time
class Program

   

{

   

static void Main(string[] args)

   

{

   

Console.WriteLine(DateTime.Now.ToLongTimeString().ToString()); Console.WriteLine(DateTime.Now.ToShortTimeString().ToString());

   

Console.ReadLine();

   

}

   

}

   

Android

   

android.os.SystemClock program

   


SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

   

Calendar cal = Calendar.getInstance();

   

System.out.println("time => " + dateFormat.format(cal.getTime()));

   

String time_str = dateFormat.format(cal.getTime());

   

String[] s = time_str.split(" ");

   

for (int i = 0; i < s.length; i++)

   

{

   

System.out.println("date => " + s);

   

}

   

int year_sys = Integer.parseInt(s[0].split("/")[0]);

   

int month_sys = Integer.parseInt(s[0].split("/")[1]);

   

int day_sys = Integer.parseInt(s[0].split("/")[2]);

   

int hour_sys = Integer.parseInt(s[1].split(":")[0]);

   

int min_sys = Integer.parseInt(s[1].split(":")[1]);

   

System.out.println("year_sys => " + year_sys);

   

System.out.println("month_sys => " + month_sys);

   

System.out.println("day_sys => " + day_sys);

   

System.out.println("hour_sys => " + hour_sys);

   

System.out.println("min_sys => " + min_sys);
 

   


 

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is a program to get the time and date from the internet.

   

 
var client = new TcpClient("time.nist.gov", 13);

   

using (var streamReader = new StreamReader(client.GetStream()))

   

{

   

var response = streamReader.ReadToEnd();

   

var utcDateTimeString = response.Substring(7, 17);

   

var localDateTime = DateTime.ParseExact(utcDateTimeString, "yy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);

   

}


 

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Or you could get a GPS module and put that on the Pioneer kit. That is the best time standard in the world.

0 Likes
urchc_1533771
Level 5
Level 5
5 likes given First like received First like given

thanks, I`l checkit.

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is the GPS Program it will require some work as I didn't add any of the RTC programming. I just added the component. Also the GPS modules put out a Time signal of once per second. You could use that also.   

0 Likes
urchc_1533771
Level 5
Level 5
5 likes given First like received First like given

as I see it`s not code for PSOC Creator ? I need code that work on PSOC with server on Android

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Well, on Android you just do a 'Date now=new Date()' and get the current time and date.

   

You can use the BLE application to see how the CTS protocol can be implemented, and the create your own BLE GATT server on Android.

0 Likes