6 Replies Latest reply on Jan 4, 2016 10:42 AM by user_78878863

    RTC component

    chaplin.u_1533771

      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 ;(

        • 1. Re: RTC component
          user_242978793

          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[i]);

             

          }

             

          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);
           

             


           

          • 2. Re: RTC component
            user_242978793

            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);

               

            }


             

            • 3. Re: RTC component
              user_242978793

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

              • 4. Re: RTC component
                chaplin.u_1533771

                thanks, I`l checkit.

                • 5. Re: RTC component
                  user_242978793

                  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.   

                  • 6. Re: RTC component
                    chaplin.u_1533771

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

                    • 7. Re: RTC component
                      user_78878863

                      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.